
    &h                    "   d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ d Z eej$                        Zed   ed<    ee      Z[ eej(                        Zed   ed<    ee      Z[ G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zd Zd Z	 d(dZ 	 d)dZ!d*d Z"d*d!Z#d*d"Z$d*d#Z%e&d$k(  rdd%l'm(Z( dd&l)m*Z*  e*e('       yy)+aP  Provide objects to represent biological sequences.

See also the Seq_ wiki and the chapter in our tutorial:
 - `HTML Tutorial`_
 - `PDF Tutorial`_

.. _Seq: http://biopython.org/wiki/Seq
.. _`HTML Tutorial`: http://biopython.org/DIST/docs/tutorial/Tutorial.html
.. _`PDF Tutorial`: http://biopython.org/DIST/docs/tutorial/Tutorial.pdf

    N)ABC)abstractmethod)Optional)overload)Union)BiopythonWarning)
CodonTable)	IUPACDatac                 *   dj                  | j                               j                  d      }dj                  | j                               j                  d      }t        j                  ||j                         z   ||j                         z         S )a  Make a python string translation table (PRIVATE).

    Arguments:
     - complement_mapping - a dictionary such as ambiguous_dna_complement
       and ambiguous_rna_complement from Data.IUPACData.

    Returns a translation table (a bytes object of length 256) for use with
    the python string's translate method to use in a (reverse) complement.

    Compatible with lower case and upper case sequences.

    For internal use only.
     ASCII)joinkeysencodevaluesbytes	maketranslower)complement_mappingr   r   s      V/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/Bio/Seq.py
_maketransr   %   sq     77%**,-44W=DWW'..0188AF??4$**,.0GHH    TUc                   6   e Zd ZdZdZd Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd)dZd*dZd*dZd*dZd*dZd*dZd*dZd*dZd+dZd+dZd,dZd,dZd,dZ d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd-d&Z(e)d'        Z*e)d(        Z+y).SequenceDataAbstractBaseClassa[  Abstract base class for sequence content providers.

    Most users will not need to use this class. It is used internally as a base
    class for sequence content provider classes such as _UndefinedSequenceData
    defined in this module, and _TwoBitSequenceData in Bio.SeqIO.TwoBitIO.
    Instances of these classes can be used instead of a ``bytes`` object as the
    data argument when creating a Seq object, and provide the sequence content
    only when requested via ``__getitem__``. This allows lazy parsers to load
    and parse sequence data from a file only for the requested sequence regions,
    and _UndefinedSequenceData instances to raise an exception when undefined
    sequence data are requested.

    Future implementations of lazy parsers that similarly provide on-demand
    parsing of sequence data should use a subclass of this abstract class and
    implement the abstract methods ``__len__`` and ``__getitem__``:

    * ``__len__`` must return the sequence length;
    * ``__getitem__`` must return

      * a ``bytes`` object for the requested region; or
      * a new instance of the subclass for the requested region; or
      * raise an ``UndefinedSequenceError``.

      Calling ``__getitem__`` for a sequence region of size zero should always
      return an empty ``bytes`` object.
      Calling ``__getitem__`` for the full sequence (as in data[:]) should
      either return a ``bytes`` object with the full sequence, or raise an
      ``UndefinedSequenceError``.

    Subclasses of SequenceDataAbstractBaseClass must call ``super().__init__()``
    as part of their ``__init__`` method.
     c                     | dd dk(  sJ y)z5Check if ``__getitem__`` returns a bytes-like object.Nr   r   r   selfs    r   __init__z&SequenceDataAbstractBaseClass.__init__f   s    BQx3r   c                      y Nr   r   s    r   __len__z%SequenceDataAbstractBaseClass.__len__j       r   c                      y r#   r   )r    keys     r   __getitem__z)SequenceDataAbstractBaseClass.__getitem__n   r%   r   c                     | d d  S r#   r   r   s    r   	__bytes__z'SequenceDataAbstractBaseClass.__bytes__r   s    Awr   c                 *    t        t        |             S r#   )hashr   r   s    r   __hash__z&SequenceDataAbstractBaseClass.__hash__u   s    E$K  r   c                     t        |       |k(  S r#   r   r    others     r   __eq__z$SequenceDataAbstractBaseClass.__eq__x       T{e##r   c                     t        |       |k  S r#   r/   r0   s     r   __lt__z$SequenceDataAbstractBaseClass.__lt__{       T{U""r   c                     t        |       |k  S r#   r/   r0   s     r   __le__z$SequenceDataAbstractBaseClass.__le__~   r3   r   c                     t        |       |kD  S r#   r/   r0   s     r   __gt__z$SequenceDataAbstractBaseClass.__gt__   r6   r   c                     t        |       |k\  S r#   r/   r0   s     r   __ge__z$SequenceDataAbstractBaseClass.__ge__   r3   r   c                 \    	 t        |       t        |      z   S # t        $ r	 t        cY S w xY wr#   )r   UndefinedSequenceErrorNotImplementedr0   s     r   __add__z%SequenceDataAbstractBaseClass.__add__   s/    	";u--% 	"!!	"s    ++c                     |t        |       z   S r#   r/   r0   s     r   __radd__z&SequenceDataAbstractBaseClass.__radd__       uT{""r   c                     |t        |       z  S r#   r/   r0   s     r   __mul__z%SequenceDataAbstractBaseClass.__mul__   rC   r   c                 6    t        |       j                  |      S r#   )r   __contains__r    items     r   rG   z*SequenceDataAbstractBaseClass.__contains__   s    T{''--r   c                 6    t        |       j                  |      S )zDecode the data as bytes using the codec registered for encoding.

        encoding
          The encoding with which to decode the bytes.
        )r   decode)r    encodings     r   rK   z$SequenceDataAbstractBaseClass.decode   s     T{!!(++r   Nc                 :    t        |       j                  |||      S )zReturn the number of non-overlapping occurrences of sub in data[start:end].

        Optional arguments start and end are interpreted as in slice notation.
        This method behaves as the count method of Python strings.
        )r   countr    substartends       r   rN   z#SequenceDataAbstractBaseClass.count   s     T{  eS11r   c                 :    t        |       j                  |||      S )a9  Return the lowest index in data where subsection sub is found.

        Return the lowest index in data where subsection sub is found,
        such that sub is contained within data[start,end].  Optional
        arguments start and end are interpreted as in slice notation.

        Return -1 on failure.
        )r   findrO   s       r   rT   z"SequenceDataAbstractBaseClass.find   s     T{UC00r   c                 :    t        |       j                  |||      S )a;  Return the highest index in data where subsection sub is found.

        Return the highest index in data where subsection sub is found,
        such that sub is contained within data[start,end].  Optional
        arguments start and end are interpreted as in slice notation.

        Return -1 on failure.
        )r   rfindrO   s       r   rV   z#SequenceDataAbstractBaseClass.rfind        T{  eS11r   c                 :    t        |       j                  |||      S )aW  Return the lowest index in data where subsection sub is found.

        Return the lowest index in data where subsection sub is found,
        such that sub is contained within data[start,end].  Optional
        arguments start and end are interpreted as in slice notation.

        Raises ValueError when the subsection is not found.
        )r   indexrO   s       r   rY   z#SequenceDataAbstractBaseClass.index   rW   r   c                 :    t        |       j                  |||      S )aX  Return the highest index in data where subsection sub is found.

        Return the highest index in data where subsection sub is found,
        such that sub is contained within data[start,end].  Optional
        arguments start and end are interpreted as in slice notation.

        Raise ValueError when the subsection is not found.
        )r   rindexrO   s       r   r[   z$SequenceDataAbstractBaseClass.rindex   s     T{!!#uc22r   c                 :    t        |       j                  |||      S )a  Return True if data starts with the specified prefix, False otherwise.

        With optional start, test data beginning at that position.
        With optional end, stop comparing data at that position.
        prefix can also be a tuple of bytes to try.
        )r   
startswithr    prefixrQ   rR   s       r   r]   z(SequenceDataAbstractBaseClass.startswith   s     T{%%feS99r   c                 :    t        |       j                  |||      S )a  Return True if data ends with the specified suffix, False otherwise.

        With optional start, test data beginning at that position.
        With optional end, stop comparing data at that position.
        suffix can also be a tuple of bytes to try.
        )r   endswithr    suffixrQ   rR   s       r   ra   z&SequenceDataAbstractBaseClass.endswith   s     T{##FE377r   c                 8    t        |       j                  ||      S )a  Return a list of the sections in the data, using sep as the delimiter.

        sep
          The delimiter according which to split the data.
          None (the default value) means split on ASCII whitespace characters
          (space, tab, return, newline, formfeed, vertical tab).
        maxsplit
          Maximum number of splits to do.
          -1 (the default value) means no limit.
        )r   splitr    sepmaxsplits      r   re   z#SequenceDataAbstractBaseClass.split   s     T{  h//r   c                 8    t        |       j                  ||      S )a  Return a list of the sections in the data, using sep as the delimiter.

        sep
          The delimiter according which to split the data.
          None (the default value) means split on ASCII whitespace characters
          (space, tab, return, newline, formfeed, vertical tab).
        maxsplit
          Maximum number of splits to do.
          -1 (the default value) means no limit.

        Splitting is done starting at the end of the data and working to the front.
        )r   rsplitrf   s      r   rj   z$SequenceDataAbstractBaseClass.rsplit   s     T{!!#x00r   c                 6    t        |       j                  |      S )zStrip leading and trailing characters contained in the argument.

        If the argument is omitted or None, strip leading and trailing ASCII whitespace.
        )r   stripr    charss     r   rl   z#SequenceDataAbstractBaseClass.strip  s    
 T{  ''r   c                 6    t        |       j                  |      S )zStrip leading characters contained in the argument.

        If the argument is omitted or None, strip leading ASCII whitespace.
        )r   lstriprm   s     r   rp   z$SequenceDataAbstractBaseClass.lstrip	      
 T{!!%((r   c                 6    t        |       j                  |      S )zStrip trailing characters contained in the argument.

        If the argument is omitted or None, strip trailing ASCII whitespace.
        )r   rstriprm   s     r   rs   z$SequenceDataAbstractBaseClass.rstrip  rq   r   c                     t        |       }	 |j                  |      S # t        $ r& |j                  |      r|t	        |      d cY S |cY S w xY w)zRemove the prefix if present.N)r   removeprefixAttributeErrorr]   len)r    r_   datas      r   ru   z*SequenceDataAbstractBaseClass.removeprefix  sT     T{	$$V,, 	v&CKM**		s    (AAAc                     t        |       }	 |j                  |      S # t        $ r' |j                  |      r|dt	        |        cY S |cY S w xY w)zRemove the suffix if present.N)r   removesuffixrv   r]   rw   )r    rc   rx   s      r   rz   z*SequenceDataAbstractBaseClass.removesuffix$  sV     T{	$$V,, 	v&Ns6{l++		s    )A	AAc                 4    t        |       j                         S )zGReturn a copy of data with all ASCII characters converted to uppercase.)r   upperr   s    r   r|   z#SequenceDataAbstractBaseClass.upper1      T{  ""r   c                 4    t        |       j                         S )zGReturn a copy of data with all ASCII characters converted to lowercase.)r   r   r   s    r   r   z#SequenceDataAbstractBaseClass.lower5  r}   r   c                 4    t        |       j                         S Return True if all ASCII characters in data are uppercase.

        If there are no cased characters, the method returns False.
        )r   isupperr   s    r   r   z%SequenceDataAbstractBaseClass.isupper9      
 T{""$$r   c                 4    t        |       j                         S Return True if all ASCII characters in data are lowercase.

        If there are no cased characters, the method returns False.
        )r   islowerr   s    r   r   z%SequenceDataAbstractBaseClass.islower@  r   r   c                 8    t        |       j                  ||      S )DReturn a copy with all occurrences of substring old replaced by new.)r   replacer    oldnews      r   r   z%SequenceDataAbstractBaseClass.replaceG  s    T{""3,,r   c                 8    t        |       j                  ||      S aM  Return a copy with each character mapped by the given translation table.

          table
            Translation table, which must be a bytes object of length 256.

        All characters occurring in the optional argument delete are removed.
        The remaining characters are mapped through the given translation table.
        )r   	translate)r    tabledeletes      r   r   z'SequenceDataAbstractBaseClass.translateK  s     T{$$UF33r   c                      yzReturn True if the sequence is defined, False if undefined or partially defined.

        Zero-length sequences are always considered to be defined.
        Tr   r   s    r   definedz%SequenceDataAbstractBaseClass.definedV  s     r   c                 .    t        |       }|dkD  rd|ffS yReturn a tuple of the ranges where the sequence contents is defined.

        The return value has the format ((start1, end1), (start2, end2), ...).
        r   r   rw   r    lengths     r   defined_rangesz,SequenceDataAbstractBaseClass.defined_ranges^  s#     TA:K>!r   )zutf-8NNNr#   r   ),__name__
