[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:51:20 EST 2009


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





------- Comment #4 from lpritc at scri.sari.ac.uk  2009-03-05 10:51 EST -------
(In reply to comment #3)
> (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

It would probably be clearest, quickest and most efficient to comment that
particular line of the code to point out that it does elegant double-duty as a
check for zero sequence length ;)


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