MonkPaul has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
Im not sure if this is right but can you please check this code to see if it does what i think it should do....

The only thing is that im not entirely sure if these few lines are all i need to be able to read a DNA sequence file, extarct the sequences only and save them into an array.

sub get_File_Data() { my $web = new CGI; my $filehandle = $web->upload('upload'); my @file = <$filehandle>; my @sequences; my $seqIO = Bio::SeqIO->new(-fh => \*$filehandle, -format=>$format); my $fh = Bio::SeqIO->newFh(-fh => \*$filehandle, -format=>$format); my $sequence; while($fh != -1) { $sequence = stream->next_seq @sequences = $sequence; } }

I would be very grateful for any replies.
MonkPaul.

Replies are listed 'Best First'.
Re: Not sure about Bio::SeqIO
by blazar (Canon) on May 10, 2005 at 16:03 UTC
    Well, I do't know Bio::SeqIO, but at first sight this:
    while($fh != -1) { $sequence = stream->next_seq @sequences = $sequence; }
    looks strange, for
    1. both the name of $fh, and the way it is created suggest that it is a filehandle and thus
      while(<$fh>)
      would be the typical way to iterate over it;
    2. none of the statements in the block seem to modify $fh, so that whatever the correct test is, it is unlikely to ever succeed;
    3. stream->next_seq may well be correct, but it is more likely that there's a missing $ sigil;
    4. further, there's a missing semicolon. This code wouldn't even compile. It is recommended to post real code. It is recommended to paste rather than retype.
      Thanks,
      I posted my real code not a copy, so i apologise for my lack of precision. Im pretty useless at the moment with perl.

      With respect to Bio::Seq, im still unsure if i have done things right, to me it seems like it should work, but again i am naff.

        As I wrote, irrespectful of the fact that it may seem to you like it should work, it can't because, irregardless of Bio::SeqIO or whatever, it contains a syntax error that will simply prevent it from compiling. Why don't you try yourself?!? (Not to be intended as a personal offence - just a consideration!)
Re: Not sure about Bio::SeqIO
by stajich (Chaplain) on Jun 17, 2005 at 01:20 UTC
    You'll get better help on the Bioperl mailing list and website.

    Bio::SeqIO next_seq returns Bio::Seq objects. Follow the SYNOPSIS and you can't go wrong.

    my $seqio = Bio::SeqIO->new(-format => $seqformat, -file =>$filename); while( my $seq = $seqio->next_seq ) { print "seq name is ", $seq->display_id, " desc is ", $seq->description(), "\n"; print "sequence is ", $seq->seq(), "\n"; }
    You can do magic stuff if you want to treat it like a filehandle too (although I doubt this is what you were trying to do)
    my $fh = Bio::SeqIO->newFh(-format =>$seqformat, -file =>$filename); while(<$fh>) { my $seq = $_; # do as before }
    You can also process filehandles (all XXIO modules in Bioperl support this if the inherit from Bio::Root::IO). Usefile if you are pipine output from a program with your script and want to capture the stream and make it Bio::Seq objects.
    my $fh; open($fh, "cat seqfile |") ||die $!; my $seqio = Bio::SeqIO->new(-format => $seqformat, -fh => $fh); # OR retrieve a sequence from the blast formatted db 'nt' # by GI number open(IN, "fastacmd -d nt -s 3264957 |") ||die $!; my $seqio = Bio::SeqIO->new(-format => 'fasta',-fh => \*IN); while( my $seq = $seqio->next_seq ) { #and so forth.... }