Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

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

    Comment


    • #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

      • seqadmin
        Strategies for Sequencing Challenging Samples
        by seqadmin


        Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
        03-22-2024, 06:39 AM
      • seqadmin
        Techniques and Challenges in Conservation Genomics
        by seqadmin



        The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

        Avian Conservation
        Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
        03-08-2024, 10:41 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, Yesterday, 06:37 PM
      0 responses
      8 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, Yesterday, 06:07 PM
      0 responses
      8 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 03-22-2024, 10:03 AM
      0 responses
      49 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 03-21-2024, 07:32 AM
      0 responses
      66 views
      0 likes
      Last Post seqadmin  
      Working...
      X