__module____qualname____doc__	__slots__r!   r   r$   r(   r*   r-   r2   r5   r8   r:   r<   r@   rB   rE   rG   rK   rN   rT   rV   rY   r[   r]   ra   re   rj   rl   rp   rs   ru   rz   r|   r   r   r   r   r   propertyr   r   r   r   r   r   r   B   s   B I    !$#$#$"##.,2	1	2	2	3:801())##%%-	4   	 	r   r   c                      e Zd ZdZdZdZed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zededefd       Zededdfd       Zd Zd Zd Zd Zd Zd Zd:dZd:dZd Zd:dZd:dZ d:dZ!d:d Z"d! Z#d:d"Z$d:d#Z%d;d$Z&d;d%Z'd<d&Z(d<d'Z)d<d(Z*d=d)Z+d=d*Z,d=d+Z-d=d,Z.d- Z/d. Z0	 d>d/Z1d=d0Z2d=d1Z3d=d2Z4d=d3Z5d=d4Z6d=d5Z7d6 Z8d=d7Z9e:d8        Z;e:d9        Z<y)?_SeqAbstractBaseClasszAbstract base class for the Seq and MutableSeq classes (PRIVATE).

    Most users will not need to use this class. It is used internally as an
    abstract base class for Seq and MutableSeq, as most of their methods are
    identical.
    _dataNc                      y r#   r   r   s    r   r!   z_SeqAbstractBaseClass.__init__v  r%   r   c                 ,    t        | j                        S r#   )r   r   r   s    r   r*   z_SeqAbstractBaseClass.__bytes__z  s    TZZ  r   c                    | j                   }t        |t              rdt        |        dS t        |t              ri }|j                   j                         D ]Y  \  }}t        |      dkD  r0|dd j                  d      }|dd j                  d      }| d| }n|j                  d      }|||<   [ d	|t        |       fz  S t        |      dkD  rG|dd j                  d      }|dd j                  d      }| j                  j                   d
| d| dS |j                  d      }| j                  j                   d
| dS )z2Return (truncated) representation of the sequence.zSeq(None, length=)<   N6   r   z...zSeq(%r, length=%d)z('z'))	r   
isinstance_UndefinedSequenceDatarw   _PartiallyDefinedSequenceDataitemsrK   	__class__r   )r    rx   dpositionseqrQ   rR   s          r   __repr__z_SeqAbstractBaseClass.__repr__}  sQ   zzd23&s4yk33d9:A!%!1!1!3 "#s8b=HOOG4Ebc(//'2C"G3se,C**W-C!(" (1c$i.88t9r> "I$$W-Ers)""7+Cnn--.bs3%rBB;;w'Dnn--.bb99r   c                 8    | j                   j                  d      S )z,Return the full sequence as a python string.r   )r   rK   r   s    r   __str__z_SeqAbstractBaseClass.__str__  s    zz  ))r   c                     t        |t              r| j                  |j                  k(  S t        |t              r| j                  |j	                  d      k(  S | j                  |k(  S )aL  Compare the sequence to another sequence or a string.

        Sequences are equal to each other if their sequence contents is
        identical:

        >>> from Bio.Seq import Seq, MutableSeq
        >>> seq1 = Seq("ACGT")
        >>> seq2 = Seq("ACGT")
        >>> mutable_seq = MutableSeq("ACGT")
        >>> seq1 == seq2
        True
        >>> seq1 == mutable_seq
        True
        >>> seq1 == "ACGT"
        True

        Note that the sequence objects themselves are not identical to each
        other:

        >>> id(seq1) == id(seq2)
        False
        >>> seq1 is seq2
        False

        Sequences can also be compared to strings, ``bytes``, and ``bytearray``
        objects:

        >>> seq1 == "ACGT"
        True
        >>> seq1 == b"ACGT"
        True
        >>> seq1 == bytearray(b"ACGT")
        True
        r   r   r   r   strr   r0   s     r   r2   z_SeqAbstractBaseClass.__eq__  sT    F e23::,,s#::g!666::&&r   c                     t        |t              r| j                  |j                  k  S t        |t              r| j                  |j	                  d      k  S | j                  |k  S )z Implement the less-than operand.r   r   r0   s     r   r5   z_SeqAbstractBaseClass.__lt__  Q    e23::++s#::W 555::%%r   c                     t        |t              r| j                  |j                  k  S t        |t              r| j                  |j	                  d      k  S | j                  |k  S )z)Implement the less-than or equal operand.r   r   r0   s     r   r8   z_SeqAbstractBaseClass.__le__  Q    e23::,,s#::g!666::&&r   c                     t        |t              r| j                  |j                  kD  S t        |t              r| j                  |j	                  d      kD  S | j                  |kD  S )z#Implement the greater-than operand.r   r   r0   s     r   r:   z_SeqAbstractBaseClass.__gt__  r   r   c                     t        |t              r| j                  |j                  k\  S t        |t              r| j                  |j	                  d      k\  S | j                  |k\  S )z,Implement the greater-than or equal operand.r   r   r0   s     r   r<   z_SeqAbstractBaseClass.__ge__  r   r   c                 ,    t        | j                        S )z"Return the length of the sequence.)rw   r   r   s    r   r$   z_SeqAbstractBaseClass.__len__  s    4::r   c                 T    | j                   j                  d      j                         S )z#Return an iterable of the sequence.r   )r   rK   __iter__r   s    r   r   z_SeqAbstractBaseClass.__iter__  s     zz  )2244r   rY   returnc                      y r#   r   r    rY   s     r   r(   z!_SeqAbstractBaseClass.__getitem__  s    .1r   Seqc                      y r#   r   r   s     r   r(   z!_SeqAbstractBaseClass.__getitem__  s    25r   c                     t        |t        j                        rt        | j                  |         S | j                  | j                  |         S )a  Return a subsequence as a single letter or as a sequence object.

        If the index is an integer, a single letter is returned as a Python
        string:

        >>> seq = Seq('ACTCGACGTCG')
        >>> seq[5]
        'A'

        Otherwise, a new sequence object of the same class is returned:

        >>> seq[5:8]
        Seq('ACG')
        >>> mutable_seq = MutableSeq('ACTCGACGTCG')
        >>> mutable_seq[5:8]
        MutableSeq('ACG')
        )r   numbersIntegralchrr   r   r   s     r   r(   z!_SeqAbstractBaseClass.__getitem__  sB    $ eW--.tzz%()) >>$**U"344r   c                     t        |t              r(| j                  | j                  |j                  z         S t        |t              r-| j                  | j                  |j                  d      z         S t        S )zAdd a sequence or string to this sequence.

        >>> from Bio.Seq import Seq, MutableSeq
        >>> Seq("MELKI") + "LV"
        Seq('MELKILV')
        >>> MutableSeq("MELKI") + "LV"
        MutableSeq('MELKILV')
        r   )r   r   r   r   r   r   r?   r0   s     r   r@   z_SeqAbstractBaseClass.__add__  s^     e23>>$**u{{":;;s#>>$**u||G/D"DEE "!r   c                     t        |t              r-| j                  |j                  d      | j                  z         S t
        S )a   Add a sequence string on the left.

        >>> from Bio.Seq import Seq, MutableSeq
        >>> "LV" + Seq("MELKI")
        Seq('LVMELKI')
        >>> "LV" + MutableSeq("MELKI")
        MutableSeq('LVMELKI')

        Adding two sequence objects is handled via the __add__ method.
        r   )r   r   r   r   r   r?   r0   s     r   rB   z_SeqAbstractBaseClass.__radd__#  s5     eS!>>%,,w"7$**"DEE!!r   c                     t        |t        j                        s#t        d| j                  j
                   d      | j                  j                  |      }| j	                  |      S )zMultiply sequence by integer.

        >>> from Bio.Seq import Seq, MutableSeq
        >>> Seq('ATG') * 2
        Seq('ATGATG')
        >>> MutableSeq('ATG') * 2
        MutableSeq('ATGATG')
        can't multiply  by non-int typer   r   r   	TypeErrorr   r   r   rE   r    r1   rx   s      r   rE   z_SeqAbstractBaseClass.__mul__3  sY     %!1!12odnn.E.E-FFVWXX
 zz!!%(~~d##r   c                     t        |t        j                        s#t        d| j                  j
                   d      | j                  j                  |      }| j	                  |      S )z|Multiply integer by sequence.

        >>> from Bio.Seq import Seq
        >>> 2 * Seq('ATG')
        Seq('ATGATG')
        r   r   r   r   s      r   __rmul__z_SeqAbstractBaseClass.__rmul__E  sY     %!1!12odnn.E.E-FFVWXX
 zz!!%(~~d##r   c                     t        |t        j                        s#t        d| j                  j
                   d      | j                  j                  |      }| j	                  |      S )av  Multiply the sequence object by other and assign.

        >>> from Bio.Seq import Seq
        >>> seq = Seq('ATG')
        >>> seq *= 2
        >>> seq
        Seq('ATGATG')

        Note that this is different from in-place multiplication. The ``seq``
        variable is reassigned to the multiplication result, but any variable
        pointing to ``seq`` will remain unchanged:

        >>> seq = Seq('ATG')
        >>> seq2 = seq
        >>> id(seq) == id(seq2)
        True
        >>> seq *= 2
        >>> seq
        Seq('ATGATG')
        >>> seq2
        Seq('ATG')
        >>> id(seq) == id(seq2)
        False
        r   r   r   r   s      r   __imul__z_SeqAbstractBaseClass.__imul__U  sY    2 %!1!12odnn.E.E-FFVWXX
 zz!!%(~~d##r   c                 L   t        |t              r|j                  }nkt        |t              rt	        |      }nOt        |t
              r|j                  d      }n-t        |t        t        f      st        dt        |      z        | j                  j                  |||      S )a  Return a non-overlapping count, like that of a python string.

        The number of occurrences of substring argument sub in the
        (sub)sequence given by [start:end] is returned as an integer.
        Optional arguments start and end are interpreted as in slice
        notation.

        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        e.g.

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("AAAATGA")
        >>> print(my_seq.count("A"))
        5
        >>> print(my_seq.count("ATG"))
        1
        >>> print(my_seq.count(Seq("AT")))
        1
        >>> print(my_seq.count("AT", 2, -1))
        1

        HOWEVER, please note because the ``count`` method of Seq and MutableSeq
        objects, like that of Python strings, do a non-overlapping search, this
        may not give the answer you expect:

        >>> "AAAA".count("AA")
        2
        >>> print(Seq("AAAA").count("AA"))
        2

        For an overlapping search, use the ``count_overlap`` method:

        >>> print(Seq("AAAA").count_overlap("AA"))
        3
        r   Ha Seq, MutableSeq, str, bytes, or bytearray object is required, not '%s')r   
MutableSeqr   r   r   r   r   	bytearrayr   typerN   rO   s       r   rN   z_SeqAbstractBaseClass.countw  s    P c:&))CS!*CS!**W%CC%!34Zs)  zzUC00r   c                 x   t        |t              r|j                  }nkt        |t              rt	        |      }nOt        |t
              r|j                  d      }n-t        |t        t        f      st        dt        |      z        | j                  }d}	 |j                  |||      dz   }|dk7  r|dz  }n|S $)aw  Return an overlapping count.

        Returns an integer, the number of occurrences of substring
        argument sub in the (sub)sequence given by [start:end].
        Optional arguments start and end are interpreted as in slice
        notation.

        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        e.g.

        >>> from Bio.Seq import Seq
        >>> print(Seq("AAAA").count_overlap("AA"))
        3
        >>> print(Seq("ATATATATA").count_overlap("ATA"))
        4
        >>> print(Seq("ATATATATA").count_overlap("ATA", 3, -1))
        1

        For a non-overlapping search, use the ``count`` method:

        >>> print(Seq("AAAA").count("AA"))
        2

        Where substrings do not overlap, ``count_overlap`` behaves the same as
        the ``count`` method:

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("AAAATGA")
        >>> print(my_seq.count_overlap("A"))
        5
        >>> my_seq.count_overlap("A") == my_seq.count("A")
        True
        >>> print(my_seq.count_overlap("ATG"))
        1
        >>> my_seq.count_overlap("ATG") == my_seq.count("ATG")
        True
        >>> print(my_seq.count_overlap(Seq("AT")))
        1
        >>> my_seq.count_overlap(Seq("AT")) == my_seq.count(Seq("AT"))
        True
        >>> print(my_seq.count_overlap("AT", 2, -1))
        1
        >>> my_seq.count_overlap("AT", 2, -1) == my_seq.count("AT", 2, -1)
        True

        HOWEVER, do not use this method for such cases because the
        count() method is much for efficient.
        r   r   r      )r   r   r   r   r   r   r   r   r   r   rT   )r    rP   rQ   rR   rx   overlap_counts         r   count_overlapz#_SeqAbstractBaseClass.count_overlap  s    j c:&))CS!*CS!**W%CC%!34Zs)  zzIIc5#.2Ez"$$ r   c                     t        |t              rt        |      }n!t        |t              r|j	                  d      }|| j
                  v S )aK  Return True if item is a subsequence of the sequence, and False otherwise.

        e.g.

        >>> from Bio.Seq import Seq, MutableSeq
        >>> my_dna = Seq("ATATGAAATTTGAAAA")
        >>> "AAA" in my_dna
        True
        >>> Seq("AAA") in my_dna
        True
        >>> MutableSeq("AAA") in my_dna
        True
        r   )r   r   r   r   r   r   rH   s     r   rG   z"_SeqAbstractBaseClass.__contains__  s?     d12;Dc";;w'Dtzz!!r   c                    t        |t              rt        |      }nOt        |t              r|j	                  d      }n-t        |t        t
        f      st        dt        |      z        | j                  j                  |||      S )a  Return the lowest index in the sequence where subsequence sub is found.

        With optional arguments start and end, return the lowest index in the
        sequence such that the subsequence sub is contained within the sequence
        region [start:end].

        Arguments:
         - sub - a string or another Seq or MutableSeq object to search for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Returns -1 if the subsequence is NOT found.

        e.g. Locating the first typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.find("AUG")
        3

        The next typical start codon can then be found by starting the search
        at position 4:

        >>> my_rna.find("AUG", 4)
        15

        See the ``search`` method to find the locations of multiple subsequences
        at the same time.
        r   r   )
