[BioPython] how to add new methods to class Seq ?

Frederic Sohm frederic.sohm at iaf.cnrs-gif.fr
Wed Oct 5 02:40:03 EDT 2005


Hi

The best practice would commend to write a new class inheriting from Seq.
Here is an example :

>>> from Bio.Seq import Seq
>>> class myseq(Seq) :
	def tolist(self) :
		return list(self.tostring())

	
>>> s = myseq('ACGT')
>>> s.tolist()
['A', 'C', 'G', 'T']
>>> dir(Seq)
['_Seq__maketrans', '__add__', '__doc__', '__getitem__', '__getslice__', 
'__init__', '__len__', '__module__', '__radd__', '__repr__', '__str__', 
'complement', 'count', 'reverse_complement', 'tomutable', 'tostring']
>>> dir(myseq)
['_Seq__maketrans', '__add__', '__doc__', '__getitem__', '__getslice__', 
'__init__', '__len__', '__module__', '__radd__', '__repr__', '__str__', 
'complement', 'count', 'reverse_complement', 'tolist', 'tomutable', 
'tostring']
>>> 


Le Mardi 4 Octobre 2005 20:33, Jose Borreguero a écrit :
> Hi all,
> I'm new to biopython (and python!), and wondering the efficient way to add
> methods of my own to class Seq for my in-house computing. Should I (1) open
> the code and start ading add methods; (2) instantiate a derived class from
> Seq and write there my methods; (3) what else?
> jose
>
> _______________________________________________
> BioPython mailing list  -  BioPython at biopython.org
> http://biopython.org/mailman/listinfo/biopython

-- 
Frédéric Sohm
Equipe INRA U1126 "Morphogenèse du système nerveux des Chordés"
UPR 2197 DEPSN, CNRS
Institut de Neurosciences A. Fessard
1 Avenue de la Terrasse
91 198 GIF-SUR-YVETTE
FRANCE
Phone: +33 (0) 1 69 82 34 12
Fax:+33 (0) 1 69 82 34 47



More information about the BioPython mailing list