[BioPython] Sequence numbering. Moving on...

Jeffrey Chang jchang@SMI.Stanford.EDU
Tue, 28 Sep 1999 00:22:27 -0700 (PDT)


Thanks.  I've added a link to it on the Sequence Object web page.
http://www.biopython.org/Projects/SeqObject.shtml

> 1) A sequence will be a base class, with subclasses for nucleotide and
> peptide sequences. The subclasses will be used.

Yep, sounds good.



> compTable = {'A':'T', 'T':'A', 'G':'C', 'C':'G'}
> class DNASeq(Seq):
> 	# Example of a nucleotide sequence subclass, with a method
> 	def complement(self, min=None, max=None):
> 		retSeq = DNASeq()
> 		for i in self(min,max): # This calls the seq attribute in the
> 										# base class
> 			retSeq.append(compTable[i])
> 		return retSeq
> 
> chargeTable = {'E':-1., 'D':-1., 'K':1., 'R':1, 'H':0.5}
> class PEPSeq(Seq):
> 	# Example of an amino-acid subclass, with a method
> 	def charge(self, min=None, max=None):
> 		c=0.
> 		for i in self(min,max): # This calls the seq attribute 
> 										# in the base class
> 			try:
> 				c = c + chargeTable[i]
> 			except KeyError:
> 				pass
> 		return c

The problem I have with this style is that you'll end up with a bunch of
small methods that do essentially the same things with different data.
For example, you'd repeat much of that code if you were to add a method
that calculates the molecular weight of a protein strand.

Perhaps a more general solution would be to write a function that iterates
over a sequence and performs a generic calculation to be
specified in the parameter list.

Jeff