r   r   r   r   r   r   r   r   r   rT   rO   s       r   rT   z_SeqAbstractBaseClass.find	  st    < c01*CS!**W%CC%!34Zs)  zzsE3//r   c                    t        |t              rt        |      }nOt        |t              r|j	                  d      }n-t        |t        t
        f      st        dt        |      z        | j                  j                  |||      S )a  Return the highest index in the sequence where subsequence sub is found.

        With optional arguments start and end, return the highest index in the
        sequence such that the subsequence sub is contained within the sequence
        region [start:end].

        Arguments:
         - sub - a string or another Seq or MutableSeq object to search for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Returns -1 if the subsequence is NOT found.

        e.g. Locating the last typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.rfind("AUG")
        15

        The location of the typical start codon before that can be found by
        ending the search at position 15:

        >>> my_rna.rfind("AUG", end=15)
        3

        See the ``search`` method to find the locations of multiple subsequences
        at the same time.
        r   r   )
r   r   r   r   r   r   r   r   r   rV   rO   s       r   rV   z_SeqAbstractBaseClass.rfind2  sv    < c01*CS!**W%CC%!34Zs)  zzUC00r   c                 L   t        |t              r|j                  }nkt        |t              rt	        |      }nOt        |t
              r|j                  d      }n-t        |t        t        f      st        dt        |      z        | j                  j                  |||      S )aK  Return the lowest index in the sequence where subsequence sub is found.

        With optional arguments start and end, return the lowest index in the
        sequence such that the subsequence sub is contained within the sequence
        region [start:end].

        Arguments:
         - sub - a string or another Seq or MutableSeq object to search for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Raises a ValueError if the subsequence is NOT found.

        e.g. Locating the first typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.index("AUG")
        3

        The next typical start codon can then be found by starting the search
        at position 4:

        >>> my_rna.index("AUG", 4)
        15

        This method performs the same search as the ``find`` method.  However,
        if the subsequence is not found, ``find`` returns -1 while ``index``
        raises a ValueError:

        >>> my_rna.index("T")
        Traceback (most recent call last):
                   ...
        ValueError: ...
        >>> my_rna.find("T")
        -1

        See the ``search`` method to find the locations of multiple subsequences
        at the same time.
        r   r   )r   r   r   r   r   r   r   r   r   r   rY   rO   s       r   rY   z_SeqAbstractBaseClass.index[  s    R c:&))CS!*CS!**W%CC%!34Zs)  zzUC00r   c                 L   t        |t              r|j                  }nkt        |t              rt	        |      }nOt        |t
              r|j                  d      }n-t        |t        t        f      st        dt        |      z        | j                  j                  |||      S )a`  Return the highest index in the sequence where subsequence sub is found.

        With optional arguments start and end, return the highest index in the
        sequence such that the subsequence sub is contained within the sequence
        region [start:end].

        Arguments:
         - sub - a string or another Seq or MutableSeq object to search for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Returns -1 if the subsequence is NOT found.

        e.g. Locating the last typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.rindex("AUG")
        15

        The location of the typical start codon before that can be found by
        ending the search at position 15:

        >>> my_rna.rindex("AUG", end=15)
        3

        This method performs the same search as the ``rfind`` method.  However,
        if the subsequence is not found, ``rfind`` returns -1 which ``rindex``
        raises a ValueError:

        >>> my_rna.rindex("T")
        Traceback (most recent call last):
                   ...
        ValueError: ...
        >>> my_rna.rfind("T")
        -1

        See the ``search`` method to find the locations of multiple subsequences
        at the same time.
        r   r   )r   r   r   r   r   r   r   r   r   r   r[   rO   s       r   r[   z_SeqAbstractBaseClass.rindex  s    R c:&))CS!*CS!**W%CC%!34Zs)  zz  eS11r   c              #   L  K   t        j                  t              }t        |      D ]  \  }}t	        |t
        t        f      rt        |      }nKt	        |t              r|j                  d      }n)t	        |t              st        d|t        |      fz        t        |      }||   j                  |        t        t        |       dz
        D ]N  }|j                         D ]9  \  }}||z   }|D ]*  }| j                   || |k(  s||j#                         f  9 ; P yw)aZ  Search the substrings subs in self and yield the index and substring found.

        Arguments:
         - subs - a list of strings, Seq, MutableSeq, bytes, or bytearray
           objects containing the substrings to search for.

        >>> from Bio.Seq import Seq
        >>> dna = Seq("GTCATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAGTTG")
        >>> matches = dna.search(["CC", Seq("ATTG"), "ATTG", Seq("CCC")])
        >>> for index, substring in matches:
        ...     print(index, substring)
        ...
        7 CC
        9 ATTG
        20 CC
        34 CC
        34 CCC
        35 CC
        r   zRsubs[%d]: a Seq, MutableSeq, str, bytes, or bytearray object is required, not '%s'r   N)collectionsdefaultdictset	enumerater   r   r   r   r   r   r   r   rw   addranger   r   rK   )r    subssubdictrY   rP   r   rQ   stops           r   searchz_SeqAbstractBaseClass.search  s    ( ))#.#D/ 	%JE3# 5yABCjC%jj)U+hd3i()  XFFO$	% 3t9q=) 	E ' v~ Czz%-4$cjjl33	s   DD$D$c                     t        |t              rt        d |D              }n=t        |t              rt        |      }n!t        |t              r|j                  d      }| j                  j                  |||      S )a  Return True if the sequence starts with the given prefix, False otherwise.

        Return True if the sequence starts with the specified prefix
        (a string or another Seq object), False otherwise.
        With optional start, test sequence beginning at that position.
        With optional end, stop comparing sequence at that position.
        prefix can also be a tuple of strings to try.  e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.startswith("GUC")
        True
        >>> my_rna.startswith("AUG")
        False
        >>> my_rna.startswith("AUG", 3)
        True
        >>> my_rna.startswith(("UCC", "UCA", "UCG"), 1)
        True
        c              3   t   K   | ]0  }t        |t              rt        |      n|j                  d        2 ywr   Nr   r   r   r   .0ps     r   	<genexpr>z3_SeqAbstractBaseClass.startswith.<locals>.<genexpr>  4       'q*?@aahhwFWW   68r   )r   tupler   r   r   r   r   r]   r^   s       r   r]   z _SeqAbstractBaseClass.startswith  sl    ( fe$  F  566]F$]]7+Fzz$$VUC88r   c                     t        |t              rt        d |D              }n=t        |t              rt        |      }n!t        |t              r|j                  d      }| j                  j                  |||      S )a  Return True if the sequence ends with the given suffix, False otherwise.

        Return True if the sequence ends with the specified suffix
        (a string or another Seq object), False otherwise.
        With optional start, test sequence beginning at that position.
        With optional end, stop comparing sequence at that position.
        suffix can also be a tuple of strings to try.  e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.endswith("UUG")
        True
        >>> my_rna.endswith("AUG")
        False
        >>> my_rna.endswith("AUG", 0, 18)
        True
        >>> my_rna.endswith(("UCC", "UCA", "UUG"))
        True
        c              3   t   K   | ]0  }t        |t              rt        |      n|j                  d        2 ywr   r   r   s     r   r   z1_SeqAbstractBaseClass.endswith.<locals>.<genexpr>$  r   r   r   )r   r  r   r   r   r   r   ra   rb   s       r   ra   z_SeqAbstractBaseClass.endswith  sl    ( fe$  F  566]F$]]7+Fzz""65#66r   c                     t        |t              rt        |      }n!t        |t              r|j	                  d      }| j
                  j                  ||      D cg c]  }t        |       c}S c c}w )a}  Return a list of subsequences when splitting the sequence by separator sep.

        Return a list of the subsequences in the sequence (as Seq objects),
        using sep as the delimiter string.  If maxsplit is given, at
        most maxsplit splits are done.  If maxsplit is omitted, all
        splits are made.

        For consistency with the ``split`` method of Python strings, any
        whitespace (tabs, spaces, newlines) is a separator if sep is None, the
        default value

        e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_aa = my_rna.translate()
        >>> my_aa
        Seq('VMAIVMGR*KGAR*L')
        >>> for pep in my_aa.split("*"):
        ...     pep
        Seq('VMAIVMGR')
        Seq('KGAR')
        Seq('L')
        >>> for pep in my_aa.split("*", 1):
        ...     pep
        Seq('VMAIVMGR')
        Seq('KGAR*L')

        See also the rsplit method, which splits the sequence starting from the
        end:

        >>> for pep in my_aa.rsplit("*", 1):
        ...     pep
        Seq('VMAIVMGR*KGAR')
        Seq('L')
        r   )r   r   r   r   r   r   re   r   r    rg   rh   parts       r   re   z_SeqAbstractBaseClass.split.  sZ    J c01*CS!**W%C&*jj&6&6sH&EFdD	FFF   A1c                     t        |t              rt        |      }n!t        |t              r|j	                  d      }| j
                  j                  ||      D cg c]  }t        |       c}S c c}w )a  Return a list of subsequences by splitting the sequence from the right.

        Return a list of the subsequences in the sequence (as Seq objects),
        using sep as the delimiter string.  If maxsplit is given, at
        most maxsplit splits are done.  If maxsplit is omitted, all
        splits are made.

        For consistency with the ``rsplit`` method of Python strings, any
        whitespace (tabs, spaces, newlines) is a separator if sep is None, the
        default value

        e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_aa = my_rna.translate()
        >>> my_aa
        Seq('VMAIVMGR*KGAR*L')
        >>> for pep in my_aa.rsplit("*"):
        ...     pep
        Seq('VMAIVMGR')
        Seq('KGAR')
        Seq('L')
        >>> for pep in my_aa.rsplit("*", 1):
        ...     pep
        Seq('VMAIVMGR*KGAR')
        Seq('L')

        See also the split method, which splits the sequence starting from the
        beginning:

        >>> for pep in my_aa.split("*", 1):
        ...     pep
        Seq('VMAIVMGR')
        Seq('KGAR*L')
        r   )r   r   r   r   r   r   rj   r   r  s       r   rj   z_SeqAbstractBaseClass.rsplitY  sZ    J c01*CS!**W%C&*jj&7&7X&FGdD	GGGr  c                 x   t        |t              rt        |      }n!t        |t              r|j	                  d      }	 | j
                  j                  |      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S # t        $ r t        d      dw xY w)aO  Return a sequence object with leading and trailing ends stripped.

        With default arguments, leading and trailing whitespace is removed:

        >>> seq = Seq(" ACGT ")
        >>> seq.strip()
        Seq('ACGT')
        >>> seq
        Seq(' ACGT ')

        If ``chars`` is given and not ``None``, remove characters in ``chars``
        instead.  The order of the characters to be removed is not important:

        >>> Seq("ACGTACGT").strip("TGCA")
        Seq('')

        A copy of the sequence is returned if ``inplace`` is ``False`` (the
        default value).  If ``inplace`` is ``True``, the sequence is stripped
        in-place and returned.

        >>> seq = MutableSeq(" ACGT ")
        >>> seq.strip()
        MutableSeq('ACGT')
        >>> seq
        MutableSeq(' ACGT ')
        >>> seq.strip(inplace=True)
        MutableSeq('ACGT')
        >>> seq
        MutableSeq('ACGT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if ``strip``
        is called on a ``Seq`` object with ``inplace=True``.

        See also the lstrip and rstrip methods.
        r   Hargument must be None or a string, Seq, MutableSeq, or bytes-like objectNSequence is immutable)
r   r   r   r   r   r   rl   r   r   r   r    rn   inplacerx   s       r   rl   z_SeqAbstractBaseClass.strip  s    H e23%LEs#LL)E	::##E*D
 djj)4 788 DJJqMK>>$''  	Z	   B# #B9c                 x   t        |t              rt        |      }n!t        |t              r|j	                  d      }	 | j
                  j                  |      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S # t        $ r t        d      dw xY w)an  Return a sequence object with leading and trailing ends stripped.

        With default arguments, leading whitespace is removed:

        >>> seq = Seq(" ACGT ")
        >>> seq.lstrip()
        Seq('ACGT ')
        >>> seq
        Seq(' ACGT ')

        If ``chars`` is given and not ``None``, remove characters in ``chars``
        from the leading end instead.  The order of the characters to be removed
        is not important:

        >>> Seq("ACGACGTTACG").lstrip("GCA")
        Seq('TTACG')

        A copy of the sequence is returned if ``inplace`` is ``False`` (the
        default value).  If ``inplace`` is ``True``, the sequence is stripped
        in-place and returned.

        >>> seq = MutableSeq(" ACGT ")
        >>> seq.lstrip()
        MutableSeq('ACGT ')
        >>> seq
        MutableSeq(' ACGT ')
        >>> seq.lstrip(inplace=True)
        MutableSeq('ACGT ')
        >>> seq
        MutableSeq('ACGT ')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``lstrip`` is called on a ``Seq`` object with ``inplace=True``.

        See also the strip and rstrip methods.
        r   r
  Nr  )
r   r   r   r   r   r   rp   r   r   r   r  s       r   rp   z_SeqAbstractBaseClass.lstrip      J e23%LEs#LL)E	::$$U+D
 djj)4 788 DJJqMK>>$''  	Z	r  c                 x   t        |t              rt        |      }n!t        |t              r|j	                  d      }	 | j
                  j                  |      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S # t        $ r t        d      dw xY w)ag  Return a sequence object with trailing ends stripped.

        With default arguments, trailing whitespace is removed:

        >>> seq = Seq(" ACGT ")
        >>> seq.rstrip()
        Seq(' ACGT')
        >>> seq
        Seq(' ACGT ')

        If ``chars`` is given and not ``None``, remove characters in ``chars``
        from the trailing end instead.  The order of the characters to be
        removed is not important:

        >>> Seq("ACGACGTTACG").rstrip("GCA")
        Seq('ACGACGTT')

        A copy of the sequence is returned if ``inplace`` is ``False`` (the
        default value).  If ``inplace`` is ``True``, the sequence is stripped
        in-place and returned.

        >>> seq = MutableSeq(" ACGT ")
        >>> seq.rstrip()
        MutableSeq(' ACGT')
        >>> seq
        MutableSeq(' ACGT ')
        >>> seq.rstrip(inplace=True)
        MutableSeq(' ACGT')
        >>> seq
        MutableSeq(' ACGT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``rstrip`` is called on a ``Seq`` object with ``inplace=True``.

        See also the strip and lstrip methods.
        r   r
  Nr  )
r   r   r   r   r   r   rs   r   r   r   r  s       r   rs   z_SeqAbstractBaseClass.rstrip  r  r  c                    t        |t              rt        |      }n!t        |t              r|j	                  d      }	 | j
                  j                  |      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S # t        $ r t        d      dt        $ r. | j
                  }|j                  |      r|t        |      d }Y w xY w)a#  Return a new Seq object with prefix (left) removed.

        This behaves like the python string method of the same name.

        e.g. Removing a start Codon:

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("ATGGTGTGTGT")
        >>> my_seq
        Seq('ATGGTGTGTGT')
        >>> my_seq.removeprefix('ATG')
        Seq('GTGTGTGT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``removeprefix`` is called on a ``Seq`` object with ``inplace=True``.

        See also the removesuffix method.
        r   @argument must be a string, Seq, MutableSeq, or bytes-like objectNr  )r   r   r   r   r   r   ru   r   rv   r]   rw   r   r   )r    r_   r  rx   s       r   ru   z"_SeqAbstractBaseClass.removeprefix(  s    & f346]F$]]7+F
	+::**62D djj)4 788 DJJqMK>>$''  	R  	+::Dv&CKM*		+s   B# #AC.-C.c                    t        |t              rt        |      }n!t        |t              r|j	                  d      }	 | j
                  j                  |      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S # t        $ r t        d      dt        $ r/ | j
                  }|j                  |      r|dt        |        }Y w xY w)aL  Return a new Seq object with suffix (right) removed.

        This behaves like the python string method of the same name.

        e.g. Removing a stop codon:

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("GTGTGTGTTAG")
        >>> my_seq
        Seq('GTGTGTGTTAG')
        >>> stop_codon = Seq("TAG")
        >>> my_seq.removesuffix(stop_codon)
        Seq('GTGTGTGT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``removesuffix`` is called on a ``Seq`` object with ``inplace=True``.

        See also the removeprefix method.
        r   r  Nr  )r   r   r   r   r   r   rz   r   rv   ra   rw   r   r   )r    rc   r  rx   s       r   rz   z"_SeqAbstractBaseClass.removesuffixR  s    ( f346]F$]]7+F
	,::**62D djj)4 788 DJJqMK>>$''  	R  	,::D}}V$Ns6{l+		,s   B# #A	C/.C/c                     | j                   j                         }|r6t        | j                   t              st	        d      || j                   dd | S | j                  |      S )a  Return the sequence in upper case.

        An upper-case copy of the sequence is returned if inplace is False,
        the default value:

        >>> from Bio.Seq import Seq, MutableSeq
        >>> my_seq = Seq("VHLTPeeK*")
        >>> my_seq
        Seq('VHLTPeeK*')
        >>> my_seq.lower()
        Seq('vhltpeek*')
        >>> my_seq.upper()
        Seq('VHLTPEEK*')
        >>> my_seq
        Seq('VHLTPeeK*')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("VHLTPeeK*")
        >>> my_seq
        MutableSeq('VHLTPeeK*')
        >>> my_seq.lower()
        MutableSeq('vhltpeek*')
        >>> my_seq.upper()
        MutableSeq('VHLTPEEK*')
        >>> my_seq
        MutableSeq('VHLTPeeK*')

        >>> my_seq.lower(inplace=True)
        MutableSeq('vhltpeek*')
        >>> my_seq
        MutableSeq('vhltpeek*')
        >>> my_seq.upper(inplace=True)
        MutableSeq('VHLTPEEK*')
        >>> my_seq
        MutableSeq('VHLTPEEK*')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``upper`` is called on a ``Seq`` object with ``inplace=True``.

        See also the ``lower`` method.
        r  N)r   r|   r   r   r   r   r    r  rx   s      r   r|   z_SeqAbstractBaseClass.upper}  U    V zz!djj)4 788 DJJqMK>>$''r   c                     | j                   j                         }|r6t        | j                   t              st	        d      || j                   dd | S | j                  |      S )a  Return the sequence in lower case.

        An lower-case copy of the sequence is returned if inplace is False,
        the default value:

        >>> from Bio.Seq import Seq, MutableSeq
        >>> my_seq = Seq("VHLTPeeK*")
        >>> my_seq
        Seq('VHLTPeeK*')
        >>> my_seq.lower()
        Seq('vhltpeek*')
        >>> my_seq.upper()
        Seq('VHLTPEEK*')
        >>> my_seq
        Seq('VHLTPeeK*')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("VHLTPeeK*")
        >>> my_seq
        MutableSeq('VHLTPeeK*')
        >>> my_seq.lower()
        MutableSeq('vhltpeek*')
        >>> my_seq.upper()
        MutableSeq('VHLTPEEK*')
        >>> my_seq
        MutableSeq('VHLTPeeK*')

        >>> my_seq.lower(inplace=True)
        MutableSeq('vhltpeek*')
        >>> my_seq
        MutableSeq('vhltpeek*')
        >>> my_seq.upper(inplace=True)
        MutableSeq('VHLTPEEK*')
        >>> my_seq
        MutableSeq('VHLTPEEK*')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``lower`` is called on a ``Seq`` object with ``inplace=True``.

        See also the ``upper`` method.
        r  N)r   r   r   r   r   r   r  s      r   r   z_SeqAbstractBaseClass.lower  r  r   c                 6    | j                   j                         S r   )r   r   r   s    r   r   z_SeqAbstractBaseClass.isupper      
 zz!!##r   c                 6    | j                   j                         S r   )r   r   r   s    r   r   z_SeqAbstractBaseClass.islower  r  r   c           
         	 t        |       }| j                  t        t        |       |||||            S # t        $ r? t        |       }|dz  dk7  rt        j                  dt
               t        d|dz        cY S w xY w)a  Turn a nucleotide sequence into a protein sequence by creating a new sequence object.

        This method will translate DNA or RNA sequences. It should not
        be used on protein sequences as any result will be biologically
        meaningless.

        Arguments:
         - table - Which codon table to use?  This can be either a name
           (string), an NCBI identifier (integer), or a CodonTable
           object (useful for non-standard genetic codes).  This
           defaults to the "Standard" table.
         - stop_symbol - Single character string, what to use for
           terminators.  This defaults to the asterisk, "*".
         - to_stop - Boolean, defaults to False meaning do a full
           translation continuing on past any stop codons (translated as the
           specified stop_symbol).  If True, translation is terminated at
           the first in frame stop codon (and the stop_symbol is not
           appended to the returned protein sequence).
         - cds - Boolean, indicates this is a complete CDS.  If True,
           this checks the sequence starts with a valid alternative start
           codon (which will be translated as methionine, M), that the
           sequence length is a multiple of three, and that there is a
           single in frame stop codon at the end (this will be excluded
           from the protein sequence, regardless of the to_stop option).
           If these tests fail, an exception is raised.
         - gap - Single character string to denote symbol used for gaps.
           Defaults to the minus sign.

        A ``Seq`` object is returned if ``translate`` is called on a ``Seq``
        object; a ``MutableSeq`` object is returned if ``translate`` is called
        pn a ``MutableSeq`` object.

        e.g. Using the standard table:

        >>> coding_dna = Seq("GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
        >>> coding_dna.translate()
        Seq('VAIVMGR*KGAR*')
        >>> coding_dna.translate(stop_symbol="@")
        Seq('VAIVMGR@KGAR@')
        >>> coding_dna.translate(to_stop=True)
        Seq('VAIVMGR')

        Now using NCBI table 2, where TGA is not a stop codon:

        >>> coding_dna.translate(table=2)
        Seq('VAIVMGRWKGAR*')
        >>> coding_dna.translate(table=2, to_stop=True)
        Seq('VAIVMGRWKGAR')

        In fact, GTG is an alternative start codon under NCBI table 2, meaning
        this sequence could be a complete CDS:

        >>> coding_dna.translate(table=2, cds=True)
        Seq('MAIVMGRWKGAR')

        It isn't a valid CDS under NCBI table 1, due to both the start codon
        and also the in frame stop codons:

        >>> coding_dna.translate(table=1, cds=True)
        Traceback (most recent call last):
            ...
        Bio.Data.CodonTable.TranslationError: First codon 'GTG' is not a start codon

        If the sequence has no in-frame stop codon, then the to_stop argument
        has no effect:

        >>> coding_dna2 = Seq("TTGGCCATTGTAATGGGCCGC")
        >>> coding_dna2.translate()
        Seq('LAIVMGR')
        >>> coding_dna2.translate(to_stop=True)
        Seq('LAIVMGR')

        NOTE - Ambiguous codons like "TAN" or "NNN" could be an amino acid
        or a stop codon.  These are translated as "X".  Any invalid codon
        (e.g. "TA?" or "T-A") will throw a TranslationError.

        NOTE - This does NOT behave like the python string's translate
        method.  For that use str(my_seq).translate(...) instead
           r   zYPartial codon, len(sequence) not a multiple of three. This may become an error in future.Ngap)	r   r>   rw   warningswarnr   r   r   _translate_str)r    r   stop_symbolto_stopcdsr  rx   ns           r   r   z_SeqAbstractBaseClass.translate  s    d	%t9D ~~3t9e['3CP
 	
 & 
	% D	A1uz:$
 tQ!V$$
	%s   6 AA>=A>c                     t         }	 | j                  j                  |      }|r6t	        | j                  t
              st        d      || j                  dd | S | j                  |      S # t        $ r | cY S w xY w)am  Return the complement as a DNA sequence.

        >>> Seq("CGA").complement()
        Seq('GCT')

        Any U in the sequence is treated as a T:

        >>> Seq("CGAUT").complement()
        Seq('GCTAA')

        In contrast, ``complement_rna`` returns an RNA sequence:

        >>> Seq("CGAUT").complement_rna()
        Seq('GCUAA')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("CGA")
        >>> my_seq
        MutableSeq('CGA')
        >>> my_seq.complement()
        MutableSeq('GCT')
        >>> my_seq
        MutableSeq('CGA')

        >>> my_seq.complement(inplace=True)
        MutableSeq('GCT')
        >>> my_seq
        MutableSeq('GCT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``complement_rna`` is called on a ``Seq`` object with ``inplace=True``.
        r  N)_dna_complement_tabler   r   r>   r   r   r   r   )r    r  ttablerx   s       r   
complementz _SeqAbstractBaseClass.complementW  s{    D '	::''/D
 djj)4 788 DJJqMK~~d## & 	 K	s   A, ,A:9A:c                     	 | j                   j                  t              }|r6t	        | j                   t
              st        d      || j                   dd | S | j                  |      S # t        $ r | cY S w xY w)a|  Return the complement as an RNA sequence.

        >>> Seq("CGA").complement_rna()
        Seq('GCU')

        Any T in the sequence is treated as a U:

        >>> Seq("CGAUT").complement_rna()
        Seq('GCUAA')

        In contrast, ``complement`` returns a DNA sequence by default:

        >>> Seq("CGA").complement()
        Seq('GCT')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("CGA")
        >>> my_seq
        MutableSeq('CGA')
        >>> my_seq.complement_rna()
        MutableSeq('GCU')
        >>> my_seq
        MutableSeq('CGA')

        >>> my_seq.complement_rna(inplace=True)
        MutableSeq('GCU')
        >>> my_seq
        MutableSeq('GCU')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``complement_rna`` is called on a ``Seq`` object with ``inplace=True``.
        r  Nr   r   _rna_complement_tabler>   r   r   r   r   r  s      r   complement_rnaz$_SeqAbstractBaseClass.complement_rna  su    D	::''(=>D
 djj)4 788 DJJqMK~~d## & 	 K	s   A* *A87A8c                    	 | j                   j                  t              }|r9t	        | j                   t
              st        d      || j                   ddd<   | S | j                  |ddd         S # t        $ r | cY S w xY w)a  Return the reverse complement as a DNA sequence.

        >>> Seq("CGA").reverse_complement()
        Seq('TCG')

        Any U in the sequence is treated as a T:

        >>> Seq("CGAUT").reverse_complement()
        Seq('AATCG')

        In contrast, ``reverse_complement_rna`` returns an RNA sequence:

        >>> Seq("CGA").reverse_complement_rna()
        Seq('UCG')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("CGA")
        >>> my_seq
        MutableSeq('CGA')
        >>> my_seq.reverse_complement()
        MutableSeq('TCG')
        >>> my_seq
        MutableSeq('CGA')

        >>> my_seq.reverse_complement(inplace=True)
        MutableSeq('TCG')
        >>> my_seq
        MutableSeq('TCG')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``reverse_complement`` is called on a ``Seq`` object with
        ``inplace=True``.
        r  Nr   )r   r   r(  r>   r   r   r   r   r  s      r   reverse_complementz(_SeqAbstractBaseClass.reverse_complement      F	::''(=>D
 djj)4 788#DJJttK~~d4R4j)) & 	 K	   A3 3B Bc                    	 | j                   j                  t              }|r9t	        | j                   t
              st        d      || j                   ddd<   | S | j                  |ddd         S # t        $ r | cY S w xY w)a  Return the reverse complement as an RNA sequence.

        >>> Seq("CGA").reverse_complement_rna()
        Seq('UCG')

        Any T in the sequence is treated as a U:

        >>> Seq("CGAUT").reverse_complement_rna()
        Seq('AAUCG')

        In contrast, ``reverse_complement`` returns a DNA sequence:

        >>> Seq("CGA").reverse_complement()
        Seq('TCG')

        The sequence is modified in-place and returned if inplace is True:

        >>> my_seq = MutableSeq("CGA")
        >>> my_seq
        MutableSeq('CGA')
        >>> my_seq.reverse_complement_rna()
        MutableSeq('UCG')
        >>> my_seq
        MutableSeq('CGA')

        >>> my_seq.reverse_complement_rna(inplace=True)
        MutableSeq('UCG')
        >>> my_seq
        MutableSeq('UCG')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``reverse_complement_rna`` is called on a ``Seq`` object with
        ``inplace=True``.
        r  Nr   r,  r  s      r   reverse_complement_rnaz,_SeqAbstractBaseClass.reverse_complement_rna  r1  r2  c                     | j                   j                  dd      j                  dd      }|r6t        | j                   t              st	        d      || j                   dd | S | j                  |      S )aY  Transcribe a DNA sequence into RNA and return the RNA sequence as a new Seq object.

        Following the usual convention, the sequence is interpreted as the
        coding strand of the DNA double helix, not the template strand. This
        means we can get the RNA sequence just by switching T to U.

        >>> from Bio.Seq import Seq
        >>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
        >>> coding_dna
        Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
        >>> coding_dna.transcribe()
        Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

        The sequence is modified in-place and returned if inplace is True:

        >>> sequence = MutableSeq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
        >>> sequence
        MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
        >>> sequence.transcribe()
        MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
        >>> sequence
        MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')

        >>> sequence.transcribe(inplace=True)
        MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
        >>> sequence
        MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``transcribe`` is called on a ``Seq`` object with ``inplace=True``.

        Trying to transcribe an RNA sequence has no effect.
        If you have a nucleotide sequence which might be DNA or RNA
        (or even a mixture), calling the transcribe method will ensure
        any T becomes U.

        Trying to transcribe a protein sequence will replace any
        T for Threonine with U for Selenocysteine, which has no
        biologically plausible rational.

        >>> from Bio.Seq import Seq
        >>> my_protein = Seq("MAIVMGRT")
        >>> my_protein.transcribe()
        Seq('MAIVMGRU')
           T   U   t   ur  Nr   r   r   r   r   r   r  s      r   
transcribez _SeqAbstractBaseClass.transcribe  sf    \ zz!!$-55dDAdjj)4 788 DJJqMK~~d##r   c                     | j                   j                  dd      j                  dd      }|r6t        | j                   t              st	        d      || j                   dd | S | j                  |      S )ax  Return the DNA sequence from an RNA sequence by creating a new Seq object.

        >>> from Bio.Seq import Seq
        >>> messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG")
        >>> messenger_rna
        Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
        >>> messenger_rna.back_transcribe()
        Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')

        The sequence is modified in-place and returned if inplace is True:

        >>> sequence = MutableSeq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG")
        >>> sequence
        MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
        >>> sequence.back_transcribe()
        MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
        >>> sequence
        MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

        >>> sequence.back_transcribe(inplace=True)
        MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
        >>> sequence
        MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``transcribe`` is called on a ``Seq`` object with ``inplace=True``.

        Trying to back-transcribe DNA has no effect, If you have a nucleotide
        sequence which might be DNA or RNA (or even a mixture), calling the
        back-transcribe method will ensure any U becomes T.

        Trying to back-transcribe a protein sequence will replace any U for
        Selenocysteine with T for Threonine, which is biologically meaningless.

        >>> from Bio.Seq import Seq
        >>> my_protein = Seq("MAIVMGRU")
        >>> my_protein.back_transcribe()
        Seq('MAIVMGRT')
        r7  r6  r9  r8  r  Nr:  r  s      r   back_transcribez%_SeqAbstractBaseClass.back_transcribeL  sf    P zz!!$-55dDAdjj)4 788 DJJqMK~~d##r   c           
      :   t        |t              r2| j                  t        |       j	                  t        |                  S t        |t              r)| j                  t        |       j	                  |            S ddlm} t        ||      rt        d      |D ]:  }t        ||      rt        d      t        |t        t        f      r1t        d       | j                  t        |       j	                  |D cg c]  }t        |       c}            S c c}w )a  Return a merge of the sequences in other, spaced by the sequence from self.

        Accepts a Seq object, MutableSeq object, or string (and iterates over
        the letters), or an iterable containing Seq, MutableSeq, or string
        objects. These arguments will be concatenated with the calling sequence
        as the spacer:

        >>> concatenated = Seq('NNNNN').join([Seq("AAA"), Seq("TTT"), Seq("PPP")])
        >>> concatenated
        Seq('AAANNNNNTTTNNNNNPPP')

        Joining the letters of a single sequence:

        >>> Seq('NNNNN').join(Seq("ACGT"))
        Seq('ANNNNNCNNNNNGNNNNNT')
        >>> Seq('NNNNN').join("ACGT")
        Seq('ANNNNNCNNNNNGNNNNNT')
        r   	SeqRecordzIterable cannot be a SeqRecordz"Iterable cannot contain SeqRecordszHInput must be an iterable of Seq objects, MutableSeq objects, or strings)r   r   r   r   r   Bio.SeqRecordr@  r   )r    r1   r@  c_s        r   r   z_SeqAbstractBaseClass.join|  s    & e23>>#d)..U"<==s#>>#d).."788+eY'<== 	A!Y' DEEC)>#?@^ 		 ~~c$inne-Dc!f-DEFF-Ds   ;Dc                    t        |t              rt        |      }n!t        |t              r|j	                  d      }t        |t              rt        |      }n!t        |t              r|j	                  d      }| j
                  j                  ||      }|r6t        | j
                  t              st        d      || j
                  dd | S | j                  |      S )aX  Return a copy with all occurrences of subsequence old replaced by new.

        >>> s = Seq("ACGTAACCGGTT")
        >>> t = s.replace("AC", "XYZ")
        >>> s
        Seq('ACGTAACCGGTT')
        >>> t
        Seq('XYZGTAXYZCGGTT')

        For mutable sequences, passing inplace=True will modify the sequence in place:

        >>> m = MutableSeq("ACGTAACCGGTT")
        >>> t = m.replace("AC", "XYZ")
        >>> m
        MutableSeq('ACGTAACCGGTT')
        >>> t
        MutableSeq('XYZGTAXYZCGGTT')

        >>> m = MutableSeq("ACGTAACCGGTT")
        >>> t = m.replace("AC", "XYZ", inplace=True)
        >>> m
        MutableSeq('XYZGTAXYZCGGTT')
        >>> t
        MutableSeq('XYZGTAXYZCGGTT')

        As ``Seq`` objects are immutable, a ``TypeError`` is raised if
        ``replace`` is called on a ``Seq`` object with ``inplace=True``.
        r   r  N)
r   r   r   r   r   r   r   r   r   r   )r    r   r   r  rx   s        r   r   z_SeqAbstractBaseClass.replace  s    : c01*CS!**W%Cc01*CS!**W%Czz!!#s+djj)4 788 DJJqMK~~d##r   c                 p    t        | j                  t        t        f      ry| j                  j                  S r   )r   r   r   r   r   r   s    r   r   z_SeqAbstractBaseClass.defined  s*     djj5)"45::%%%r   c                     t        | j                  t        t        f      rt	        |       }|dkD  rd|ffS y| j                  j
                  S r   )r   r   r   r   rw   r   r   s     r   r   z$_SeqAbstractBaseClass.defined_ranges  sF     djj5)"45YFzF~%::,,,r   r   r   )NFF)Standard*FF-)=r   r   r   r   r   __array_ufunc__r   r!   r*   r   r   r2   r5   r8   r:   r<   r$   r   r   intr   r(   slicer@   rB   rE   r   r   rN   r   rG   rT   rV   rY   r[   r   r]   ra   re   rj   rl   rp   rs   ru   rz   r|   r   r   r   r   r*  r.  r0  r4  r;  r=  r   r   r   r   r   r   r   r   r   r   k  s    IO !:6*('T&'&'5 111 15555 552"$" $$$  $D31jG%R"('0R'1R41l42l'R9>7>)GV)HV4(l5(n5(n((T)(V2(h2(h$$ PSb
H.$`-$^.*`.*`4$l.$`$GL+$Z & & - -r   r   c            
       Z    e Zd ZU dZeeef   ed<   	 ddeeee	e
eedf   dee   fdZd Zy)	r   aB  Read-only sequence object (essentially a string with biological methods).

    Like normal python strings, our basic sequence object is immutable.
    This prevents you from doing my_seq[5] = "A" for example, but does allow
    Seq objects to be used as dictionary keys.

    The Seq object provides a number of string like methods (such as count,
    find, split and strip).

    The Seq object also provides some biological methods, such as complement,
    reverse_complement, transcribe, back_transcribe and translate (which are
    not applicable to protein sequences).
    r   Nrx   r   c                    |;|t        d      |dk(  rd| _        y|dk  rt        d      t        |      | _        yt        |t        t
        f      r|| _        yt        |t        t        f      rt	        |      | _        yt        |t              rt	        |d      | _        yt        |t              r|t        d      |dk(  rd| _        y|dk  rt        d      d}d	}t        |j                               }i }|D ]i  }||   }t        |t              rt	        |d      }n	 t	        |      }||k  rt        d      ||k(  r||xx   |z  cc<   n|||<   |}|t        |      z   }k ||kD  rt        d      ||k(  r|dk(  r||   | _        yt        ||      | _        yt        d      # t        $ r t        d
      w xY w)a  Create a Seq object.

        Arguments:
         - data - Sequence, required (string)
         - length - Sequence length, used only if data is None or a dictionary (integer)

        You will typically use Bio.SeqIO to read in sequences from files as
        SeqRecord objects, whose sequence will be exposed as a Seq object via
        the seq property.

        However, you can also create a Seq object directly:

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF")
        >>> my_seq
        Seq('MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF')
        >>> print(my_seq)
        MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF

        To create a Seq object with for a sequence of known length but
        unknown sequence contents, use None for the data argument and pass
        the sequence length for the length argument. Trying to access the
        sequence contents of a Seq object created in this way will raise
        an UndefinedSequenceError:

        >>> my_undefined_sequence = Seq(None, 20)
        >>> my_undefined_sequence
        Seq(None, length=20)
        >>> len(my_undefined_sequence)
        20
        >>> print(my_undefined_sequence)
        Traceback (most recent call last):
        ...
        Bio.Seq.UndefinedSequenceError: Sequence content is undefined

        If the sequence contents is known for parts of the sequence only, use
        a dictionary for the data argument to pass the known sequence segments:

        >>> my_partially_defined_sequence = Seq({3: "ACGT"}, 10)
        >>> my_partially_defined_sequence
        Seq({3: 'ACGT'}, length=10)
        >>> len(my_partially_defined_sequence)
        10
        >>> print(my_partially_defined_sequence)
        Traceback (most recent call last):
        ...
        Bio.Seq.UndefinedSequenceError: Sequence content is only partially defined
        >>> my_partially_defined_sequence[3:7]
        Seq('ACGT')
        >>> print(my_partially_defined_sequence[3:7])
        ACGT
        Nz'length must not be None if data is Noner   r   zlength must not be negative.r   )rL   z/length must not be None if data is a dictionaryr   z&Expected bytes-like objects or stringszSequence data are overlapping.z5Provided sequence data extend beyond sequence length.zDdata should be a string, bytes, bytearray, Seq, or MutableSeq object)
ValueErrorr   r   r   r   r   r   r   r   dictsortedr   	Exceptionrw   r   r   )	r    rx   r   currentrR   startsr   rQ   r   s	            r   r!   zSeq.__init__  s   B <~ !JKK1 
! !?@@3F;
u&CDEDJy*?@AtDJc"tg6DJd#~ !RSS1 
! !?@@		,*,# +Eu+C!#s+#C':W"'*C s{()IJJ#g#-'*e"'#c(*C!+" <$O  F]w!|!&wDJ!>vu!MDJV )  ) W",-U"VVWs   (F//Gc                 ,    t        | j                        S )zHash of the sequence as a string for comparison.

        See Seq object comparison documentation (method ``__eq__`` in
        particular) as this has changed in Biopython 1.65. Older versions
        would hash on object identity.
        )r,   r   r   s    r   r-   zSeq.__hash__v  s     DJJr   r#   )r   r   r   r   r   r   r   __annotations__r   r   r   rQ  r   rL  r!   r-   r   r   r   r   r     sb     5566 !%y!)
y yv r   r   c                   H    e Zd ZdZd Zd Zd Zd Zd ZddZ	d Z
d	 Zd
 Zy)r   a  An editable sequence object.

    Unlike normal python strings and our basic sequence object (the Seq class)
    which are immutable, the MutableSeq lets you edit the sequence in place.
    However, this means you cannot use a MutableSeq object as a dictionary key.

    >>> from Bio.Seq import MutableSeq
    >>> my_seq = MutableSeq("ACTCGTCGTCG")
    >>> my_seq
    MutableSeq('ACTCGTCGTCG')
    >>> my_seq[5]
    'T'
    >>> my_seq[5] = "A"
    >>> my_seq
    MutableSeq('ACTCGACGTCG')
    >>> my_seq[5]
    'A'
    >>> my_seq[5:8] = "NNN"
    >>> my_seq
    MutableSeq('ACTCGNNNTCG')
    >>> len(my_seq)
    11

    Note that the MutableSeq object does not support as many string-like
    or biological methods as the Seq object.
    c                 l   t        |t              r|| _        yt        |t              rt        |      | _        yt        |t              rt        |d      | _        yt        |t
              r|j                  dd | _        yt        |t              rt        t        |            | _        yt        d      )zCreate a MutableSeq object.r   NzMdata should be a string, bytearray object, Seq object, or a MutableSeq object)r   r   r   r   r   r   r   r   )r    rx   s     r   r!   zMutableSeq.__init__  s    dI&DJe$"4DJc""41DJj)ADJc""5;/DJ$ r   c                    t        |t        j                        rt        |      | j                  |<   yt        |t
              r|j                  | j                  |<   yt        |t              rt        |      | j                  |<   yt        |t              r|j                  d      | j                  |<   yt        dt        |      j                   d      )zSet a subsequence of single letter via value parameter.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq[0] = 'T'
        >>> my_seq
        MutableSeq('TCTCGACGTCG')
        r   zreceived unexpected type ''N)r   r   r   ordr   r   r   r   r   r   r   r   r   )r    rY   values      r   __setitem__zMutableSeq.__setitem__  s     eW--. #E
DJJu %,$)KK

5!E3'$)%L

5!E3'$)LL$9

5!"<T%[=Q=Q<RRS TUUr   c                     | j                   |= y)zDelete a subsequence of single letter.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> del my_seq[0]
        >>> my_seq
        MutableSeq('CTCGACGTCG')
        Nr   r   s     r   __delitem__zMutableSeq.__delitem__  s     JJur   c                 j    | j                   j                  t        |j                  d                   y)zAdd a subsequence to the mutable sequence object.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq.append('A')
        >>> my_seq
        MutableSeq('ACTCGACGTCGA')

        No return value.
        r   N)r   appendr\  r   )r    rB  s     r   rb  zMutableSeq.append  s$     	

#ahhw/01r   c                 l    | j                   j                  |t        |j                  d                   y)aD  Add a subsequence to the mutable sequence object at a given index.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq.insert(0,'A')
        >>> my_seq
        MutableSeq('AACTCGACGTCG')
        >>> my_seq.insert(8,'G')
        >>> my_seq
        MutableSeq('AACTCGACGGTCG')

        No return value.
        r   N)r   insertr\  r   r    irB  s      r   rd  zMutableSeq.insert  s&     	

!S'!234r   c                 P    | j                   |   }| j                   |= t        |      S )aV  Remove a subsequence of a single letter at given index.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq.pop()
        'G'
        >>> my_seq
        MutableSeq('ACTCGACGTC')
        >>> my_seq.pop()
        'C'
        >>> my_seq
        MutableSeq('ACTCGACGT')

        Returns the last character of the sequence.
        )r   r   re  s      r   popzMutableSeq.pop  s%     JJqMJJqM1vr   c                     t        |      }	 | j                  j                  |       y# t        $ r t        d      dw xY w)a6  Remove a subsequence of a single letter from mutable sequence.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq.remove('C')
        >>> my_seq
        MutableSeq('ATCGACGTCG')
        >>> my_seq.remove('A')
        >>> my_seq
        MutableSeq('TCGACGTCG')

        No return value.
        zvalue not found in MutableSeqN)r\  r   removerP  )r    rI   	codepoints      r   rj  zMutableSeq.remove  sD     I		HJJi( 	H<=4G	Hs   ) ?c                 8    | j                   j                          y)zQModify the mutable sequence to reverse itself.

        No return value.
        N)r   reverser   s    r   rm  zMutableSeq.reverse	  s    
 	

r   c                 d   t        |t              r&| j                  j                  |j                         yt        |t              r%| j                  j                  t        |             yt        |t              r+| j                  j                  |j                  d             yt        d      )a9  Add a sequence to the original mutable sequence object.

        >>> my_seq = MutableSeq('ACTCGACGTCG')
        >>> my_seq.extend('A')
        >>> my_seq
        MutableSeq('ACTCGACGTCGA')
        >>> my_seq.extend('TTT')
        >>> my_seq
        MutableSeq('ACTCGACGTCGATTT')

        No return value.
        r   z$expected a string, Seq or MutableSeqN)	r   r   r   extendr   r   r   r   r   r0   s     r   ro  zMutableSeq.extend	  su     eZ(JJekk*s#JJeEl+s#JJell734BCCr   N)r   )r   r   r   r   r!   r^  r`  rb  rd  rh  rj  rm  ro  r   r   r   r   r     s7    6&V,	
