[Biopython-dev] derive from Seq

Peter biopython-dev at maubp.freeserve.co.uk
Tue Apr 22 13:27:38 EDT 2008


Hi Matthias,

> ... I've started to write a derived class which overwrites some of the
> methods from the Seq - especially __getitem__ - and I run quite fast
> into problems. E.g. the complement method returns a Seq object.
>
>  The desired behaviour would be to return an instance of my derived class
>  .. This could be done easily with self.__class__(s, self.alphabet).

That has been raised before (although I don't think anyone filed a
bug) and as I recall, changing this lead to some unexpected side
effects (failures in the test suite).  If you fancy trying this
change, and digging into what (if anything) breaks as a result, that
would be very helpful.

>  Unfortunately the __init__ method of my derived class has a third
>  parameter (with default value) which sets the sequence to circular / linear.
>  This could be done with copy or clone methods.
>
>  So you see that there are problems when deriving from the Seq class. What
>  is the best (or a good) strategy for deriving classes from Seq?

Maybe for now your best bet is to subclass, and then write your own
(reverse)complement method which calls the base-class to do the work,
and then transforms the resulting Seq object into your own CircularSeq
object.  Unfortunately, you would probably have to do something
similar for other problematic methods (until the base class is fixed).

Out of interest, how do you interpret integers in your CircularSeq's
__getitem__ method?  Python's existing negative index behaviour seems
to be ideal, for example -1 already returns the last letter.  I'd
guess you make values longer than the sequence length simply wrap.  Is
that the only change or do you alter the splice behaviour too (this is
where it gets tricky).

Peter


More information about the Biopython-dev mailing list