Bioperl: Bioperl SEQ functions

Matthew Pocock mrp@sanger.ac.uk
Thu, 01 Jul 1999 11:56:29 +0100


Hi.

Andrew Dalke wrote:

> Aaron J Mackey <ajm6q@virginia.edu> suggested sample code
> of the form:
> > print Bio::Tools::Hydrophobicity->kyte_doolittle($seq); # yee haw!
>
> Following is some software philosophy.  I am against this
> style of interface because it requires the underlying code
> to have too much duplication.  Here's why, and a different
> (IMO better :) solution.

Interface definitions shouldn't require any code duplication. Common
implementation code can almost always be either put in a base-class (if
the code defines an algorithm, flow of control, plan), or in a mixin
module (if it provides some service, data).

> <snip/>

>   The general principle is: push decision logic up as early as you
> can, not embedded in the code.  This simplifies the code, and
> if you ever have to do code coverage testing, simplifies your
> test case development by a lot.

Also, there should be an object to represent a process, a type of objects
for each part of the process that can change independantly of the others
(who's abstract methods are called by the process object, not the client
code), and all client code should know interfaces, not absolute types. I
think in this case, we have an object that scores a sequence against a
scale, with one method for scoring the whole sequence and one for scoring
a window. We also have many different types of objects that represent
different scores. Mabey the interface we are talking about would let us
write code like this:

use Bio::Tools::Scale::Hydrophobicity;
use Bio::Tools::Scale::MolecularWeight;
use Bio::Tools::SequenceScorer;

$scorer = new Bio::Tools::SequenceScorer;
$m = Bio::Tools::Scale::MolecularWeight->getScale('mw');
$d = Bio::Tools::Scale::Hydrophobicity->getScale('kyte_doolittle');
$e = Bio::Tools::Scale::Hydrophobicity->getScale('esg');

print $scorer->score($seq, $m);
print $scorer->score($seq, $d);
print $scorer->score($seq, $e);

print $scorer->score_window($seq, $m, 10, 14);

This looks more like factory methods, and unifies all the interfaces. The
values of $m, $d, $e can be either a hash, or something more complicated,
but the client code doesn't care. That is up to Bio::Tools::Scorer,
Bio::Tools::AbstractScale and Bio::Tools::AbstractScaleFactory to sort out
between them.

Just my 2c - probably design overkill on my part, but that is how I would
like to use it in a script.

>
>
>                                                 Andrew Dalke
>                                                 dalke@bioreason.com
> =========== Bioperl Project Mailing List Message Footer =======
> Project URL: http://bio.perl.org/
> For info about how to (un)subscribe, where messages are archived, etc:
> http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl.html
> ====================================================================

=========== Bioperl Project Mailing List Message Footer =======
Project URL: http://bio.perl.org/
For info about how to (un)subscribe, where messages are archived, etc:
http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl.html
====================================================================