25&H&Dr   r   c                       e Zd ZdZy)r>   zSequence contents is undefined.N)r   r   r   r   r   r   r   r>   r>   /	  s    )r   r>   c                        e Zd ZdZdZ fdZdedeed f   fdZ	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zed        Zed        Z xZS )r   a  Stores the length of a sequence with an undefined sequence contents (PRIVATE).

    Objects of this class can be used to create a Seq object to represent
    sequences with a known length, but an unknown sequence contents.
    Calling __len__ returns the sequence length, calling __getitem__ raises an
    UndefinedSequenceError except for requests of zero size, for which it
    returns an empty bytes object.
    _lengthc                 0    || _         t        | 	          y)zInitialize the object with the sequence length.

        The calling function is responsible for ensuring that the length is
        greater than zero.
        N)rs  superr!   )r    r   r   s     r   r!   z_UndefinedSequenceData.__init__?	  s     r   r'   r   c                     t        |t              rF|j                  | j                        \  }}}t	        t        |||            }|dk(  ryt        |      S t        d      )Nr   r   Sequence content is undefined)r   rM  indicesrs  rw   r   r   r>   )r    r'   rQ   rR   stepsizes         r   r(   z"_UndefinedSequenceData.__getitem__H	  sY    c5!"{{4<<8E3uUC./Dqy)$//()HIIr   c                     | j                   S r#   rr  r   s    r   r$   z_UndefinedSequenceData.__len__R	      ||r   c                     t        d      )Nrw  r>   r   s    r   r*   z _UndefinedSequenceData.__bytes__U	  s    $%DEEr   c                     t        |       t        |      z   }	 t        |      }t        |       |i}t        ||      S # t        $ r& t	        |t
              rt        |      cY S t        cY S w xY wr#   )rw   r   r   r>   r   r   r?   )r    r1   r   rx   s       r   r@   z_UndefinedSequenceData.__add__X	  sl    TSZ'
	?%LE Iu%D0>> & 	&%!78-f55%%		&s   = $A,#A,+A,c                 b    dt        |      i}t        |      t        |       z   }t        ||      S Nr   )r   rw   r   )r    r1   rx   r   s       r   rB   z_UndefinedSequenceData.__radd__f	  s/    5< Uc$i',VT::r   c                 ,    t        | j                        S z*Return an upper case copy of the sequence.r   rs  r   s    r   r|   z_UndefinedSequenceData.upperk	       &dll33r   c                 ,    t        | j                        S z)Return a lower case copy of the sequence.r  r   s    r   r   z_UndefinedSequenceData.lowerq	  r  r   c                     t        d      )r   rw  r~  r   s    r   r   z_UndefinedSequenceData.isupperw	       %%DEEr   c                     t        d      )r   rw  r~  r   s    r   r   z_UndefinedSequenceData.islower	  r  r   c                 p    t        |      t        |      k7  rt        d      t        | j                        S )r   rw  )rw   r>   r   rs  r   s      r   r   z_UndefinedSequenceData.replace	  s/    
 s8s3x()HII%dll33r   c                      y)zGReturn False, as the sequence is not defined and has a non-zero length.Fr   r   s    r   r   z_UndefinedSequenceData.defined	       r   c                      y)zReturn a tuple of the ranges where the sequence contents is defined.

        As the sequence contents of an _UndefinedSequenceData object is fully
        undefined, the return value is always an empty tuple.
        r   r   r   s    r   r   z%_UndefinedSequenceData.defined_ranges	  s     r   )r   r   r   r   r   r!   rM  r   r   r(   r$   r*   r@   rB   r|   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r   3	  s     IJu Ju6N/N)O JF?;
