How To Capture The Blast Result In A String Variable To Save In A Database Using Bioperl
2
0
Entering edit mode
11.6 years ago
Curious Mind ▴ 10

I am trying to run RemoteBlast using the Bio::Tools::Run::RemoteBlast object of BioPerl. Once the result is obtained, I know how to save it to a file as shown below:

while ( my @rids = $factory->each_rid ) {
    foreach my $rid ( @rids ) {
        my $result = $factory->retrieve_blast( $rid );  
        if ( ref( $result )) {
            my $output   = $result->next_result();
            my $filename = $output->query_name().".out";
            $factory->save_output( $filename ); 
            $factory->remove_rid( $rid );
            print "Result:",$output->query_name(),"\n";
        }
    }
}

However I want to save the result to a database. Please let me know how the result can be captured in a string variable so that it could be inserted into a table.

bioperl • 3.4k views
ADD COMMENT
2
Entering edit mode
11.6 years ago

Tell BioPerl to save the result as XML.

I wrote a xslt stylesheet transforming a BLAST xml output to sqlite3 statements: https://github.com/lindenb/xslt-sandbox/blob/master/stylesheets/bio/ncbi/blast2sqlite.xsl

usage:

xsltproc --novalid   blast2sqlite.xsl  blast.xml |  sqlite3 blast.sqlite

then:

~$ sqlite3 -header -line blast.sqlite 'select * from Hit,Hsp where hsp.hit_id=hit.id ' | cut -c 1-80
          id = 1
iteration_id = 1
         num = 1
      hit_id = gi|118082669|ref|XM_416233.2|
         def = PREDICTED: Gallus gallus similar to ubiquitous tetratricopeptide 
   accession = XM_416233
         len = 2868
          id = 1
      hit_id = 1
         num = 1
   bit_score = 556.962
       score = 301.0
      evalue = 3.58957e-158
  query_from = 92
    query_to = 395
    hit_from = 2378
      hit_to = 2681
 query_frame = 1
   hit_frame = 1
    identity = 303
    positive = 303
        gaps = 0
   align_len = 304
        qseq = TACTAGATATGCAGCAGACCTATGACATGTGGCTAAAGAAACACAATCCTGGGAAGCCTGGAGAG
        hseq = TACTAGATATGCAGCAGACCTATGACATGTGGCTAAAGAAACACAATCCTGGGAAGCCTGGAGAG
     midline = |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

          id = 2
iteration_id = 1
         num = 2
      hit_id = gi|27881483|ref|NM_017590.4|
         def = Homo sapiens zinc finger CCCH-type containing 7B (ZC3H7B), mRNA
   accession = NM_017590
         len = 5868
          id = 2
      hit_id = 2
         num = 1
   bit_score = 366.757
       score = 198.0
      evalue = 6.49273e-101
  query_from = 100
    query_to = 390
    hit_from = 2608
      hit_to = 2898
 query_frame = 1
   hit_frame = 1
    identity = 264
    positive = 264
        gaps = 8
   align_len = 295
        qseq = ATGCAGCAGACCTATGACATGTGGCT-AAAGAAACACAATCCTGGGAAGCCTGGAG-AGGGAACA
        hseq = ATGCAGCAGACCTATGACATGTGGCTGAAA-AAACACAACCCAGGAAAGCCTGGAGAAGGGACCC
     midline = |||||||||||||||||||||||||| ||| |||||||| || || |||||||||| ||||| |
ADD COMMENT
0
Entering edit mode

Hi Pierre,

This is a great example of using xslt for converting blast output which has been saved as XML and then save it in sqlite3. However, I am looking for a way not to save the blast output at all. My application is web based, so it creates its own peculiar issues for saving on the server and then transforming. I would rather get the output directly into a Perl string variable.

Thanks

ADD REPLY
0
Entering edit mode
11.2 years ago
jing ▴ 10

Hi,

The trick is to print everything to a scalar ref.

For instance:

use 5.16.0;
use warnings;
use autodie;
use Data::Dumper;

use Bio::Tools::Run::RemoteBlast;
use strict;
my $prog = 'blastp';
my $db   = 'swissprot';
my $e_val= '1e-10';
my $output; #result will be printed here

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

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

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

while (my $input = $str->next_seq()){

    my $r = $factory->submit_blast($input);
        while ( my @rids = $factory->each_rid ) {
            foreach my $rid ( @rids ) {
                my $result = $factory->retrieve_blast( $rid );
                if ( ref( $result )) {
                    my $output   = $result->next_result();
                    $factory->save_output( \$output ); #NOTE how a scalar ref is passed as a parameter, instead of a filename string.
                    $factory->remove_rid( $rid );
                    print "Result:",$output->query_name(),"\n";
                }
            }
        }
}
say $output; #print result to STDOUT
ADD COMMENT

Login before adding your answer.

Traffic: 1076 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6