[Bioperl-l] Writer filters

Jason Stajich jason@cgt.mc.duke.edu
Sat, 23 Nov 2002 10:52:30 -0500 (EST)


You can now provide a filter for Result,Hit,or HSPs when using the
SearchIO::Writer objects to restrict the output to a subset of the data.

This works for the tablewriters as well as the blast report outputters
TextResultWriters and HTMLResultWriters

The basic example is if you had a BLAST report and only wanted to see the
Hits above a certain e-value (or something more clever of course).

#!/usr/bin/perl -w
use strict;
use Bio::SearchIO;
use Bio::SearchIO::Writer::TextResultWriter;

my $in = new Bio::SearchIO(-format => 'blast',
			   -file   => 'AAC12660_swissprot.bls');


my $writer = new Bio::SearchIO::Writer::TextResultWriter(-filters =>
{'HIT'=>\&hit_filter});
my $out = Bio::SearchIO->new( -writer => $writer );

while ( my $result = $in->next_result() ) {
    $out->write_result($result, ($in->result_count - 1 ? 0 : 1) );
}

sub hit_filter{
    my $hit = shift;
    ( $hit->significance < 0.001);
}

-jason

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