:py:mod:`alhambra.seq`
======================

.. py:module:: alhambra.seq


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   alhambra.seq.Seq



Functions
~~~~~~~~~

.. autoapisummary::

   alhambra.seq.revcomp
   alhambra.seq.is_null
   alhambra.seq.is_definite
   alhambra.seq.check_seq
   alhambra.seq.count_ambiguous
   alhambra.seq.dna_length
   alhambra.seq.merge



Attributes
~~~~~~~~~~

.. autoapisummary::

   alhambra.seq._L_TO_N
   alhambra.seq._N_TO_L
   alhambra.seq._WC
   alhambra.seq._PUNC
   alhambra.seq._WC_WITH_PUNC
   alhambra.seq._AMBBASES
   alhambra.seq._VALID_NTS
   alhambra.seq._VALID_WITH_PUNC


.. py:data:: _L_TO_N

   

.. py:data:: _N_TO_L

   

.. py:data:: _WC

   

.. py:data:: _PUNC
   :value: Multiline-String

    .. raw:: html

        <details><summary>Show Value</summary>

    .. code-block:: python

        """-+ 
        	"""

    .. raw:: html

        </details>

   

.. py:data:: _WC_WITH_PUNC

   

.. py:data:: _AMBBASES

   

.. py:data:: _VALID_NTS

   

.. py:data:: _VALID_WITH_PUNC

   

.. py:function:: revcomp(seq_str: str) -> str

   Return the reverse complement of a string sequence.  Preserves
   whitespace and capitalization.  Does not do any sequence checking.


.. py:function:: is_null(seq_str: str | None, _check_seq: bool = True) -> bool

   Return True if a sequence consists only of Ns (or Xs), or is empty.
   Return False otherwise.


.. py:function:: is_definite(seq_str: str | None, _check_seq: bool = True) -> bool

   Return True if a sequence consists only of defined bases.  Return
   False otherwise.  If blank, return False.


.. py:function:: check_seq(seq_str: str)

   Raises an error (`InvalidSequence`) if the sequence has invalid elements.


.. py:function:: count_ambiguous(seq_str: str, _check_seq: bool = True) -> int

   Return the number of ambiguous bases in a sequence.


.. py:function:: dna_length(seq_str: str, _check_seq: bool = True) -> int

   Return the length of a sequence, stripping whitespace.  This does not handle
   extended labels, etc.


.. py:function:: merge(seq1: str, seq2: str, _check_seq: bool = True) -> str

   Merge two sequences together, returning a single sequence that
   represents the constraint of both sequences.  If the sequences
   can't be merged, raise a MergeConflictError.


.. py:exception:: InvalidSequence


   Bases: :py:obj:`ValueError`

   Inappropriate argument value (of correct type).

   .. py:attribute:: sequence
      :type: str

      

   .. py:attribute:: invalids
      :type: List[Tuple[int, str]]

      


.. py:exception:: MergeConflictError


   Bases: :py:obj:`ValueError`

   Merge of items failed because of conflicting information.
   Arguments are (item1, item2, location or property, value1, value2)

   .. py:attribute:: item1
      :type: str

      

   .. py:attribute:: item2
      :type: str

      

   .. py:attribute:: location
      :type: Union[str, Tuple[int, int], int]

      

   .. py:attribute:: value1
      :type: Union[str, int]

      

   .. py:attribute:: value2
      :type: Union[str, int]

      


.. py:exception:: MergeConflictsError


   Bases: :py:obj:`ValueError`

   Merge of multiple items failed because individual merges
   raised MergeConflictErrors.
   Arguments are ([list of MergeConflictErrors])


.. py:class:: Seq(seq_str: Union[Seq, str])


   .. py:property:: revcomp
      :type: Seq


   .. py:property:: is_null
      :type: bool


   .. py:property:: is_definite
      :type: bool


   .. py:property:: dna_length
      :type: int


   .. py:property:: n_ambiguous
      :type: int


   .. py:property:: base_str
      :type: str


   .. py:attribute:: seq_str
      :type: str

      

   .. py:method:: __add__(other: Seq | str) -> Seq


   .. py:method:: __radd__(other: Seq | str) -> Seq


   .. py:method:: merge(other: Union[Seq, str, None]) -> Seq


   .. py:method:: __or__(other: Union[Seq, str, None]) -> Seq


   .. py:method:: __ror__(other: Union[Seq, str, None]) -> Seq


   .. py:method:: __str__() -> str

      Return str(self).


   .. py:method:: __repr__() -> str

      Return repr(self).


   .. py:method:: __len__() -> int


   .. py:method:: __getitem__(ix: Union[int, slice]) -> Seq
      :abstractmethod:



