[Bioperl-l] howto save blast parser output

Karolina Zavisek Karolina.Zavisek at zg.htnet.hr
Thu Sep 9 12:19:59 EDT 2004


Hi,

Can someone please help me with this little problem I'm having with my BLAST
parser. Parser works fine but I don't know how to make him save output that he
prints out on my screen. I would like to save it to some file.  Oh, and must I
mention that I'm new to perl and bioperl. 

Thanks!

First part of the program executes remote BLAST and retrieves report which is
saved in to the file which is later used by parser. So this is code:

#!/usr/bin/perl -w

use strict;
use Bio::SeqIO;
use Bio::Tools::Run::RemoteBlast;
use Bio::SearchIO;
use Bio::SearchIO::Writer::HTMLResultWriter;
use Bio::AlignIO;


my $prog = 'blastp';
my $db = 'nr';
my $e_val = '1e-10';


my @params = ('-program'=> $prog,
	      '-data'=> $db,
	      '-expect'=> $e_val,
	      'readmethod' => 'SearchIO');


my $factory = Bio::Tools::Run::RemoteBlast -> new (@params);

my $v = 1;

my $str = Bio::SeqIO -> new (-file => 'ketosynt.fasta',
				              -format => 'fasta');

my $r = $factory -> submit_blast ('ketosynt.fasta');

print STDERR "waiting..." if( $v > 0 );
    while ( my @rids = $factory->each_rid ) {
         foreach my $rid ( @rids ) {
         my $rc = $factory->retrieve_blast($rid);
        if( !ref($rc) ) {
              if( $rc < 0 ) {
              $factory->remove_rid($rid);
          }
          print STDERR "**\n" if ( $v > 0 );
          sleep 5;
        } else {
          my $result = $rc->next_result();
          #save the output
          my $filename = $result->query_name()."\.out";
          $factory->save_output('my_result.bls');
	  $factory->remove_rid($rid);
	  }
     }
}



################### PARSER 1 ###########################################

 my $in = new Bio::SearchIO(-format => 'blast',
                                                    -file   => 'my_result.bls');

 while( my $result = $in->next_result )        {
   while( my $hit = $result->query_description ) {
    while( $hit = $result->query_accession )      {
      while( $hit = $result->next_hit )           {
       while( my $hsp = $hit->next_hsp )         {
	    my $aln = $hsp->get_aln();
                  if( $hsp->length('total') > 100 )       {
                  if ( $hsp->percent_identity >= 75 )   {

	      print "Hit= ",       $hit->name,
                    ",\nLength=",     $hsp->length('total'),                   
       #this is part which output I want to                     
                                                                               
                         #save 
                    ",\nPercent_id=", $hsp->percent_identity,                      #
		    ",\nAccession_number=", $hit->accession,                      #
		    ",\nDescription=", $hit->description,"\n\n";                     #
                                                                               
                          #
		   my $alnIO = Bio::AlignIO->new(-format=>'fasta');            #
                   my $alignment_as_string = $alnIO->write_aln($aln);       #


# change BLAST report from text format to html########################

		my $writer = new Bio::SearchIO::Writer::HTMLResultWriter;

		$in = new Bio::SearchIO(-format => 'blast',
                                                             -file   =>
'my_result.bls');
		my $out = new Bio::SearchIO(-writer => $writer,
					                             -file => '>my_result2.html');
                    $out->write_result($in->next_result);



       }
      }
     }
    }
   }
  }
 }




---------------------- H T n e t - - W e b M a i l ----------------------
Ova poruka poslana je upotrebom HTnet WebMail usluge.
http://www.htnet.hr/webmail






More information about the Bioperl-l mailing list