[Bioperl-l] getting top blast hit

Jason Stajich jason at cgt.duhs.duke.edu
Fri Apr 2 10:48:41 EST 2004


On Fri, 2 Apr 2004, 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?

protect your next_hit calls...   see below

> thanks,
> -Nandita
>
> 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) {
>      $filename=$_;
> #    print "$filename\n";
>
>      my $in = new Bio::SearchIO(-format => 'blast',
>                                 -file   => "$filename");
>
> while( my $result = $in->next_result ) {
> print  "\n", $result->query_name, "\t";
  if(  my $top_hit = $result->next_hit ) {
      print  $top_hit->name, "\t";
      print   $top_hit->significance,. "\n";
  } else {
    print "\n";
  }

 ( or maybe you only want to print anything if there is a hit, so move
   your print query_name into that same if block)

> }}}
>
>
>
>
>
>
>
>
>
>
>
> >Nandita,
> >
> >You can do something like (from Bio::SearchIO):
> >
> >    use Bio::SearchIO;
> >    # format can be 'fasta', 'blast', 'exonerate', ...
> >    my $searchio = new Bio::SearchIO( -format => 'blastxml',
> >                                      -file   => 'blastout.xml' );
> >    while ( my $result = $searchio->next_result() ) {
> >        #get first hit and do something with it.
> >        my $top_hit = $result->next_hit;
> >        #do some stuff such as saving a it in a hash
> >        #move on to next result (next query)
> >    }
> >
> >Sean
> >
> >On 3/30/04 6:19 PM, "Nandita Mullapudi" <nandita at uga.edu> wrote:
> >
> >>  I am currently using  Bio::SearchIO to parse tons of blast files by
> >>  setting limits on E- value, % identity etc. I now want to parse a
> >>  huge blast job, by getting just the top hit out of each file.
> >>  (Assuming blast was run and hits were returned with hit with lowest E
> >>  value first)
> >>  Is there a quick way to do this?
> >>  thanks,
> >>  -Nandita
> >>  _______________________________________________
> >>  Bioperl-l mailing list
> >>  Bioperl-l at portal.open-bio.org
> >>  http://portal.open-bio.org/mailman/listinfo/bioperl-l
> >>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list