[Biopython] SeqRecord subclassing or composition
    Uri Laserson 
    laserson at mit.edu
       
    Wed Mar  9 03:07:54 UTC 2011
    
    
  
I am trying to implement a data type for my work.  Each object will have a
sequence (derived from a single read) and lots of annotations and features.
 However, I want to implement some extra interface that is problem-specific
to make my analysis more convenient.
I am debating whether to subclass SeqRecord and simply implement the extra
interface or define a new object that wraps a SeqRecord object and pass on
the subset of native SeqRecord calls and/or simply access the underlying
SeqRecord directly.
One additional factor is that I want to be able to read/write INSDC-style
files for the data (e.g., GenBank).  Therefore, if I use the SeqIO parser,
it will return native SeqRecords.  If I go the inheritance route, how do I
cast a SeqRecord object to my new subclass?
So, I am debating between inheritance
class ImmuneChain(SeqRecord):
    def __init__(self, *args, **kw):
        SeqRecord.__init__(self,*args,**kw)
        # But how do I cast a SeqRecord to an ImmuneChain?
or composition
class ImmuneChain(object):
    def __init__(self, *args, **kw):
        if isinstance(args[0],SeqRecord):
            self._record = args[0]
        else:
            # Initialize the underlying SeqRecord manually
            self._record.seq = ...
Any thoughts?
Thanks!
Uri
...................................................................................
Uri Laserson
Graduate Student, Biomedical Engineering
Harvard-MIT Division of Health Sciences and Technology
M +1 917 742 8019
laserson at mit.edu
    
    
More information about the Biopython
mailing list