44FF4    r   r   c                        e Zd ZdZdZ fdZdeeef   dee	e
f   fdZd Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZddZd Zed        Zed        Z xZS )r   a  Stores the length of a sequence with an undefined sequence contents (PRIVATE).

    Objects of this class can be used to create a Seq object to represent
    sequences with a known length, but with a sequence contents that is only
    partially known.
    Calling __len__ returns the sequence length, calling __getitem__ returns
    the sequence contents if known, otherwise an UndefinedSequenceError is
    raised.
    )rs  r   c                 >    || _         || _        t        |           y)zInitialize with the sequence length and defined sequence segments.

        The calling function is responsible for ensuring that the length is
        greater than zero.
        N)rs  r   ru  r!   )r    r   rx   r   s      r   r!   z&_PartiallyDefinedSequenceData.__init__	  s     
r   r'   r   c                    t        |t              r|j                  | j                        \  }}}t	        t        |||            }|dk(  ryi }| j                  j                         D ]  \  }}t        | | | j                  z         |   }	|	j                  }
|
J |dkD  r2|
dk  r?|	j                  dk  r|	j                  |z  }nY|	j                  }nL|
dk  rd }
t	        |      dz
  }|	j                  |kD  r||	j                  |z
  |z  z   }n|	j                  }|dk  r||	j                  z
  |z  }|||
