BioPython 1.66 Problem with storing SeqIO.parse results in list
1
0
Entering edit mode
9.4 years ago
ckan91 ▴ 40

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 • 2.8k views
ADD COMMENT
1
Entering edit mode
9.4 years ago
Li Hsing ▴ 10

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.

ADD COMMENT
0
Entering edit mode

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

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

Login before adding your answer.

Traffic: 2028 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6