[Biopython] Subclassing Seq and SeqRecord

Jose Blanca jblanca at btc.upv.es
Tue Nov 24 10:32:55 UTC 2009


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)

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.
Regards,

-- 
Jose M. Blanca Postigo
Instituto Universitario de Conservacion y
Mejora de la Agrodiversidad Valenciana (COMAV)
Universidad Politecnica de Valencia (UPV)
Edificio CPI (Ciudad Politecnica de la Innovacion), 8E
46022 Valencia (SPAIN)
Tlf.:+34-96-3877000 (ext 88473)



More information about the Biopython mailing list