[Biopython-dev] [Bug 2596] New: Add string like strip, rstrip and lstrip methods to the Seq object

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Fri Sep 26 15:52:50 UTC 2008


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

           Summary: Add string like strip, rstrip and lstrip methods to the
                    Seq object
           Product: Biopython
           Version: Not Applicable
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Main Distribution
        AssignedTo: biopython-dev at biopython.org
        ReportedBy: biopython-bugzilla at maubp.freeserve.co.uk
OtherBugsDependingO 2351
             nThis:


As part of Bug 2351 to make the Seq object more string like, it would be nice
to add strip, rstrip and lstrip methods to the Seq object.

The returned Seq object will have the same alphabet as the parent sequence.

While for strings defaulting to removing white space (spaces, tabs, newlines)
makes sense, for sequences there shouldn't be any white space.  I think
defaulting to the gap character is more natural here.

Possible implementation:

    def strip(self, chars=None) :
        """Returns a new Seq object with leading and trailing ends stripped.

        Optional argument chars defines which characters to remove.  If
        omitted or None (default) the gap character will be used (if defined
        for the alphabet, otherwise defaulting to "-").

        In comparison, the string strip method will default to removing
        white space."""
        if chars is None :
            try :
                chars = self.alphabet.gap_char
            except AttributeError :
                chars = "-"
        return Seq(str(self).strip(chars), self.alphabet)

    def lstrip(self, chars=None) :
        """Returns a new Seq object with leading (left) end stripped.

        Optional argument chars defines which characters to remove.  If
        omitted or None (default) the gap character will be used (if defined
        for the alphabet, otherwise defaulting to "-").

        In comparison, the string lstrip method will default to removing
        white space."""
        if chars is None :
            try :
                chars = self.alphabet.gap_char
            except AttributeError :
                chars = "-"
        return Seq(str(self).lstrip(chars), self.alphabet)

    def rstrip(self, chars=None) :
        """Returns a new Seq object with trailing (right) end stripped.

        Optional argument chars defines which characters to remove.  If
        omitted or None (default) the gap character will be used (if defined
        for the alphabet, otherwise defaulting to "-").

        In comparison, the string rstrip method will default to removing
        white space."""
        if chars is None :
            try :
                chars = self.alphabet.gap_char
            except AttributeError :
                chars = "-"
        return Seq(str(self).rstrip(chars), self.alphabet)


-- 
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