[Bioperl-l] desperate: what's wrong with this code

shawnh@fugu-sg.org shawnh@fugu-sg.org
Sat, 16 Nov 2002 20:28:23 +0800 (SGT)


hi Nathanael,

I'm not sure where $hashref->{infile} is coming from.

The slightly modified code for me works:

use Bio::SearchIO;

my $parser = Bio::SearchIO->new( -file => $ARGV[0], -format =>
'blastxml' );
my $regex = qr/yaddayadda/;
while ( my $result = $parser->next_result ) {
     while ( my $hit = $result->next_hit ) {
          while ( my $hsp = $hit->next_hsp ) {
               if ( $hit->description =~ m/$regex/ ) {
                    print $result->query_name," hit ",$hit->name,"\n",
                              $hsp->query_string,"\n"
               } else {
                    print $result->query_name," hit ",$hit->name,"\n",
                              $hsp->query_string,"\n"
               }
           }
     }
}

running this 
perl test.pl t/data/plague_yeast.bls.xml

gives me

gi|5763815|emb|CAB53168.1| hit gi|6320063|ref|NP_010143.1|
KVYRVMVLEGTIAESIEHLDKKENEDILNNNRNRIVLADNTVINFDNISQLKEFLRRSVNIVDHDIFSSNGFEG--------------FNPTSHFPSNPSSDYFNSTGVTFGSGVDLGQRSKQDLLNDGVPQYIADRLDGYY

maybe you want to print $hashref->{infile} to make sure you are specifying the
file you need.

I'm running bioperl1.02 and perl5.6 as well.

cheers,

shawn


> 
> #code snippet
> 
> use lib qw( /home/nkuipers/modules/lib/site_perl/5.6.0 );
> use Bio::SearchIO;
> 
> open FH1, ">>output" or die $!;
> open FH2, ">>bunk"   or die $!; #not really :)
> my $parser = Bio::SearchIO->new( -file => $hashref->{infile}, -format => 
> 'blastxml' );
> my $regex = qr/yaddayadda/;
> while ( my $result = $parser->next_result ) {
>      while ( my $hit = $result->next_hit ) {
>           while ( my $hsp = $hit->next_hsp ) {
>                if ( $hit->description =~ m/$regex/ ) {
>                     print FH1 $result->query_name," hit ",$hit->name,"\n",
>                               $hsp->query_string,"\n"
>                } else {
>                     print FH2 $result->query_name," hit ",$hit->name,"\n",
>                               $hsp->query_string,"\n"
>                }
>            }
>      }
> }
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
> 

-- 
********************************
* Shawn Hoon
* http://www.fugu-sg.org/~shawnh
********************************