[Biopython-dev] [Bug 2853] New: Support the "in" keyword with Seq objects / define __contains__ method

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Tue Jun 9 16:02:21 UTC 2009


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

           Summary: Support the "in" keyword with Seq objects / define
                    __contains__ method
           Product: Biopython
           Version: Not Applicable
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Main Distribution
        AssignedTo: biopython-dev at biopython.org
        ReportedBy: biopython-bugzilla at maubp.freeserve.co.uk


Currently the "in" keyword isn't properly supported in the Seq object, meaning
instead of this:

>>> if "TAG" in my_seq:
>>>    print "Found TAG"

you have to do something else like this (using the find method added on Bug
2809):

>>> if my_seq.find("TAG") >= 0 :
>>>    print "Found TAG"

In dealing with Bug 2809 we already have a policy in place for dealing with the
alphabet issues, so the code to do this is very simple. Patch to follow.

Because we don't define __contains__ yet, when someone uses "in" at the moment
Python does something indirectly via our __getitem__ method, which means "in"
returns True when used for a single letter (as a string) that is in the
sequence, and False otherwise (e.g. a multi-letter string, or a Seq object).

i.e. currently:

>>> from Bio.Seq import Seq
>>> from Bio.Alphabet import generic_dna, generic_rna, generic_protein
>>> my_dna=Seq("AAGTGCTAATAGAAAAA", generic_dna)
>>> "N" in my_dna #works
False
>>> "A" in my_dna #works
True
>>> Seq("A") in my_dna #I think this is broken, should be True
False
>>> "TAG" in my_dna #I think this is broken, should be True
False
>>> "TAG" in my_dna.tostring()
True
>>> "TAG" in str(my_dna)
True


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