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
        Best Practices for Single-Cell Sequencing Analysis
        by seqadmin



        While isolating and preparing single cells for sequencing was historically the bottleneck, recent technological advancements have shifted the challenge to data analysis. This highlights the rapidly evolving nature of single-cell sequencing. The inherent complexity of single-cell analysis has intensified with the surge in data volume and the incorporation of diverse and more complex datasets. This article explores the challenges in analysis, examines common pitfalls, offers...
        06-06-2024, 07:15 AM
      • seqadmin
        Latest Developments in Precision Medicine
        by seqadmin



        Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

        Somatic Genomics
        “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
        05-24-2024, 01:16 PM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 06-21-2024, 07:49 AM
      0 responses
      14 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-20-2024, 07:23 AM
      0 responses
      14 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-17-2024, 06:54 AM
      0 responses
      16 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-14-2024, 07:24 AM
      0 responses
      25 views
      0 likes
      Last Post seqadmin  
      Working...
      X