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
        Recent Advances in Sequencing Analysis Tools
        by seqadmin


        The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
        05-06-2024, 07:48 AM
      • seqadmin
        Essential Discoveries and Tools in Epitranscriptomics
        by seqadmin




        The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
        04-22-2024, 07:01 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 05-07-2024, 06:57 AM
      0 responses
      12 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 05-06-2024, 07:17 AM
      0 responses
      16 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 05-02-2024, 08:06 AM
      0 responses
      21 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-30-2024, 12:17 PM
      0 responses
      24 views
      0 likes
      Last Post seqadmin  
      Working...
      X