[Biopython-dev] derive from Seq

Eric Talevich eric.talevich at gmail.com
Sat Feb 20 19:01:42 UTC 2010


On Tue, Feb 16, 2010 at 8:09 AM, Brad Chapman <chapmanb at 50mail.com> wrote:

>
> More generally, it is interesting that you are subclassing Seq. Can
> you describe your application for this? I was debating with Peter
> and Michiel this week and arguing that the Seq class should be
> switched to a standard string, with biological functions like
> reverse_complement and the like moving to stand alone functions and
> SeqRecord objects. I'd be interested in hearing the opposite case;
> that additional functionality is needed on a Seq object.
>
>
I've seen a technique like this used to good effect:

# File: Seq.py

# Standalone functions all take a string-like first argument
def reverse_complement(seq): ...
def translate(seq, table=1): ...

class Seq(basestring):  # or str
    def __init__(self, data, alphabet): ...
    # Then attach the above functions as methods here
    reverse_complement = reverse_complement
    translate = translate
    ...


The same functionality is then available in a functional or OO style, with
minimal code duplication. And for interactive sessions, where converting
strings to Seqs is a bit more of an inconvenience, "from Bio.Seq import *"
becomes quick and handy.

-Eric



More information about the Biopython-dev mailing list