[Biopython-dev] [Bug 2778] Efficiency improvement in function Bio.SeqUtils.GC()

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Thu Mar 5 10:31:17 EST 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2778





------- Comment #3 from bsouthey at gmail.com  2009-03-05 10:31 EST -------
(In reply to comment #2)
> I've checked that in, but with the existing code to catch a zero length
> sequence and return 0 instead of raising a ZeroDivisionError.
> 
> def GC(seq):
>     """Calculates G+C content, ..."""
>     gc=sum(map(seq.count,['G','C','g','c','S','s']))
>     if gc == 0: return 0
>     return gc*100.0/len(seq)
> 

I think that it is clearer to check that the sequence length is not zero rather
than assuming that if the sum is zero then the sequence length is also zero. 

def GC(seq):
    """Calculates G+C content, ..."""
   gc=sum(map(seq.count,['G','C','g','c','S','s']))
   if len(seq) > 0: 
      return gc*100.0/len(seq)
   else:
      return 0


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the Biopython-dev mailing list