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
        Genetic Variation in Immunogenetics and Antibody Diversity
        by seqadmin



        The field of immunogenetics explores how genetic variations influence immune responses and susceptibility to disease. In a recent SEQanswers webinar, Oscar Rodriguez, Ph.D., Postdoctoral Researcher at the University of Louisville, and Ruben Martínez Barricarte, Ph.D., Assistant Professor of Medicine at Vanderbilt University, shared recent advancements in immunogenetics. This article discusses their research on genetic variation in antibody loci, antibody production processes,...
        11-06-2024, 07:24 PM
      • seqadmin
        Choosing Between NGS and qPCR
        by seqadmin



        Next-generation sequencing (NGS) and quantitative polymerase chain reaction (qPCR) are essential techniques for investigating the genome, transcriptome, and epigenome. In many cases, choosing the appropriate technique is straightforward, but in others, it can be more challenging to determine the most effective option. A simple distinction is that smaller, more focused projects are typically better suited for qPCR, while larger, more complex datasets benefit from NGS. However,...
        10-18-2024, 07:11 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, Today, 11:09 AM
      0 responses
      22 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, Today, 06:13 AM
      0 responses
      20 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 11-01-2024, 06:09 AM
      0 responses
      30 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 10-30-2024, 05:31 AM
      0 responses
      21 views
      0 likes
      Last Post seqadmin  
      Working...
      X