[Bioperl-l] blast best hit

Frank Schwach fs5 at sanger.ac.uk
Thu Mar 31 11:06:41 EDT 2011


Hi Boyang,

With best_hit_only set to "true" (as you have done now) you should be
able to use the usual way of parsing the BLAST report with 

while (my $result = $blast_io->next_result) {
  my $hit = $result->next_hit;
  ... (do something with the hit)
}

Because there should be only one hit now. 'best_hit_only' is a flag, an
indicator that tells the parser to limit the output to the best hit. It
does not itself return any hits.

Even if you used the 

while (my $hit=$result->next_hit){..

inner loop (as in the BioPerl HOWTOs) you should now only ever get one
hit retunred from that loop, which is the best hit for the result. I
haven't tried this but it should work.

Personally, I'd not use this option and rather sort or filter the hits
because tomorrow you might want to find out what the next best hit
actually was and how close the e-values and bits were or something like
that. 

Hope this helps,

Frank


On Thu, 2011-03-31 at 16:43 +0200, boyang zhe wrote:
> I try this at the constructor
> 
> my $blast_io = Bio::SearchIO->new(-file => 'test', -format => 'blast',
> -best_hit_only => 1);
> 
> What I need to do in the following steps? It seems that setting
> best_hit_only or not does not change the way of blast parser working.
> 
> In my opinion, if we can use it as a similar way following, it will be
> much better.
> 
> my $blast_io = Bio::SearchIO->new(-file => 'test', -format => 'blast',
> -best_hit_only => 1);
> 
> while (my $blast_result = $blast_io->next_result()) {
>       my $best_hit = $blast_result->best_hit_only();  # just assume it
> working here; in fact, it does not work
>       my $best_hit_name = $best_hit->name();
>       ...................................
> }
> 
> thank you !
> 
> On Thu, Mar 31, 2011 at 4:23 PM, Frank Schwach <fs5 at sanger.ac.uk>
> wrote:
>         Yes, best_hit_only is a boolean that can be set to true if you
>         only want
>         one hit to be returned from the stream of hits (the best hit).
>         I have
>         never actualyl used this one but you shoud be able to set it
>         in the
>         constructor as in:
>         my $blast = Bio::SearchIO->new( ...., -best_hit_only => 1 )
>         
>         
>         
>         Frank
>         
>         
>         On Thu, 2011-03-31 at 14:28 +0200, boyang zhe wrote:
>         > Hi,
>         >
>         > I just want to parse the blast results ,and get the best
>         hit.
>         >
>         > One way is to parse the results as usual, then get the first
>         hit and exit
>         > the loop.
>         >
>         > I checked the bioperl document, and find that there is a
>         method
>         > best_hit_only in Bio::SearchIO::blast.pm.
>         > But it only return 1/0. So my question is how to use this
>         method to get the
>         > best hit.
>         >
>         > Thank you very much!
>         >
>         > Boyang
>         
>         
>         > _______________________________________________
>         > Bioperl-l mailing list
>         > Bioperl-l at lists.open-bio.org
>         > http://lists.open-bio.org/mailman/listinfo/bioperl-l
>         
>         
>         
>         
>         --
>          The Wellcome Trust Sanger Institute is operated by Genome
>         Research
>          Limited, a charity registered in England with number 1021457
>         and a
>          company registered in England with number 2742969, whose
>         registered
>          office is 215 Euston Road, London, NW1 2BE.
> 



-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 



More information about the Bioperl-l mailing list