1 Apr 2011 01:49
[Biopython] extending Motif class
Philip Machanick <philip.machanick <at> gmail.com>
2011-03-31 23:49:33 GMT
2011-03-31 23:49:33 GMT
I want to add a new scoring function to the Motif class and in true
object-oriented spirit would like to do it by deriving a new class rather
than hacking the existing code.
The general structure of my test program (all in 1 file) is:
from Bio.Motif import Motif
class ScannableMotif(Motif):
def pwm_score_hit(self,sequence,position):
## stuff to compute my new score
from Bio import Motif
def main ():
for motif in
ScannableMotif.parse(open("/Users/philip/tmp/meme.txt"),"MEME"):
for i in range(3):
print
motif.pwm_score_hit("CCTGGGGTCCCATTTCTCTTTTCTCTCCTGGGGTCCC",i)
The two different imports appear to be necessary. I need the first to be
able to use the base class to derive a new one, and without the second when
I use metaclass methods, I get
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
The other problem: I can't directly invoke a metaclass method on a derived
instance as above. The snippet below works as expected, but looks like a
kludge to me. Is there a better way of accessing metaclass methods from a
(Continue reading)
RSS Feed