For the most part, my script below works to generate a csv file. However, sometimes it doesn't return a result, which causes my csv file to be incorrectly aligned. A sample input sequence which causes alignment issues is below.

Thanks for the help,
-Hans

use strict; use Bio::Tools::Run::RemoteBlast; use Getopt::Std; my $usage = "\nusage: <script_name> <input_file> <output_file>\n". "Creates a CSV file with query_name, hit_name, score, and exp +ect\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 => 'Se +archIO', -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_descript +ion().",".$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;
inputfile
>gi|117625301|ref|YP_854502.1| hydrogenase 2 protein HybA [Escherichia + coli APEC O1] MNRRNFIKAASCGALLTGALPSVSHAAAENRPPIPGSLGMLYDSTLCVGCQACVTKCQDINFPERNPQGE QTWSNNDKLSPYTNNIIQVWTSGTGVNKDQEENGYAYIKKQCMHCVDPNCVSVCPVSALKKDPKTGIVHY DKDVCTGCRYCMVACPYNVPKYDYNNPFGALHKCELCNQKGVERLDKGGLPGCVEVCPAGAVIFGTREEL MAEAKKRLALKPGSEYHYPRQTLKSGDTYLHTVPKYYPHLYGEKEGGGTQVLVLTGVPYENLDLPKLDDL STGARSEHVQHTLYKGMMLPLAVLAGLTVLVRRNTKNDHHDGGDDHES

In reply to Bio::Search::Hit::BlastHit unreturned results misformats csv output by hansoffate

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.