Parsing BLAST results into per-query files
From BioPerl
(see thread)
- Remember that Bio::SearchIO can write as well as read. --Ed.
Tim Kohler asks:
When I use Bio::Tools::Run::StandAloneBlast to BLAST one fasta file including different sequences, I get a BLAST output with many queries, each having several hits / sbjcts. My problem is how to parse all hits of one query into a single new file. And this for all the queries I have in my BLAST output file.
If you have your multiple-query blast report file, you can sort and output separate files like so:
use Bio::Search::Result::BlastResult; use Bio::SearchIO; my $report = Bio::SearchIO->new( -file=>'full-report.bls', -format => blast); my $result = $report->next_result; my %hits_by_query; while (my $hit = $result->next_hit) { push @{$hits_by_query{$hit->name}}, $hit; } foreach my $qid ( keys %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=>'blast' ); $blio->write_result($result); }
--Ed.
Russell also had a solution, but we'll let him pare it down for the scrapbook!