[Bioperl-l] Subclassing Bio::Seq ? Extending Bio::Perl
hlapp at gmx.net
Tue Oct 24 18:57:02 UTC 2006
On Oct 24, 2006, at 1:59 PM, JK ((Jesper Agerbo Krogh)) wrote:
>> I think you've generally taken the right path, but see below.
>> First off, object factories are used extensively already but not yet
>> in each and every place where Bioperl creates an object internally.
>> Achieving your goal may entail fixes to Bioperl to use a factory
>> instead of a hard-coded module name. Also be on the lookout for
>> factory() or seq_factory() methods for classes whose work entails
>> creating sequence objects and that already give you control over the
>> type to be created.
> Can you elaborate/describe this a bit more?
See for example the POD of Bio::SeqIO (sorry, the method is called
>> The reason that this is a Bio::PrimarySeq and not a Bio::Seq or your
>> extension of the latter is that the Perl garbage collector can't deal
>> with circular references.
> Doesn't Scalar::Util::weaken solve that?
You're welcome to test and try. It should be a simple change in
Bio::Seq::add_SeqFeature(). You will see that it is this method and
not the feature object that makes sure the wrapped primarySeq gets
passed as sequence reference. Just change that to creating a new
reference to the sequence object and make it a weak reference before
passing it to the feature object.
(The feature object has no requirement (or knowledge) that the
referenced sequence object is a PrimarySeq.)
>> Having said all that, note that if all what you want to do is
>> defining computations on Bio::Seq objects, as opposed to storing
>> values for additional attributes, the best design approach is not to
>> extend the class but to create a class with those computations as
>> static methods (which would accept the seq object on which to compute
>> as an argument; e.g., print $seqComputations->message_digest($seq)).
> I could but there are some functionality that I'd by design would
> like to
> have available on every sequence in the system. This way I would
> end up
> coding the functionality for getting the message_digest every place
> I needed to get the value (which would be quite often in this
> whereas it by design belongs into the Bio::Seq-stuff.
I'm not following you why this would make any difference (it would be
$seq->message_digest() compared to $seqCompute->message_digest
($seq)), unless what you are saying is that you would like to cache
the result of the computation.
: Hilmar Lapp -:- Durham, NC -:- hlapp at gmx dot net :
More information about the Bioperl-l