Skip to content

GC_skew () issue #1107

Closed
Closed

Description

@sachalau

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?

Cheers and thanks for the good work !

Activity

  1. peterjc commented on Mar 22, 2017

    @peterjc
    Member

    You missed out the error, under Python 3.6 I get:

    >>> 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).

  2. sachalau commented on Mar 22, 2017

    @sachalau
    Author

    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.

  3. peterjc commented on Mar 22, 2017

    @peterjc
    Member

    You could make a good case for returning zero here too.

  4. peterjc commented on Mar 28, 2017

    @peterjc
    Member

    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.

  5. sachalau commented on Mar 29, 2017

    @sachalau
    Author

    Yes sorry, I have prepared the pull request but did not send it yet. I'll add a test as well then.

  6. added a commit that references this issue on Apr 7, 2017
  7. added 2 commits that reference this issue on Oct 31, 2017
    ffd0027
    f459b62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions