[Biopython] subclassing SeqRecord

Björn Johansson bjorn_johansson at bio.uminho.pt
Tue Apr 26 15:16:22 UTC 2011


Hi, I tried to subclass the SeqRecord object to make it take a new parameter
which is a int describing the annealing position for a primer. I tried the
code below, but it does not produce the result I want and it is also ugly,
mostly where indicated. This question may be more about Python the
BioPython, but I run into the wall here.
The comments in the code point out where it goes wrong.

I have RTFM but in the Python docs, but I still did not figure this one out.
I suspect that I am complicating things.

If someone knows how to do this, I would be grateful!

cheers,
bjorn


from Bio.Alphabet.IUPAC import ambiguous_dna
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq

#Subclassing of of the SeqRecord class

class Primer(SeqRecord):
    def __init__(self, primer, annealing_position):
        assert type(primer) == SeqRecord
        primer.seq.alphabet = ambiguous_dna
        SeqRecord.__init__(self,primer,primer.id,primer.name,primer.description)

        # Is this how to do it ???
        #I want to pass the SeqRecord object given as parameter to my new
primer object
        self.annealing_position = annealing_position

a = SeqRecord(Seq("aaa"),"id","name")

print a.seq
# prints aaa

print type(a.seq)
# prints <class 'Bio.Seq.Seq'>

b= Primer(a,33)

print b.annealing_position
# prints 33

print b.seq
#prints
#ID: id
#Name: name
#Description: <unknown description>
#Number of features: 0
#Seq('aaa', IUPACAmbiguousDNA())

print type(b.seq)
#<class 'Bio.SeqRecord.SeqRecord'>
# here I was expection Bio.Seq.Seq



More information about the Biopython mailing list