[Biopython-dev] [Bug 2351] Make Seq more like a string, even subclass string?

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Thu Nov 1 04:35:13 UTC 2007


http://bugzilla.open-bio.org/show_bug.cgi?id=2351





------- Comment #8 from mdehoon at ims.u-tokyo.ac.jp  2007-11-01 00:35 EST -------
> > 3) The sequence should be mutable, so that we won't need a separate
> > MutableSeq class. This also implies that a Seq class cannot subclass from
> > string, since strings are not mutable.
> 
> Why? Python strings are not mutable, and this isn't usually a problem.
> Personally, I have never needed a mutable sequence and have only ever
> used them in test cases.

For my research, I do need a mutable sequence.

> Having the basic Seq non-mutable means we can leverage existing
> string functionality and optimizations.

Thinking this over, I can see one more pressing reason to keep the basic Seq
immutable: If Seq is immutable, it can be used as the key in a dictionary, and
as a member of a set. With a mutable Seq, neither is possible. So I guess we
need to keep both a Seq and a MutableSeq class. We'll have to write a clearer
explanation though in the tutorial as to why two classes are needed.

> Also writing a new mutable sequence in C seems like a bit maintainance load in
> the long term (and may complicate the cross platform build process).
> Surely we can get good enough performance via the array of characters
> route currently used?

The array of characters approach allows us fast modification of sequences. On
the other hand, things like taking the complement is much slower than for
strings. I looked around a bit in the Python standard library and found that
there already is a MutableString class (located in the UserString module).
Since this class stores a immutable string internally, it is as fast as a
string. So how about letting the basic Seq class inherit from string, and the
MutableSeq class from MutableString?


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list