Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Lyn Hsiong
    Member
    • Sep 2011
    • 14

    Errors in my bioperl script. Thanks in advance!

    Dear friends:

    I have a blast report, and want to extract following information for each result(query): the Query_name, hit_number, name and description of the hit(HSP) with the highest identity.

    my bioperl script is:
    Code:
    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use Bio::SearchIO;
    
    if (@ARGV != 2){die "Usage: $0 <BLAST-report-file> <output-file>\n"};
    
    my ($infile,$outfile) = @ARGV;
    print "Parsing the BLAST result ...";
    my $blast = new Bio::SearchIO(
    -format => 'blast',
    -file   => $infile);
    open (OUT,">$outfile") or die "Cannot open $outfile: $!";
    
    print OUT "query\tNumber of hits\tGreatest identity %\tAccession (identity %)\tDescription (identity %)\n";
    
    while (my $result = $blast->next_result){
       print OUT $result->query_name . "\t";
       print OUT $result->num_hits. "\t";
            if (my $hit = &sort_hit($result)){
                             if (my $hsp=$hit->hsp){
                                            print OUT $hsp->percent_identity. "\t"; 
                                            print OUT $hit->accession. "\t";
                                            print OUT $hit->description. "\n";
                                }                   
               }
        }
     close OUT;
     print " DONE!!!\n";
    
     sub sort_hit{
                      my $result = shift;
                      my @hits;
                      while (my $hit = $result->next_hit) {
                            push @hits, $hit;
                            }
                      my @hit_sort = sort { $b-> hsp ->percent_identity * 100 <=> $a-> hsp ->percent_identity * 100 } @hits;
                      $result->rewind;
                      my $flag=0;
                      my $temp_hit;
                      while (my $hit=$result->next_hit){
                            if($flag==0){
                               $temp_hit=$hit;
                         $flag++;
                               }
                      return $temp_hit
                            }
             }
    error information:
    -------------EXCEPTION: Bio::Root::Exception -------------
    MSG: Can't get HSPs: data not collected.
    STACK: Error::throw
    STACK: Bio::Root::Root::throw /home/xiongtl/Bioperl/dag/lib/perl5/Bio/Root/Root.pm:368
    STACK: Bio::Search::Hit::GenericHit::hsp /home/xiongtl/Bioperl/dag/lib/perl5/Bio/Search/Hit/GenericHit.pm:688
    STACK: main::sort_hit xtl_new.pl:37
    STACK: xtl_new.pl:20
    -----------------------------------------------------------
    Parsing the BLAST result ...
    I don't know what does it mean. Please give me some clues, all your words are welcome!


    NOTE:
    BTW, my bioperl version is 1.6.1, I use blastx 2.2.27+.
    My blast report(-outfmt 0) have many queries and each query have many hits(against nr database), so each hit maybe also have several HSPs.
    Last edited by Lyn Hsiong; 06-06-2013, 05:50 PM. Reason: extra information
  • Torst
    Senior Member
    • Apr 2008
    • 275

    #2
    Do you mean $hit->next_hsp instead of $hit->hsp ?

    Comment

    • Lyn Hsiong
      Member
      • Sep 2011
      • 14

      #3
      Originally posted by Torst View Post
      Do you mean $hit->next_hsp instead of $hit->hsp ?
      Thanks for your reply!
      I tried the $hit->next_hsp before, but running the script still informed me the same error. However, today I have just reruned the script, both $hit->next_hsp and $hit->hsp are ok! They both outputed the first hit for each result. I don't know why. So I tried different sort rules as follows:

      # my @hit_sort = sort { $b-> hsp ->hsp_length <=> $a-> hsp ->hsp_length } @hits;
      # my @hit_sort = sort { $b-> hsp ->percent_identity * 100 <=> $a-> hsp ->percent_identity * 100 } @hits;
      # my @hit_sort = sort { $b-> significance <=> $a-> significance } @hits;
      # my @hit_sort = sort { $a-> accession cmp $b-> accession } @hits;
      but different sort functions still generate the same output (still the first hit)! It seems that the sub-function does not work at all!
      oh, it really troubles me...

      Comment

      Latest Articles

      Collapse

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, Yesterday, 10:09 AM
      0 responses
      10 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-04-2026, 08:59 AM
      0 responses
      20 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-02-2026, 12:03 PM
      0 responses
      27 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-02-2026, 11:40 AM
      0 responses
      21 views
      0 reactions
      Last Post SEQadmin2  
      Working...