[Bioperl-l] passing $result

Jason Stajich jason at cgt.duhs.duke.edu
Wed Nov 12 12:41:17 EST 2003


Two things - you don't want to call print_graph with $result - remove the
inner while( my $hit ...) loop if you want to operate on $result objs.

Second - remember that the next_XXX methods indicate an iterator.  So if
all the hits have already been processed (i.e. you have called next_hit
until it returns undef) then calling it again will also return undef.  You
have 2 options.   Get the list of all the hits -- my @hits = $result->hits;
Or call $result->_rewind to reset the iterator to the beginning of the
list of hits.   Examples of code that does this sort of thing are in
SearchIO::Writer::XXX, HTMLResultWriter for example.

Note that some future implementations may not support _rewind for various
reasons as it requires us to keep all the hits and hsps in memory for a
Result, but all the current implementations do support this.

-jason

On Wed, 12 Nov 2003, Joshua A Udall wrote:

> Bioperl -
>
> I'm having trouble passing an object and I seem only able to pass part of
> it, the first 'layer'.  I'm trying to pass $result (from blast parsing)
> into a function and access the hits but they seem to have
> disappeared.  What is the correct syntax to pass $result as a whole object?
>
> while(my $result = $searchio->next_result() ) {
>      while (my $hit=$result->next_hit){
>            print_graph($result);
>      }
> }
>
> sub print_graph {
>    my $result_sub = $_[0];
>    while( my $hit = $result_sub->next_hit ) {
>
> ... and do groovy stuff here with the hits
>
>    }
> }
>
>
>
>
>
> Joshua Udall
> Department of Ecology, Evolution, and Organismal Biology
> Iowa State University
> Ames, IA 50011
> Ph: (515) 294-7098
> Fax: (515) 294-1337
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>

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


More information about the Bioperl-l mailing list