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
CodonUsage.CodonAdaptationIndex is broken in a couple ways. First, the generate_index() method will crash with a float division by zero error unless the fasta file uses every possible codon at least once.
from Bio.SeqUtils import CodonUsage
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
with open("minimal.fa", "w") as fh:
seq = Seq("AGTACACTGCGT")
rec = SeqRecord(seq, id="AC12345")
SeqIO.write(rec, fh, "fasta")
ci = CodonUsage.CodonAdaptationIndex()
ci.generate_index("minimal.fa")
produces,
$ python bin/bug.py
Traceback (most recent call last):
File "bin/bug.py", line 13, in <module>
ci.generate_index("minimal.fa")
File "/home/cwarth/.conda/envs/biopython/lib/python2.7/site-packages/Bio/SeqUtils/CodonUsage.py", line 105, in generate_index
rcsu.append(self.codon_count[codon] / denominator)
ZeroDivisionError: float division by zero
Second, the signature of generate_index() should take a file handle to read, NOT the string name of a fasta file. Mocking a file handle for testing is a lot easier than writing a mock file to the filesystem.
The text was updated successfully, but these errors were encountered:
Taking a handle OR a filename (to preserve backward compatibility, but also matching the typical usecase) would be a sensible improvement. If you would like to submit this as a pull request, please use:
CodonUsage.CodonAdaptationIndex
is broken in a couple ways. First, thegenerate_index()
method will crash with afloat division by zero
error unless the fasta file uses every possible codon at least once.produces,
Second, the signature of
generate_index()
should take a file handle to read, NOT the string name of a fasta file. Mocking a file handle for testing is a lot easier than writing a mock file to the filesystem.The text was updated successfully, but these errors were encountered: