[Bioperl-l] Subclassing Bio::Seq ? Extending Bio::Perl

JK (Jesper Agerbo Krogh) JK at novozymes.com
Tue Oct 24 17:59:10 UTC 2006

> 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? 

> The problem that hits you here though isn't one of determining the  
> type of the object to be created, because the respective method  
> doesn't create a sequence object. It only returns the sequence object  
> that the feature has a reference to.

This was what Data::Dumper told me, but stuff I'd likewise would like to 
change was to get a RichSeq object returned every-time from Bio::Seq, adding
in the stuff that allways seems appropriate. 

> 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? 

> 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 that
I needed to get the value (which would be quite often in this application), 
whereas it by design belongs into the Bio::Seq-stuff. 


More information about the Bioperl-l mailing list