Bioperl-guts: Re: Bioperl: 0.05 pre release

Ewan Birney
Tue, 23 Mar 1999 06:58:43 -0100

On Mon, 22 Mar 1999, Steve Chervitz wrote:

>  > 
>  > #2. Otherwise you get into the rediculous situtation where you have code
>  > like:
>  > $prot = Bio::Seq->new(Bio::Seq->new($seq->reverse)->translate);
>  > rather than:
>  > $prot = $seq->reverse()->translate();
> I also like the chaining of method calls that returning objects
> provides. I think a nice compromise would be to allow both #1 and #2
> by differentiating the method calls or providing a special argument to 
> make it obvious what the return type is. So we could have
>    $seq = translate_seq();  # returns a new Bio::Seq
>    $str = translate_str();  # returns a string
> or
>   $seq = translate(-return_type => 'seq');    # returns a string
>   $str = translate(-return_type => 'string'); # returns a string

Hmmm. I am still favouring a vanilla #2 method. Reasons -

a) No real gain in efficiency for _str methods

$str = $seq->translate()->str(); is only marginally trickier than
$str = $seq->translate_str();

b) Encourages two different implementations of translate, as str will
have to produce strings and translate_seq might want to hide things in
a complex object. Two methods - twice the bugs

c) So now do we have to provide a @arr = $seq->translate_arr(); or all
the pairwise combinations of factories and accessors? No ... but you get
the gist.


I think we can solve this problem by good documentation. I don't think
we need to solve in code. When we start coding to make up for deficiencies
in our documentation, that is a worry...

However, I have to admit this is the perl way to do things (not be
orthoganal, but cut corners when corners need to be cut). So... the
culture that we live does lend some credence to this idea.

> You know what would be cool? A wantobject() method that could detect
> when a method was being called in a context that requires an object
> reference. This would actually be a very perlish thing to do:

Indeed. It is this sort of Perl thing that gives me the heebie-jeebies and
makes me want to say 'no' - I am going to start a bio python project/bio
java project. Get me out!

>   sub translate {
>     my $self = shift;
>     my $translation_str = $self->get_translation();
>     wantobject 
>       ? return new Bio::Seq(-seq=>$translation_str)
>       : return $translation_str;
>   }
> You could also test for wantarray if wantobject fails and provide the
> residues in an array as well. I wonder if a wantobject functionality
> has been proposed and if so, if it could be implemented efficiently. 
> One for the perl porters... 

I am secretly hoping they wont do it ;)

> Note that reverse, complement, revcom, and translate all take optional
> start and stop arguments, so this optimization is already there (and
> you save a method call).

But only if you know how to do it. You are overestimating our users...

> SteveC

Ewan Birney

=========== Bioperl Project Mailing List Message Footer =======
Project URL:
For info about how to (un)subscribe, where messages are archived, etc: