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

Jason Stajich jason@cgt.mc.duke.edu
Mon, 11 Nov 2002 15:42:14 -0500 (EST)


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

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