|   }|s|||<    t	        |      dk(  rt        |      S d}d}|j                         }i }|D ]-  \  }}||k(  r||xx   |z  cc<   n|||<   |}|t	        |      z   }/ t	        |      dk(  r#|j                  d      }|t	        |      |k(  r|S |dk  r3t        t        |j                                     D ci c]  }|||   
 }}t        ||      S | j                  |k  rt!        d      | j                  j                         D ]&  \  }}||k  s||t	        |      z   k  s|||z
     c S  t#        d|z        c c}w )Nr   r   r   r   zsequence index out of rangez$Sequence at position %d is undefined)r   rM  rx  rs  rw   r   r   r   r   rQ   r   getreversedlistr   r   
IndexErrorr>   )r    r'   rQ   rR   ry  rz  rx   sr   rx  epreviousr   r   s                 r   r(   z)_PartiallyDefinedSequenceData.__getitem__	  s    c5!"{{4<<8E3uUC./DqyD

((* $1QB$56s;#*<<}$!8Av }}q(#MMD0#MM1u a&1*C}}s*7==3#6$">>#MM1u W]]*t3a$hK"#DK1$2 4yA~-d33CHJJLED# '
s%<Nc)N"%DK$Hc#h&' 4yA~hhqk?s3x4'7Jax 9AdiikAR8STutE{*TT0t<<\\S :;;"jj..0 ,
sC<C%#c(*:$:sU{++, ))ORU)UVV Us   ?Jc                     | j                   S r#   rr  r   s    r   r$   z%_PartiallyDefinedSequenceData.__len__	  r|  r   c                     t        d      )N*Sequence content is only partially definedr~  r   s    r   r*   z'_PartiallyDefinedSequenceData.__bytes__	  s    $%QRRr   c                    t        |       t        |      z   }t        | j                        }t        | j                  j	                               }|d   \  }}|t        |      z   }	 t        |      }|t        |       k(  r||xx   |z  cc<   n||t        |       <   	 t        ||      S # t        $ r t        |t              rnt        |t              rt        |j                  j	                               }|t        |       k(  r8|j                  d      \  }	}
|	dk(  r||xx   |
z  cc<   n|
|t        |       |	z   <   |D ]  \  }	}
|
|t        |       |	z   <    Y w xY wNr   r   )rw   rQ  r   r  r   r   r>   r   r   r   rh  )r    r1   r   rx   r   rQ   r   rR   other_itemsother_start	other_seqs              r   r@   z%_PartiallyDefinedSequenceData.__add__	  sI   TSZ'DJJTZZ%%'(2Y
sc#h	(%LE c$iUu$"'SY,VT::% & 	>%!78E#@A"5;;#4#4#67#d)#-8__Q-?*K"a'Uy08ASY45.9 >*K4=DT[01>	>s   'B) )B.EEc                    t        |      t        |       z   }	 t        |      }d|i}t        | j                  j	                               }|j                  d      \  }}|dk(  r|dxx   |z  cc<   n||t        |      |z   <   |D ]  \  }}||t        |      |z   <    	 t        ||      S # t        $ rC | j                  j	                         D ci c]  \  }}t        |      |z   | nc c}}w }}}Y Ww xY wr  )rw   r   r  r   r   rh  r>   r   )r    r1   r   rx   r   rQ   r   s          r   rB   z&_PartiallyDefinedSequenceData.__radd__
  s    Uc$i'	/%LE u:D))+,E1JE3zQ3+.SZ%'(# /
s+.SZ%'(/,VT:: & 	R>Bjj>N>N>PQ
sCJ&+QQDQ	Rs   B+ +&C7C+*
C76C7c                    | j                   }| j                  j                         }i }d}d}t        |      D ]<  }|D ]'  \  }}	|||z  z  }||k(  r||xx   |	z  cc<   !|	||<   |}) t	        	      z   }> t        ||z  |      S r  )rs  r   r   r   rw   r   )
r    r1   r   r   rx   rR   r  rf  rQ   r   s
             r   rE   z%_PartiallyDefinedSequenceData.__mul__,
  s    

  "u 	#A# %
