use strict; use Bio::Tools::Run::RemoteBlast; use Getopt::Std; my $usage = "\nusage: \n". "Creates a CSV file with query_name, hit_name, score, and expect\n\n". "-b Y or N If Y, it will produce the blastoutput for each sequence query; Defaults N\n\n"; our($opt_b); getopts('b:') or die $usage; if(!defined($opt_b)) { $opt_b = 'N'; } my $prog = 'blastp'; my $db = 'nr'; my $e_val = '1e-2'; my $v = 1; my $infile = shift or die $usage; my $outfile = shift or die $usage; open OUT, ">$outfile" or die $usage; print OUT "Query_Name,Description,Hit_Name,Score,Expect\n"; my $remoteBlast = Bio::Tools::Run::RemoteBlast->new(-prog => $prog, -data => $db, -readmethod => 'SearchIO', -expect => 100); my $v = 1; #my $str = Bio::SeqIO->new(-file=>'smallinput.fna', -format => 'fasta' ); my $str = Bio::SeqIO->new(-file=> $infile, -format => 'fasta' ); $Bio::Tools::Run::RemoteBlast::HEADER{'ENTREZ_QUERY'} = 'Arabidopsis [ORGN]'; ###animals not plants while( my $input = $str->next_seq()) { my $r = $remoteBlast->submit_blast($input); print STDERR "waiting..." if ($v > 0); while(my @rids = $remoteBlast->each_rid) { foreach my $rid (@rids) { my $rc = $remoteBlast->retrieve_blast($rid); if(!ref($rc)) { if($rc < 0 ) { $remoteBlast->remove_rid($rid); } print STDERR "." if ($v > 0); sleep 5; } else { my $result = $rc->next_result(); #### save the output if($opt_b eq 'Y') { my $filename = $result->query_name()."\.out"; $remoteBlast->save_output($filename); } $remoteBlast->remove_rid($rid); print "\nQuery Name: ", $result->query_name(), " retrieved\n"; while (my $hit = $result->next_hit) { next unless ($v > 0); #print OUT $result->query_name().",".$result->query_description().",".$hit->name().","; if(defined($hit)) { print OUT $result->query_name().",".$hit->name().","; } else { print OUT "\n"; } while (my $hsp = $hit->next_hsp) { #print OUT $hsp->score().",".$hsp->expect()."\n"; if(defined($hsp)) { print OUT $hsp->score().",".$hsp->expect().",".$result->query_description()."\n"; } else { print OUT "\n"; } } } } } } } close OUT;