[Biopython] SeqRecord subclassing or composition
Peter Cock
p.j.a.cock at googlemail.com
Wed Mar 9 15:32:50 UTC 2011
On Wed, Mar 9, 2011 at 3:28 PM, Uri Laserson <laserson at mit.edu> wrote:
>> Unless you modify the methods/atttributes too much, a
>> ImmuneChain subclass of SeqRecord should be usable
>> as is with SeqIO.write etc. You don't need to 'cast'.
>
> I'm more worried about parsing than writing. As you mentioned, I will have
> to upgrade my SeqRecord object to an ImmuneChain object.
> So maybe the best approach is a combination of the two code snippets I
> included. It would subclass SeqRecord, and then manually check whether I am
> initializing with a pre-existing SeqRecord or just data:
> class ImmuneChain(SeqRecord):
> def __init__(self, *args, **kw):
> if isinstance(args[0],SeqRecord):
> # if initializing with SeqRecord, then manually transfer the
> data
> # based on the initializer for SeqRecord (http://goo.gl/X95Zf)
> record = args[0]
> SeqRecord.__init__(self, seq, id=record.id, name=record.name,
> description=record.description, dbxrefs=record.dbxrefs,
> features=record.features,
> annotations=record.annotations,
> letter_annotations=record.letter_annotations)
> else:
> # assume I'm initializing just like a regular SeqRecord:
> SeqRecord.__init__(*args,**kw)
>
> # Finally, I perform any problem-specific additional initializations
> # here.
> pass
> Does this seem like a good solution?
I think it will work,
> Also, do you think that it would make sense to make a deep copy of the
> SeqRecord object before I use it to initialize the ImmuneChain?
Assuming you will be discarding the original SeqRecord, then I see
no reason to make a deep copy. It will just slow things down.
Peter
More information about the Biopython
mailing list