[Biopython] Subclassing Seq and SeqRecord
Peter Cock
p.j.a.cock at googlemail.com
Tue Nov 24 05:53:40 EST 2009
On Tue, Nov 24, 2009 at 10:32 AM, Jose Blanca <jblanca at btc.upv.es> wrote:
> Hi:
> I'm "Biopythoniing" my utilities. I want to subclass Seq and SeqRecord to
> modify a little its behaviour. for instance I'm doing:
>
> from Bio.Seq import Seq as BioSeq
>
> class Seq(BioSeq):
> 'A biopython Seq with some extra functionality'
> def __eq__(self, seq):
> 'It checks if the given seq is equal to this one'
> return str(self) == str(seq)
That is something I have been meaning to bring up on the list. I
started chatting to Brad about this at BOSC2009. The details get
quite hairy with hashes and dictionaries and so on, so I will leave
it to another email.
> The problem is that to modify this behaviour I have to copy a lot of Seq
> methods because this methods create new Seq instances to return. This
> instances are created like:
> return Seq(str(self).replace('T','U').replace('t','u'), alphabet)
>
> would it be possible to change that to:
> return self.__class__(str(self).replace('T','U').replace('t','u'), alphabet)
>
> In that way the new instance would be created using the subclassed
> class and not the Seq class. Is that a reasonable change? In that
> case I could prepare a patch for Seq and SeqRecord.
It is a reasonable change, but ONLY if all the subclasses support
the same __init__ method, which isn't true. For example, the
Bio.Seq.UnknownSeq subclasses Seq and uses a different __init__
method signature. This means any change would at a minimum
have to include lots of fixes to the UnknownSeq
More information about the Biopython
mailing list