[Bioperl-l] seq_inds method question for blast parsing...

Sajeev Batra US-OPERON-Alameda batra@OPERON.com
Mon, 11 Nov 2002 14:21:26 -0800


Thanks Jason, 
You mention below that currently for the time being I should use the
iterator interface.  Do you mean the following as in below?  But I still get
the same error.  Do you have a tip to avoid this error below in the simple
code shown.

Thanks again,
Sajeev.
------------------------
My error; 
Can't locate object method "hits" via package
"Bio::Search::Result::GenericResult" at ./custom_writer_sajeev2.pl line 14,
<STDIN> line 315.

-------------------------
My code: 

#!/usr/bin/perl

                                                                      
use Bio::SearchIO;
my $blast_report = new Bio::SearchIO ('-format' => 'blast',
                                      '-fh'   => \*STDIN
                                      );
my $result = $blast_report->next_result;
while( my $hit = $result->next_hit()) {
    print "\thit name: ", $hit->name(), "\n";
    while( my $hsp = $hit->next_hsp()) { 
        print "E: ", $hsp->evalue(), "frac_identical: ", 
        $hsp->frac_identical(), "\n";
        @seq_inds_array = $hsp->seq_inds('query','identical',1);
        print "@seq_inds_array\n";

    }
} 
 
----------------------------------------------------------------------------
---







-----Original Message-----
From: Jason Stajich [mailto:jason@cgt.mc.duke.edu]
Sent: Monday, November 11, 2002 12:52 PM
To: Sajeev Batra
Cc: bioperl-l@bioperl.org
Subject: Re: [Bioperl-l] seq_inds method question for blast parsing...


On Mon, 11 Nov 2002, Jason Stajich wrote:

> On Mon, 11 Nov 2002, Sajeev Batra wrote:
>
> > Hi Jason and others,
> > A while back you suggested if I want to useq the seq_inds() method for
> > Washu and NCBI blastn output, that I should use the 'blast' format in
> > SearchIO instead of 'psiblast'.  Thank you for your tip but
> > I tried to that but need another tip from you guys.
> >
> > Here's my error msg:
> > Can't locate object method "hits" via package
> > "Bio::Search::Result::GenericResult" at ./custom_writer_sajeev2.pl line
> > 48, <STDIN> line 315.
> >

> It's been ported into the latest code - just use the
>
Sorry - meaning: you can use your construct below on the latest code,
however in the meantime use the iterator interface:

> while( my $hit = $result->next_hit ) {
>
> }
> instead of your foreach loop.
>
> If you're calling this function more than once on the same result object,
> call $result->rewind
>
> > Any suggestions?  Does anyone have a sample code in where they are using
> > the seq_inds function for the 'blast' format successfully?  Your
>
> yep - and there is a test for it in t/SearchIO.t
>
> > feedback is appreciated and thank you.
> > Sajeev.
> >
> > Here's my code:
> >
> > use strict;
> > use lib '../../../';
> > use Bio::Root::Root;
> > use Bio::SearchIO::SearchWriterI;
> >
> > use vars qw( @ISA );
> > @ISA = qw( Bio::Root::Root Bio::SearchIO::SearchWriterI );
> >
> > sub to_string {
> >     my ($self, $result, @args) = @_;
> >     my $str = '';
> >
> >     my $hits_reported = 0;
> >
> >     foreach my $hit($result->hits) {
> >
> >       $hits_reported++;
> >
> >       my @seq_inds_array = $hit->seq_inds('query','identical',1);
> >       my @test_inds_array = $hit->seq_inds('subject','identical',1);
> >
> >       my $query_matches = $#seq_inds_array  + 1;
> >
> >       print "seq_inds_array id ",@seq_inds_array, "\n";
> >       print "test_inds_array co ",@test_inds_array,"\n";
> >
> >
> >       $str .= sprintf "%s\t%s\t%d\t%d\t%d\t%d\t%d\t%.1e\t%d\t%d\t%f\n",
> >                 $result->query_name, $hit->name, $result->query_length,
> >                 $hit->length,
> >                 $hit->score, $hit->bits, $hit->iteration, $hit->expect,
> >                 $query_matches, $hit->length_aln('query'),
> > $hit->frac_identical('query');
> >
> >     }
> >
> >
> >     $str;
> >
> > }
> > package main;
> >
> > #===================================================
> > # Start of script
> > #===================================================
> >
> > use strict;
> >
> > use lib '../../../';
> > use Bio::SearchIO;
> >
> > select STDOUT; $|=1;
> >
> > my $in     = Bio::SearchIO->new( -format => 'blast' );
> > my $writer = MyBlastWriter->new();
> > my $out    = Bio::SearchIO->new( -format => 'blast',
> >      -writer => $writer );
> >
> > while ( my $result = $in->next_result() ) {
> >     #printf STDERR "Report %d: $result\n", $in->report_count;
> >     $out->write_result($result);
> > }
> >
> >
> >
> > _______________________________________________
> > Bioperl-l mailing list
> > Bioperl-l@bioperl.org
> > http://bioperl.org/mailman/listinfo/bioperl-l
> >
>
>

-- 
Jason Stajich
Duke University
jason at cgt.mc.duke.edu