This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BioPython 1.66 Problem with storing SeqIO.parse results in list

Hello,

I am trying to follow the Biopython tutorial and cookbook and store sequences in memory for processing. I downloaded the fasta files recommend in the Biopython workshop.

I ran the following code and it worked. It printed all of the sequence names from the FASTA:

handle = open("NC_000913.faa", "rU")
for record in SeqIO.parse(handle, "fasta"):
    print record.id
handle.close()

But when I run the following code from section 5.1.3 "Getting a list of records in a sequence file" in the tutorial it doesn't seem to work:

record= list(SeqIO.parse(handle,"fasta"))

The list record is empty and has no entries. My understanding is that it should store the SeqRecords in a list. I tried to print(record) it printed [] indicating an empty list and print(record[0].id) which returned an index of out range error.

Does anyone have a suggestion as to what I might be doing wrong?

Thank you for your help!

biopython seqio

1 answer

Hi,

It seems that your file's current position had pointed to the end of file when you run:

record= list(SeqIO.parse(handle,"fasta"))

You can perform handle.tell() to tell the file's current position, and handle.seek(0) to redirect the current position to the start of file.

Or just use a filename and let SeqIO open a new handle for you itself:

records = list(SeqIO.parse("NC_000913.faa", "fasta"))

Log in to answer this question.