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

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!

seqio biopython • 1.3k views
ADD COMMENTlink modified 3.8 years ago by Li Hsing10 • written 3.8 years ago by ckan9120
1
gravatar for Li Hsing
3.8 years ago by
Li Hsing10
China
Li Hsing10 wrote:

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 reditect the current position to the start of file.

ADD COMMENTlink written 3.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 3.5 years ago by Peter5.8k
Please log in to add an answer.

Help
Access

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