[Bioperl-l] Parsing a blast report with multiple queries into separate one query files that only contain the fasta sequences

Fields, Christopher J cjfields at illinois.edu
Tue Nov 20 19:21:25 UTC 2012


Maha,

Do you need only the sequence reported in the report (e.g. the HSP alignments) or the original FASTA sequences?  

The former can be recovered from the Bio::Search::HSP::GenericHSP objects as an alignment, and this can be redirected to a FASTA file.  The latter is a little trickier, as you will have to retrieve the sequences from their original source files.  

chris

On Nov 20, 2012, at 12:44 PM, maha ahmed <mahakadry at aucegypt.edu> wrote:

> Dear BioPerl list,
> I blasted a file that has several fasta queries against nr, however I need
> to align each query with its hits for further computational analysis so I
> need to parse the produced blast report into several files that each has
> only the fasta query sequence and its hits in fasta format.
> I found this script online,
> 
> use Bio::Search::Result::BlastResult;use Bio::SearchIO;
> my $report = Bio::SearchIO->new( -file=>'full-report.bls', -format
> <http://perldoc.perl.org/functions/format.html> => blast);my $result =
> $report->next_result;my %hits_by_query;while (my $hit =
> $result->next_hit) {
>  push <http://perldoc.perl.org/functions/push.html>
> @{$hits_by_query{$hit->name}}, $hit;}
> foreach my $qid ( keys <http://perldoc.perl.org/functions/keys.html>
> %hits_by_query ) {
>  my $result = Bio::Search::Result::BlastResult->new();
>  $result->add_hit($_) for ( @{$hits_by_query{$qid}} );
>  my $blio = Bio::SearchIO->new( -file => ">$qid\.bls", -format
> <http://perldoc.perl.org/functions/format.html>=>'blast' );
>  $blio->write_result($result);}
> 
> 
> 
> however on using it this produced the following error message
> 
> 
> 
> BlastResult::new(): Not adding iterations.
> 
> ------------- EXCEPTION: Bio::Root::NoSuchThing -------------
> MSG: No such iteration number: 0. Valid range=1-0
> VALUE: The number zero (0)
> STACK: Error::throw
> STACK: Bio::Root::Root::throw /usr/local/share/perl/5.10.0/Bio/Root/Root.pm:472
> STACK: Bio::Search::Result::BlastResult::iteration
> /usr/local/share/perl/5.10.0/Bio/Search/Result/BlastResult.pm:327
> STACK: Bio::Search::Result::BlastResult::add_hit
> /usr/local/share/perl/5.10.0/Bio/Search/Result/BlastResult.pm:257
> STACK: ./parsing.blast.results.into.per.query.files.pl:15
> 
> I tried to search for other scripts but I couldn't find any
> I would really appreciate your comments to this
> Thank you
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l





More information about the Bioperl-l mailing list