[Biopython-dev] [Bug 2507] Adding __getitem__ to SeqRecord for element access and slicing

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Mon Jun 2 14:00:15 UTC 2008


------- Comment #1 from biopython-bugzilla at maubp.freeserve.co.uk  2008-06-02 10:00 EST -------
Simple implementation with ignores the features (non-trivial) to be added to
the SeqRecord class in Bio/SeqRecord.py

    def __getitem__(self, index) :
        if isinstance(index, int) :
            #TODO - Should single letters be returned as just
            #strings?  This prevents the inclusion of any annotation.
            #Revisit this once the Seq object is a subclass of string.
            return self.seq[index]
        elif isinstance(index, slice) :
            answer = self.__class__(self.seq[index],
            #COPY the annotation dict and dbxefs list:
            answer.annotations = dict(self.annotations.iteritems())
            answer.dbxrefs = self.dbxrefs[:]
            #TODO - select relevant features, and add them with
            #adjusted coordinates.  Take special care with a stride!
            return answer
        raise ValueError, "Invalid index"

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