sV#%<Nc)N"%DK$H% #c("C	# -Ve^TBBr   c                     | j                   j                         D ci c]  \  }}||j                          }}}t        | j                  |      S c c}}w r  )r   r   r|   r   rs  r    rQ   r   rx   s       r   r|   z#_PartiallyDefinedSequenceData.upper=
  H    59ZZ5E5E5GHzucsyy{"HH,T\\4@@ I   Ac                     | j                   j                         D ci c]  \  }}||j                          }}}t        | j                  |      S c c}}w r  )r   r   r   r   rs  r  s       r   r   z#_PartiallyDefinedSequenceData.lowerB
  r  r  c                     t        d      )r   r  r~  r   s    r   r   z%_PartiallyDefinedSequenceData.isupperG
       %%QRRr   c                     t        d      )r   r  r~  r   s    r   r   z%_PartiallyDefinedSequenceData.islowerO
  r  r   c           	          | j                   j                         }|D ci c]  \  }}||j                  ||       }}}t        | j                  |      S c c}}w r   )r   r   r   r   rs  )r    r   r   r   rQ   r   rx   s          r   r   z'_PartiallyDefinedSequenceData.translateW
  sT     

  "FKL
ss}}UF33LL,T\\4@@ Ms   Ac           	          t        |      t        |      k7  rt        d      | j                  j                         }|D ci c]  \  }}||j	                  ||       }}}t        | j                  |      S c c}}w )r   z_Sequence content is only partially defined; substring 
replacement cannot be performed reliably)rw   r>   r   r   r   r   rs  )r    r   r   r   rQ   r   rx   s          r   r   z%_PartiallyDefinedSequenceData.replaced
  sx     s8s3x(;  

  "?DEs{{3,,EE,T\\4@@ Fs   A8c                      y)zMReturn False, as the sequence is not fully defined and has a non-zero length.Fr   r   s    r   r   z%_PartiallyDefinedSequenceData.defineds
  r  r   c                 V    t        d | j                  j                         D              S )r   c              3   B   K   | ]  \  }}||t        |      z   f  y wr#   r   )r   rQ   r   s      r   r   z?_PartiallyDefinedSequenceData.defined_ranges.<locals>.<genexpr>~
  s"     T:5#eUSX-.Ts   )r  r   r   r   s    r   r   z,_PartiallyDefinedSequenceData.defined_rangesx
  s"     TAQAQASTTTr   r   )r   r   r   r   r   r!   r   rM  rL  r   r   r(   r$   r*   r@   rB   rE   r|   r   r   r   r   r   r   r   r   r  r  s   @r   r   r   	  s     %I@W$@W	u33	4@WDS;8;$C"A
A
SSAA   U Ur   r   c                     t        | t              r| j                         S t        | t              rt        |       j                         S | j	                  dd      j	                  dd      S )a  Transcribe a DNA sequence into RNA.

    Following the usual convention, the sequence is interpreted as the
    coding strand of the DNA double helix, not the template strand. This
    means we can get the RNA sequence just by switching T to U.

    If given a string, returns a new string object.

    Given a Seq or MutableSeq, returns a new Seq object.

    e.g.

    >>> transcribe("ACTGN")
    'ACUGN'
    r   r   tu)r   r   r;  r   r   )dnas    r   r;  r;  
  sV      #s~~	C	$3x""$${{3$,,S#66r   c                     t        | t              r| j                         S t        | t              rt        |       j                         S | j	                  dd      j	                  dd      S )zReturn the RNA sequence back-transcribed into DNA.

    If given a string, returns a new string object.

    Given a Seq or MutableSeq, returns a new Seq object.

    e.g.

    >>> back_transcribe("ACUGN")
    'ACTGN'
    r   r   r  r  )r   r   r=  r   r   )rnas    r   r=  r=  
  sX     #s""$$	C	$3x'')){{3$,,S#66r   c           	         	 t        |      }t        j                  |   }| j                         } g }	|j                  }
|j                  }|j                  $t        |j                  j                               }nFt        t        j                   j                         t        j"                  j                         z         }t%        |       }|D cg c]	  }||
v s| }}|rX|d   }|r!t        dt%        |       d| d|
|    d	      t'        j(                  d
t%        |       d| d|
|    dt*               |rt        | dd       j                         |j,                  vrt        j.                  d| dd  d      |dz  dk7  rt        j.                  d| d      t        | dd       j                         |vrt        j.                  d| dd  d      | dd } |dz  }dg}	n"|dz  dk7  rt'        j(                  dt*               |4t        |t              st        d      t%        |      dkD  rt        d      t1        d||dz  z
  d      D ]  }| ||dz    }	 |	j3                  |
|          ! dj7                  |	      S # t        $ rN 	 t        j                  |   }n5# t
        $ r) t        |t              rt        d      dt        d      dw xY wY t        t        f$ r- t        |t        j                        r|}nt        d      dY w xY wc c}w # t
        t        j.                  f$ r ||j                  v r3|rt        j.                  d| d      d|rY  |	j3                  |       nb|j5                  t        |            r|	j3                  |       n6|||dz  k(  r|	j3                  |       nt        j.                  d| d      dY w xY w)a	  Translate nucleotide string into a protein string (PRIVATE).

    Arguments:
     - sequence - a string
     - table - Which codon table to use?  This can be either a name (string),
       an NCBI identifier (integer), or a CodonTable object (useful for
       non-standard genetic codes).  This defaults to the "Standard" table.
     - stop_symbol - a single character string, what to use for terminators.
     - to_stop - boolean, should translation terminate at the first
       in frame stop codon?  If there is no in-frame stop codon
       then translation continues to the end.
     - pos_stop - a single character string for a possible stop codon
       (e.g. TAN or NNN)
     - cds - Boolean, indicates this is a complete CDS.  If True, this
       checks the sequence starts with a valid alternative start
       codon (which will be translated as methionine, M), that the
       sequence length is a multiple of three, and that there is a
       single in frame stop codon at the end (this will be excluded
       from the protein sequence, regardless of the to_stop option).
       If these tests fail, an exception is raised.
     - gap - Single character string to denote symbol used for gaps.
       Defaults to None.

    Returns a string.

    e.g.

    >>> from Bio.Data import CodonTable
    >>> table = CodonTable.ambiguous_dna_by_id[1]
    >>> _translate_str("AAA", table)
    'K'
    >>> _translate_str("TAR", table)
    '*'
    >>> _translate_str("TAN", table)
    'X'
    >>> _translate_str("TAN", table, pos_stop="@")
    '@'
    >>> _translate_str("TA?", table)
    Traceback (most recent call last):
       ...
    Bio.Data.CodonTable.TranslationError: Codon 'TA?' is invalid

    In a change to older versions of Biopython, partial codons are now
    always regarded as an error (previously only checked if cds=True)
    and will trigger a warning (likely to become an exception in a
    future release).

    If **cds=True**, the start and stop codons are checked, and the start
    codon will be translated at methionine. The sequence must be an
    while number of codons.

    >>> _translate_str("ATGCCCTAG", table, cds=True)
    'MP'
    >>> _translate_str("AAACCCTAG", table, cds=True)
    Traceback (most recent call last):
       ...
    Bio.Data.CodonTable.TranslationError: First codon 'AAA' is not a start codon
    >>> _translate_str("ATGCCCTAGCCCTAG", table, cds=True)
    Traceback (most recent call last):
       ...
    Bio.Data.CodonTable.TranslationError: Extra in frame stop codon 'TAG' found.
    zThe Bio.Seq translate methods and function DO NOT take a character string mapping table like the python string object's translate method. Use str(my_seq).translate(...) instead.Nz(table argument must be integer or stringzBad table argumentr   z=You cannot use 'to_stop=True' with this table as it contains z: codon(s) which can be both STOP and an amino acid (e.g. 'z' -> 'z' or STOP).zThis table contains z? codon(s) which code(s) for both STOP and an amino acid (e.g. 'z9' or STOP). Such codons will be translated as amino acid.r  zFirst codon 'z' is not a start codonzSequence length z is not a multiple of threer   zFinal codon 'z' is not a stop codon   MzPartial codon, len(sequence) not a multiple of three. Explicitly trim the sequence or add trailing N before translation. This may become an error in future.z2Gap character should be a single character string.r   zExtra in frame stop codon 'z' found.zCodon 'z' is invalidr   )rL  r	   ambiguous_generic_by_idrP  ambiguous_generic_by_nameKeyErrorr   r   r   rv   r|   forward_tablestop_codonsnucleotide_alphabetr   r
   ambiguous_dna_lettersambiguous_rna_lettersrw   r   r!  r   start_codonsTranslationErrorr   rb  
issupersetr   )sequencer   r#  r$  r%  pos_stopr  table_idcodon_tableamino_acidsr  r  valid_lettersr&  rB  dual_codingrf  codons                     r   r"  r"  
  sV   BCu:2 !88B~~HK--M))K&&2K;;AACD ++113--3356
 	HA *@Q--?1@K@N$% &&&'S}Q/?.@M 
 	"3{#3"4 5334#VM!<L;M NGG 		
 x|""$K,D,DD--!~-CD  q5A:--"1#%@A  x}##%[8--.CD  Ab>	Qe	
