[Bioperl-l] getting top blast hit

Nandita Mullapudi nandita at uga.edu
Fri Apr 2 11:11:59 EST 2004

Thanks, Paulo and Jason,
It works, and I understand better now! :)

>Try making this change:
>print "\n", $result->query_name, "\t";
>if ( my $top_hit = $result->next_hit ) { # this line changed
>print $top_hit->name, "\t";
>print $top_hit->significance,. "\n";
>} else { # this else is optional, in case you want to report no hits
>print "No hits\n";
>The problem is $top_hit->name assumes there was a hit. You didn't 
>have that problem before because the while() loop was checking if 
>there was a hit. Now the if() does that.
>-Paulo Almeida
>Nandita Mullapudi wrote:
>>Thanks, Sean,
>>I tried the suggestion below in my script, which starts with a loop 
>>to read through a list of files..
>>however, now, my script stops parsing as soon as it reaches a file 
>>with no hits in it.
>>this is the error message:
>>can't call method "name" on an undefined value at 
>>/home/nandita/parse_blast-onlytophit.pl line 26, <GEN123> line 65.
>>I realise I am not looping through completely or...
>>Any suggestions?
>>use strict;
>>use Bio::SearchIO;
>>use Bio::SimpleAlign;
>>my (@list, $filename);
>>my $files= "/scratch/nandita/list";
>>open (FH,"$files") or die "cannot create list :$!";
>>while (<FH>) {
>>push (@list, $_);
>># print " $_\n"; }
>>foreach (@list) {
>># print "$filename\n";
>>my $in = new Bio::SearchIO(-format => 'blast',
>>-file => "$filename");
>>while( my $result = $in->next_result ) {
>>print "\n", $result->query_name, "\t";
>>my $top_hit = $result->next_hit ; {
>>print $top_hit->name, "\t";
>>print $top_hit->significance,. "\n";

More information about the Bioperl-l mailing list