[BioPython] SeqIO.write() Multiple Calls for fasta
Michiel de Hoon
mjldehoon at yahoo.com
Sun Dec 14 05:53:50 EST 2008
> for j in range(1, len(kogid)):
> name = "EXT-CLB-" + kogid[j] + ".seq"
> if os.path.exists(name):
> handle = open(name, "rU")
> records = list(SeqIO.parse(handle, "fasta"))
You don't need the 'list' here
> for record in records:
> speciesID = record.id.split('|')[0]
> outFile = open(speciesID.split('-')[0] + ".seq", 'w')
> SeqIO.write([record], outFile, "fasta")
> outFile.close()
> print "Added a record for" + speciesID.split('-')[0]
> handle.close()
The handle.close() should be inside the "if" block, so with an additional four spaces of indentation. Though this is not important for the problem you mentioned. The only way I can see that the SeqIo.write overwrites a files is if speciesID.split('-')[0] + ".seq" results in the same file name for more than one of the records. It's not a SeqIO.write issue; if you comment out the SeqIO.write line, you'll probably end up with the exact same set of output files (all of them empty though).
--Michiel
More information about the BioPython
mailing list