This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bioperl Seqio Reset (Next_Seq())

Hi all I am writing a script that gets a sequence from several hundred files containing genes from several database fasta files. I am reusing these database fasta files in a loop so it does not get reindexed.

However my code only works with 1 iteration.

The condition in the while loop "my $seq = $file->next_seq()" is not met after the first iteration and I am assuming that I may need to reset it. Does anyone know how I can go about this?

Thanks

bioperl

why not delete the filehandle and create a new one?

Need to see more of the code to answer this properly.

1 answer

You can add a line at the end of the loop so the the file handle seeks back to the start:

seek($file->_fh, 0, 0);

Or use the methods like $file->first_seq (which resets the file pointer to 0) followed by a series of $file->next_seq.

A better way, depending on the size of the file, may be to read the sequences into an array, see the examples here: http://www.bioperl.org/wiki/HOWTO:SeqIO

Log in to answer this question.