[Bioperl-l] Alternate hit sorting for Bio::Search::Result objects

Jason Stajich jason at cgt.duhs.duke.edu
Tue Dec 23 16:20:56 EST 2003


So Don - you want to apply a custom hit sorting routine to the data before
it is output with SearchIO::HTMLResultWriter?

The simpliest - albeit cheating and prone problems if there are changes
in the module - but is pretty easy to do:

@{$result->{'_hits'}} = sort { your custom sort here }
                        @{$result->{'_hits'}};

Perhaps we should add an API method which can get/set the Hits.

You can also create a new Result object in an albeit tedious manner:

my @hits = sort { #custom hits } $result->hits();

my $rewres = $result->new(-query_name  => $result->query_name,
                       -query_accession  => $result->query_accession,
	               -query_description => $result->query_description,
	               -query_length     => $result->query_length,
                       -database_name    => $result->database_name,
	               ... # lots more things.
                       -hits            => \@hits);


So you put all of this in to play like this
my $in = new Bio::SearchIO(-format => 'blast',
                             -file   => shift @ARGV);

my $writer = new Bio::SearchIO::Writer::HTMLResultWriter();
my $out = new Bio::SearchIO(-writer => $writer);
my $result = $in->next_result;
# apply the sorting on the hits
#

# now write the result out
$out->write_result($result);



-jason



On Tue, 23 Dec 2003, Donald G. Jackson wrote:

> Hi,
>
> I'm working on a blast wrapper using Bio::SearchIO.  I'd like to be able
> to sort through the hits by something besides score/input order.  For
> example, we've crammed the taxid into the FASTA header and would like to
> do something like NCBI's taxblast where hits are sorted by source
> organism, then by score.  I'd like to use the
> Bio::SearchIO::HTMLResultWriter to output my hits, so can't just get all
> the hits and sort them myself.
>
> I thought I'd seen mention of how to do this, but looking over the docs
> and (1.2.3) code I can't find it.  Does anyone have thoughts on how to
> do this?
>
> Thanks,
>
> Don Jackson
> BMS Bioinformatics
>
> _______________________________________________
> 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