[Bioperl-l] Cloning Bio::Search::Result::GenericResult
Chris Fields
cjfields at illinois.edu
Mon May 31 13:54:22 UTC 2010
My concern is to ensure we aren't filtering twice as much (one at the hit level, one pass at the HSP level). It should be one pass.
chris
On May 31, 2010, at 8:47 AM, Remi wrote:
> Yes, at the hit level everything works fine.
> Actually, at the hsp level, the alignment part is not written to the HTML file but the description before the alignment and the description of the hit at the beginning of the file are written.
>
> I had a quick look to the code and I'm not sure this is a bug.
>
> Chris Fields wrote:
>> That sounds like a bug. Does filtering at the hit level work around this?
>>
>> sub hit_filter {
>> my $hit = shift;
>> # filter hsps here
>> my @passing_hsps = grep { hsp_filter($_) } $hit->hsps;
>> @passing_hsps;
>> }
>>
>> sub hsp_filter {
>> # original filter
>> }
>>
>> chris
>>
>> On May 31, 2010, at 4:19 AM, Remi wrote:
>>
>>
>>> Hi,
>>>
>>> Everything is working well but there is still one point that giving me some trouble.
>>> When I filter the hsps and all the hsps of a given hit are removed, the description line of the hit is still present in the HTML file.
>>> Is there a way to get rid of this description line ?
>>> Is the only solution to inherit from Bio::SearchIO::Writer::HTMLWriter and overriding the "to_string" method ?
>>>
>>> Thanks,
>>>
>>> Rémi
>>>
>>>
>>> Chris Fields wrote:
>>>
>>>> Let us know how it goes, and if you run into any bugs.
>>>>
>>>> chris
>>>>
>>>> On May 28, 2010, at 9:31 AM, Remi wrote:
>>>>
>>>>
>>>>
>>>>> Thank you very much !!!!
>>>>> I'm gonna try it right away
>>>>>
>>>>> Chris Fields wrote:
>>>>>
>>>>>
>>>>>> 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
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
>
> _______________________________________________
> 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