[Bioperl-l] Cloning Bio::Search::Result::GenericResult

Chris Fields cjfields at illinois.edu
Fri May 28 13:25:54 UTC 2010


Remi,

Using the constructor that way is not supported.  But it's completely unnecessary.  

Are you using Bio::SearchIO::Writer::HTMLWriter?  It filters results/hits/HSPs as it writes the HTML, no need to clone.  That in combination with GenericResult::rewind() should work.  You can use that module, or inherit and override whatever methods are necessary.  Or just use it as a reference on how to do what you need.  

Something like the following should work (of course completely untested :)

my $result = $in->next_result;

# filter on HSP
write_html('result1.html', $result, { 'HSP' => \&hsp_filter });

# rewind the result to go back to the beginning
$result->rewind;

# open a new filehandle here for second report output
# filter on hit and HSP
write_html('result2.html', $result, { 'HIT' => \&hit_filter,
                           'HSP' => \&hsp_filter });

# rewind the result to go back to the beginning
$result->rewind;

# and so on....

sub write_html {
    my ($file, $result, $filters) =  @_;
    # note that $filter is a hash ref above
    my $writer = Bio::SearchIO::Writer::HTMLResultWriter->new
                     (-filters => $filters );

    my $out = Bio::SearchIO->new(-writer => $writer, -file => $file); 
    $out->write_result($result);
}

sub hsp_filter { 
    my $hsp = shift;
    return 1 if $hsp->length('total') > 100;
}

sub hit_filter { 
    my $hit = shift;
    return 1 if $hit->significance < 1e-5;
}

chris


On May 28, 2010, at 7:17 AM, Remi wrote:

> You're right, it's not working there is some missing fields ...
> 
> Actually, I'm writing a script that filter Result Object based on some criteria and I want the script to be kind of interactive like :
> 
> -Display Result object as HTML
> -Ask for filter criteria
> -Filter Result object
> -Display filtered Result object as HTML.
> ... etc
> 
> And I would like to make a copy of the Result object before each filtering step in order to be able to redo it.
> 
> I'll have a look to the modules you've mentioned, thanks.
> 
> 
> 
> 
> Dave Messina wrote:
>> Hi Rémi,
>> 
>> As far as I know, cloning objects is not natively supported in BioPerl (or Perl itself, for that matter).
>> 
>> So I don't think the code you showed will work.
>> 
>> However, there are modules such as Clone::More and Clone::Fast that can do it.
>> 
>> http://search.cpan.org/~wazzuteke/Clone-More-0.90.2/lib/Clone/More.pm
>> http://search.cpan.org/~wazzuteke/Clone-Fast-0.93/lib/Clone/Fast.pm
>> 
>> 
>> Out of curiosity, what are you trying to do with the cloned objects? Someone might be able to suggest another way to accomplish the same goal.
>> 
>> Dave
>> 
>> 
>>  
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l





More information about the Bioperl-l mailing list