in reply to Re^3: How to avoid using array in concatenating string of multiple lines
in thread How to avoid using array in concatenating string of multiple lines OR How To Read FASTA

stajich: you will need to add the flag -noclose => 1 option when initing the SeqIO object or else the filehandle is closed. But if you are going to do this, just move the initialization of the SeqIO object outside the loop.

Thanks stajich, it works ok now. But it will work with just adding the *-noclose=>1* flag. So this will just work fine:

#!/usr/bin/perl -w use strict; use Bio::SeqIO; my $file = $ARGV[0]; open INFILE, "<$file" or die "$0: Can't open file $file: $!"; for (my $trial = 1; $trial <=2; $trial++) { seek(INFILE,0,0); print "Trial $trial\n"; my $i =1; my $in = Bio::SeqIO->new(-format => 'fasta', -noclose => 1, -fh => +\*INFILE); while( my $seq = $in->next_seq() ) { print $i++, " : ", $seq->seq(), "\n"; } }
I don't understand why we still need to move the initialization of the seqIO outside the loop?



Regards,
Edward

PS: BTW, I can't find any documentation of the -noclose flag in Bio::SeqIO perldoc. Where can I find that?
  • Comment on Re^4: How to avoid using array in concatenating string of multiple lines
  • Download Code

Replies are listed 'Best First'.
Re^5: How to avoid using array in concatenating string of multiple lines
by stajich (Chaplain) on Dec 12, 2004 at 15:32 UTC
      I don't understand why we still need to move the initialization of the seqIO outside the loop?

    Well did you try it.... You can write it this way since there is no need to initialize the SeqIO object each time since you are resetting the filehandle. I expect it is a miniscule performance different.

    #!/usr/bin/perl -w use strict; use Bio::SeqIO; my $file = $ARGV[0]; open INFILE, "<$file" or die "$0: Can't open file $file: $!"; my $in = Bio::SeqIO->new(-format => 'fasta', -noclose => 1, -fh => \*INFILE); for (my $trial = 1; $trial <=2; $trial++) { seek(INFILE,0,0); print "Trial $trial\n"; my $i =1; while( my $seq = $in->next_seq() ) { print $i++, " : ", $seq->seq(), "\n"; } }
    As for the -noclose option, Bio::SeqIO ISA Bio::Root::IO so see the documenation for that module. Unfortunately perldoc does not allow one to pull in documentation from inherited modules so you have to read around to get the full list. The Pdoc generated documentation at our site doc.bioperl.org does have links up the inheritance hierarchy so you read the docs for the superclasses. So anything you can do with a Bio::Root::IO you can do with a Bio::SeqIO object. All the other Bio::XXIO modules also inherit from Bio::Root::IO.