Question: BioPython 1.66 Problem with storing SeqIO.parse results in list
gravatar for ckan91
4.8 years ago by
United States
ckan9120 wrote:


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") :

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!

seqio biopython • 1.6k views
ADD COMMENTlink modified 4.8 years ago by Li Hsing10 • written 4.8 years ago by ckan9120
gravatar for Li Hsing
4.8 years ago by
Li Hsing10
Li Hsing10 wrote:


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:


to tell the file's current position, and

to reditect the current position to the start of file.

ADD COMMENTlink written 4.8 years ago by Li Hsing10

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

records = list(SeqIO.parse("NC_000913.faa", "fasta"))
ADD REPLYlink written 4.4 years ago by Peter5.8k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 835 users visited in the last hour