Q!? 		
 #s#PQQX\QRR1a!a%i# QU#	}U34. 77;[  V	V$>>uEK 		V%% >
    JKQUU		V  I& =eZ223K12< =2 Ad *556 	///$555eWHE  "";/))#e*5""8,UcAg%5""3' 11eWL1!	sU   J 	LLL	LJ$#L$2KL7LLAO'A4OOc                     t        | t              r| j                  ||||      S t        | t              rt        |       j                  ||||      S t	        | |||||      S )a  Translate a nucleotide sequence into amino acids.

    If given a string, returns a new string object. Given a Seq or
    MutableSeq, returns a Seq object.

    Arguments:
     - table - Which codon table to use?  This can be either a name
       (string), an NCBI identifier (integer), or a CodonTable object
       (useful for non-standard genetic codes).  Defaults to the "Standard"
       table.
     - stop_symbol - Single character string, what to use for any
       terminators, defaults to the asterisk, "*".
     - to_stop - Boolean, defaults to False meaning do a full
       translation continuing on past any stop codons
       (translated as the specified stop_symbol).  If
       True, translation is terminated at the first in
       frame stop codon (and the stop_symbol is not
       appended to the returned protein sequence).
     - cds - Boolean, indicates this is a complete CDS.  If True, this
       checks the sequence starts with a valid alternative start
       codon (which will be translated as methionine, M), that the
       sequence length is a multiple of three, and that there is a
       single in frame stop codon at the end (this will be excluded
       from the protein sequence, regardless of the to_stop option).
       If these tests fail, an exception is raised.
     - gap - Single character string to denote symbol used for gaps.
       Defaults to None.

    A simple string example using the default (standard) genetic code:

    >>> coding_dna = "GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG"
    >>> translate(coding_dna)
    'VAIVMGR*KGAR*'
    >>> translate(coding_dna, stop_symbol="@")
    'VAIVMGR@KGAR@'
    >>> translate(coding_dna, to_stop=True)
    'VAIVMGR'

    Now using NCBI table 2, where TGA is not a stop codon:

    >>> translate(coding_dna, table=2)
    'VAIVMGRWKGAR*'
    >>> translate(coding_dna, table=2, to_stop=True)
    'VAIVMGRWKGAR'

    In fact this example uses an alternative start codon valid under NCBI
    table 2, GTG, which means this example is a complete valid CDS which
    when translated should really start with methionine (not valine):

    >>> translate(coding_dna, table=2, cds=True)
    'MAIVMGRWKGAR'

    Note that if the sequence has no in-frame stop codon, then the to_stop
    argument has no effect:

    >>> coding_dna2 = "GTGGCCATTGTAATGGGCCGC"
    >>> translate(coding_dna2)
    'VAIVMGR'
    >>> translate(coding_dna2, to_stop=True)
    'VAIVMGR'

    NOTE - Ambiguous codons like "TAN" or "NNN" could be an amino acid
    or a stop codon.  These are translated as "X".  Any invalid codon
    (e.g. "TA?" or "T-A") will throw a TranslationError.

    It will however translate either DNA or RNA.

    NOTE - Since version 1.71 Biopython contains codon tables with 'ambiguous
    stop codons'. These are stop codons with unambiguous sequence but which
    have a context dependent coding as STOP or as amino acid. With these tables
    'to_stop' must be False (otherwise a ValueError is raised). The dual
    coding codons will always be translated as amino acid, except for
    'cds=True', where the last codon will be translated as STOP.

    >>> coding_dna3 = "ATGGCACGGAAGTGA"
    >>> translate(coding_dna3)
    'MARK*'

    >>> translate(coding_dna3, table=27)  # Table 27: TGA -> STOP or W
    'MARKW'

    It will however raise a BiopythonWarning (not shown).

    >>> translate(coding_dna3, table=27, cds=True)
    'MARK'

    >>> translate(coding_dna3, table=27, to_stop=True)
    Traceback (most recent call last):
       ...
    ValueError: You cannot use 'to_stop=True' with this table ...
    r  )r   r   r   r   r"  )r  r   r#  r$  r%  r  s         r   r   r   e  sb    | (C !!%gsCC	Hj	)8}&&uk7CHH h{GScRRr   c                 F   ddl m} t        | t        t        f      r| j                  |      S t        | |      r|rt        d      | j                         S |rt        d      | j                  d      } | j                  t              } | j                  d      } | ddd   S )ac  Return the reverse complement as a DNA sequence.

    If given a string, returns a new string object.
    Given a Seq object, returns a new Seq object.
    Given a MutableSeq, returns a new MutableSeq object.
    Given a SeqRecord object, returns a new SeqRecord object.

    >>> my_seq = "CGA"
    >>> reverse_complement(my_seq)
    'TCG'
    >>> my_seq = Seq("CGA")
    >>> reverse_complement(my_seq)
    Seq('TCG')
    >>> my_seq = MutableSeq("CGA")
    >>> reverse_complement(my_seq)
    MutableSeq('TCG')
    >>> my_seq
    MutableSeq('CGA')

    Any U in the sequence is treated as a T:

    >>> reverse_complement(Seq("CGAUT"))
    Seq('AATCG')

    In contrast, ``reverse_complement_rna`` returns an RNA sequence:

    >>> reverse_complement_rna(Seq("CGAUT"))
    Seq('AAUCG')

    Supports and lower- and upper-case characters, and unambiguous and
    ambiguous nucleotides. All other characters are not converted:

    >>> reverse_complement("ACGTUacgtuXYZxyz")
    'zrxZRXaacgtAACGT'

    The sequence is modified in-place and returned if inplace is True:

    >>> my_seq = MutableSeq("CGA")
    >>> reverse_complement(my_seq, inplace=True)
    MutableSeq('TCG')
    >>> my_seq
    MutableSeq('TCG')

    As strings and ``Seq`` objects are immutable, a ``TypeError`` is
    raised if ``reverse_complement`` is called on a ``Seq`` object with
    ``inplace=True``.
    r   r?  SeqRecords are immutablestrings are immutabler   Nr   )rA  r@  r   r   r   r0  r   r   r   r(  rK   r  r  r@  s      r   r0  r0    s    ` ((S*-.**733(I&677**,,/00w'H!!"78Hw'HDbD>r   c                 F   ddl m} t        | t        t        f      r| j                  |      S t        | |      r|rt        d      | j                         S |rt        d      | j                  d      } | j                  t              } | j                  d      } | ddd   S )a  Return the reverse complement as an RNA sequence.

    If given a string, returns a new string object.
    Given a Seq object, returns a new Seq object.
    Given a MutableSeq, returns a new MutableSeq object.
    Given a SeqRecord object, returns a new SeqRecord object.

    >>> my_seq = "CGA"
    >>> reverse_complement_rna(my_seq)
    'UCG'
    >>> my_seq = Seq("CGA")
    >>> reverse_complement_rna(my_seq)
    Seq('UCG')
    >>> my_seq = MutableSeq("CGA")
    >>> reverse_complement_rna(my_seq)
    MutableSeq('UCG')
    >>> my_seq
    MutableSeq('CGA')

    Any T in the sequence is treated as a U:

    >>> reverse_complement_rna(Seq("CGAUT"))
    Seq('AAUCG')

    In contrast, ``reverse_complement`` returns a DNA sequence:

    >>> reverse_complement(Seq("CGAUT"), inplace=False)
    Seq('AATCG')

    Supports and lower- and upper-case characters, and unambiguous and
    ambiguous nucleotides. All other characters are not converted:

    >>> reverse_complement_rna("ACGTUacgtuXYZxyz")
    'zrxZRXaacguAACGU'

    The sequence is modified in-place and returned if inplace is True:

    >>> my_seq = MutableSeq("CGA")
    >>> reverse_complement_rna(my_seq, inplace=True)
    MutableSeq('UCG')
    >>> my_seq
    MutableSeq('UCG')

    As strings and ``Seq`` objects are immutable, a ``TypeError`` is
    raised if ``reverse_complement`` is called on a ``Seq`` object with
    ``inplace=True``.
    r   r?  r  r  r   Nr   )rA  r@  r   r   r   r4  r   r   r   r-  rK   r  s      r   r4  r4    s    ` ((S*-...w77(I&677..00/00w'H!!"78Hw'HDbD>r   c                 :   ddl m} t        | t        t        f      r| j                  |      S t        | |      r|rt        d      | j                         S |du rt        d      | j                  d      } | j                  t              } | j                  d      S )a  Return the complement as a DNA sequence.

    If given a string, returns a new string object.
    Given a Seq object, returns a new Seq object.
    Given a MutableSeq, returns a new MutableSeq object.
    Given a SeqRecord object, returns a new SeqRecord object.

    >>> my_seq = "CGA"
    >>> complement(my_seq)
    'GCT'
    >>> my_seq = Seq("CGA")
    >>> complement(my_seq)
    Seq('GCT')
    >>> my_seq = MutableSeq("CGA")
    >>> complement(my_seq)
    MutableSeq('GCT')
    >>> my_seq
    MutableSeq('CGA')

    Any U in the sequence is treated as a T:

    >>> complement(Seq("CGAUT"))
    Seq('GCTAA')

    In contrast, ``complement_rna`` returns an RNA sequence:

    >>> complement_rna(Seq("CGAUT"))
    Seq('GCUAA')

    Supports and lower- and upper-case characters, and unambiguous and
    ambiguous nucleotides. All other characters are not converted:

    >>> complement("ACGTUacgtuXYZxyz")
    'TGCAAtgcaaXRZxrz'

    The sequence is modified in-place and returned if inplace is True:

    >>> my_seq = MutableSeq("CGA")
    >>> complement(my_seq, inplace=True)
    MutableSeq('GCT')
    >>> my_seq
    MutableSeq('GCT')

    As strings and ``Seq`` objects are immutable, a ``TypeError`` is
    raised if ``reverse_complement`` is called on a ``Seq`` object with
    ``inplace=True``.
    r   r?  r  Tr  r   )rA  r@  r   r   r   r*  r   r   r   r(  rK   r  s      r   r*  r*  O  s    ` ((S*-.""7++(I&677""$$$/00w'H!!"78H??7##r   c                 6   ddl m} t        | t        t        f      r| j                  |      S t        | |      r|rt        d      | j                         S |rt        d      | j                  d      } | j                  t              } | j                  d      S )a'  Return the complement as an RNA sequence.

    If given a string, returns a new string object.
    Given a Seq object, returns a new Seq object.
    Given a MutableSeq, returns a new MutableSeq object.
    Given a SeqRecord object, returns a new SeqRecord object.

    >>> my_seq = "CGA"
    >>> complement_rna(my_seq)
    'GCU'
    >>> my_seq = Seq("CGA")
    >>> complement_rna(my_seq)
    Seq('GCU')
    >>> my_seq = MutableSeq("CGA")
    >>> complement_rna(my_seq)
    MutableSeq('GCU')
    >>> my_seq
    MutableSeq('CGA')

    Any T in the sequence is treated as a U:

    >>> complement_rna(Seq("CGAUT"))
    Seq('GCUAA')

    In contrast, ``complement`` returns a DNA sequence:

    >>> complement(Seq("CGAUT"))
    Seq('GCTAA')

    Supports and lower- and upper-case characters, and unambiguous and
    ambiguous nucleotides. All other characters are not converted:

    >>> complement_rna("ACGTUacgtuXYZxyz")
    'UGCAAugcaaXRZxrz'

    The sequence is modified in-place and returned if inplace is True:

    >>> my_seq = MutableSeq("CGA")
    >>> complement(my_seq, inplace=True)
    MutableSeq('GCT')
    >>> my_seq
    MutableSeq('GCT')

    As strings and ``Seq`` objects are immutable, a ``TypeError`` is
    raised if ``reverse_complement`` is called on a ``Seq`` object with
    ``inplace=True``.
    r   r?  r  r  r   )rA  r@  r   r   r   r.  r   r   r   r-  rK   r  s      r   r.  r.    s    ` ((S*-.&&w//(I&677&&((/00w'H!!"78H??7##r   __main__)IGNORE_EXCEPTION_DETAIL)run_doctest)optionflags)rI  FFXN)rH  rI  FFNrG  )+r   r   r   r   abcr   r   typingr   r   r   Bior   Bio.Datar	   r
   r   rQ  ambiguous_dna_complementr(  ambiguous_rna_complementr-  r   r   r   r   rP  r>   r   r   r;  r=  r"  r   r0  r4  r*  r.  r   doctestr  
Bio._utilsr  r   r   r   <module>r     s`  
            I&  	 B BC  8 =  "#;< 	 B BC  8 =  "#;< fC fR	|-C |-~3S 
 S llD& lD^*Z *i: iX_U$A _UN707* SWp h PTeSP>B>B=$@=$@ z/&34	 r   