You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I found a rather strange issue in the GC_skew() function in Bio.SeqUtils.
If you run this code :
import Bio
import Bio.SeqUtils
from Bio.Seq import Seq
Bio.SeqUtils.GC_skew(Seq("G"*100 +"A"))
this will fail because GC_skew will try to calculate the skew on the last remaining nucleotide which is not a G/C. Should this function check before trying to divide by zero?
>>> import Bio
>>> import Bio.SeqUtils
>>> from Bio.Seq import Seq
>>> Bio.SeqUtils.GC_skew(Seq("G"*100 +"A"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqUtils/__init__.py", line 106, in GC_skew
skew = (g - c) / float(g + c)
ZeroDivisionError: float division by zero
This is a corner case, due to the windowing scheme the final chunk of sequence can be far smaller than the window size (here one base A rather than a window of 100bp), and it is therefore more likely to have no C or G and thus give a divide by zero exception.
What would you suggest be returned here? None or the special float value not-a-number (I forget now the best way to define NaN for cross platform and cross version compatibility - something like float("NaN") though I think).
Activity
peterjc commentedon Mar 22, 2017
You missed out the error, under Python 3.6 I get:
This is a corner case, due to the windowing scheme the final chunk of sequence can be far smaller than the window size (here one base
Arather than a window of 100bp), and it is therefore more likely to have noCorGand thus give a divide by zero exception.What would you suggest be returned here?
Noneor the special float value not-a-number (I forget now the best way to define NaN for cross platform and cross version compatibility - something likefloat("NaN")though I think).sachalau commentedon Mar 22, 2017
Yes indeed but it could also happen with a theoretical window of only A/Ts. I am trying to see how other tools deal with this theoretical case and this one http://genskew.csb.univie.ac.at/ returns "0" when no G/C are found, which as far as I'm concerned makes sense because indeed no GC skew can be observed on such sequences.
peterjc commentedon Mar 22, 2017
You could make a good case for returning zero here too.
peterjc commentedon Mar 28, 2017
Would you like to submit a pull request returning zero in this cases (and explaining this in the docstring)?
Ideally please include a doctest or unittest for this as well.
sachalau commentedon Mar 29, 2017
Yes sorry, I have prepared the pull request but did not send it yet. I'll add a test as well then.
Thank Sacha for GC skew fix
User zero for GC skew when no G/C present in window
Thank Sacha for GC skew fix