[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
Tue Jul 15 20:07:56 UTC 2008
http://bugzilla.open-bio.org/show_bug.cgi?id=2351
------- Comment #15 from biopython-bugzilla at maubp.freeserve.co.uk 2008-07-15 16:07 EST -------
This is a suggested implementation of the split method for our Seq object,
modelled after the python string method which it calls internall. Note that I
have made the separator non-optional on the grounds that the string method's
default of white space isn't (usually) sensible for sequences. I'm happy to
change this if people this its better to be as close as possible to the string
method.
def split(self, sep, maxsplit=None) :
"""Split method, like that of a python string.
Return a list of the 'words' in the string (as Seq objects),
using sep as the delimiter string. If maxsplit is given, at
most maxsplit splits are done.
Unlike the python string method, sep must be specified (as
there shouldn't be any whitespace strings in a sequence).
e.g. print my_seq.split("-")
"""
if maxsplit :
parts = self.data.split(sep, maxsplit)
else :
parts = self.data.split(sep)
return [Seq(chunk, self.alphabet) for chunk in parts]
--
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