[Biopython] Cookbook suggestion

Justin Gibbons jgibbons1 at mail.usf.edu
Sat Apr 13 20:13:56 UTC 2013


I want to add the following to the cookbook but I am unable to create an
account.

#using SeqIO.write() without holding records in memory.

from Bio import SeqIO


seq_ids=set() #create an empty set to hold the sequence IDs.
indexed_fasta=SeqIO.index(file_path, 'fasta') #Can be searched by sequence
ID but is not held in memory

for seq_record in SeqIO.parse(file_path, 'fasta'):
    #Filter according to some critria:
        seq_ids.add(seq_record.id)

#write the fasta records to a new file using SeqIO.write()

SeqIO.write([indexed_fasta[seq_id] for seq_id in seq_ids], new_file_path,
'fasta')

So if someone who can edit the cookbook wants to add it feel free to.

Justin Gibbons



More information about the Biopython mailing list