Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Dseq with crick strand but without watson nor ovhg returns math domain error #321

Open
dgruano opened this issue Oct 30, 2024 · 1 comment

Comments

@dgruano
Copy link
Contributor

dgruano commented Oct 30, 2024

I was writing some tests for restriction which should return some single stranded products. To compare one of them, I wanted to create a Dseq object without a watson but with a crick strand (and without setting ovhg).

Dseq(watson="", crick="TAATTAAGCC")

This gave the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[100], line 1
----> 1 Dseq(watson=\"\", crick=\"TAATTAAGCC\")

File ~/dev/learn/Genestorian/pydna/src/pydna/dseq.py:338, in Dseq.__init__(self, watson, crick, ovhg, circular, pos)
    333 else:  # crick strand given
    334     if ovhg is None:  # ovhg not given
    335         olaps = _common_sub_strings(
    336             str(watson).lower(),
    337             str(_rc(crick).lower()),
--> 338             int(_math.log(len(watson)) / _math.log(4)),
    339         )
    340         if len(olaps) == 0:
    341             raise ValueError(\"Could not anneal the two strands.\" \" Please provide ovhg value\")

ValueError: math domain error"

Which makes sense, and is fixed by passing whatever value to ovhg. However, it may be better to catch this case and automatically set ovhg to the length of the sequence. What do you think?

For the record, passing a watson strand while in purpose leaving crick empty (Dseq(watson="TAATTAAGCC", crick="")) gives the following (also fixed by passing ovhg):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[101], line 1
----> 1 Dseq(watson=\"TAATTAAGCC\", crick=\"\")

File ~/dev/learn/Genestorian/pydna/src/pydna/dseq.py:335, in Dseq.__init__(self, watson, crick, ovhg, circular, pos)
    333 else:  # crick strand given
    334     if ovhg is None:  # ovhg not given
--> 335         olaps = _common_sub_strings(
    336             str(watson).lower(),
    337             str(_rc(crick).lower()),
    338             int(_math.log(len(watson)) / _math.log(4)),
    339         )
    340         if len(olaps) == 0:
    341             raise ValueError(\"Could not anneal the two strands.\" \" Please provide ovhg value\")

File ~/dev/learn/Genestorian/pydna/src/pydna/common_sub_strings.py:341, in common_sub_strings(stringx, stringy, limit)
    318 \"\"\"
    319 Finds all common substrings between stringx and stringy, and returns
    320 them sorted by length.
   (...)
    337     length1 = lenght of substring
    338 \"\"\"
    339 from pydivsufsort import common_substrings
--> 341 matches = common_substrings(stringx, stringy, limit=limit)
    342 matches.sort()
    343 matches.sort(key=_itemgetter(2), reverse=True)

File ~/dev/learn/Genestorian/pydna/.venv/lib/python3.10/site-packages/pydivsufsort/wonderstring.py:148, in common_substrings(s1, s2, limit)
    146 s1 = cast_to_numpy(s1)
    147 s2 = cast_to_numpy(s2)
--> 148 sep = max(s1.max(), s2.max()) + 1
    149 s = np.empty(len(s1) + len(s2) + 1, dtype=np.result_type(s1[0], s2[0], sep))
    150 s[: len(s1)] = s1

File ~/dev/learn/Genestorian/pydna/.venv/lib/python3.10/site-packages/numpy/core/_methods.py:41, in _amax(a, axis, out, keepdims, initial, where)
     39 def _amax(a, axis=None, out=None, keepdims=False,
     40           initial=_NoValue, where=True):
---> 41     return umr_maximum(a, axis, None, out, keepdims, initial, where)

ValueError: zero-size array to reduction operation maximum which has no identity"
```
@BjornFJohansson
Copy link
Collaborator

see #322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants