[Bioperl-l] Local parsing code

Jason Raymond jasonraymond@asu.edu
Tue, 16 Oct 2001 18:00:21 -0700


Unfortunately I haven't been able to implement J.S.'s local_blast_fetch
(probably because my annotations are all created locally and aren't
parseable by that program), but I figured it would be a good additional
intro to this stuff to try to do something myself :).  (Thanks for the
previous answers by Heikki and others).  The output to screen is exactly as
desired; the program parses a local blast file (according to my local
annotations) then retrieves the files from my local DB file, all in nice
sequential order.
But I'd like to output to a text file and this has been throwing me for a
loop, as I'm accustomed to using the "Perl for Retards" 'print OUT'
statement to get things into a file and make manipulations therein; this
works for 'print OUT $hit->name' but doesn't work for 'print OUT $stream
$seq'.  I can use a $seqout->write_seq($seq) where $seqout is piped into my
output file, but this doesn't do things in order (names are at the top of
the file and sequences are at the bottom).  What did I miss here?
Also this is one of my first files I've put together (mostly piecemeal from
others' fine work) so any critiques on a more efficient way to get the job
done are appreciated!
Thanks again,
Jason

<usual header stuff clipped>
$USAGE='usage:JRparse.pl -f file.txt -i index -o output.txt';

my ($file, $index, $output);
&GetOptions
('f|file:s'=>\$file,'i|index:s'=>\$index,'o|output:s'=>\$output);

$blastObj = Bio::Tools::Blast->new( -file  => $file,
                                   -parse => 1);
my $inx = Bio::Index::Fasta->new($index);
open(OUT, ">$output");
$stream = Bio::SeqIO->newFh();

foreach $hit ($blastObj->hits) {
  print $hit->name, "\n";
  my $id = $hit->name;
  if(my $seq = $inx->fetch($id) ) {
    print $stream $seq;
 }
}

Outputs (to screen):
Parsed ID1
Matching local DB sequence 1
Parsed ID2
etc...

If rearranged for file output as mentioned, outputs (to file):
Parsed ID1
Parsed ID2
etc...
Matching local DB sequence 1
etc...