
    Ri                     ^    d Z ddlmZ ddlmZ  G d d      Z G d de      Z G d d	      Zy
)al  Cleaved amplified polymorphic sequence (CAPS) markers.

A CAPS marker is a location a DifferentialCutsite as described below and a
set of primers that can be used to visualize this.  More information can
be found in the paper `Konieczny and Ausubel (1993)`_ (PMID 8106085).

.. _`Konieczny and Ausubel (1993)`: https://doi.org/10.1046/j.1365-313X.1993.04020403.x

    )MultipleSeqAlignment)Seqc                       e Zd ZdZd Zy)DifferentialCutsitea   Differential enzyme cutsite in an alignment.

    A differential cutsite is a location in an alignment where an enzyme cuts
    at least one sequence and also cannot cut at least one other sequence.

    Members:
     - start - Where it lives in the alignment.
     - enzyme - The enzyme that causes this.
     - cuts_in - A list of sequences (as indexes into the alignment) the
       enzyme cuts in.
     - blocked_in - A list of sequences (as indexes into the alignment) the
       enzyme is blocked in.

    c                 f    t        |d         | _        |d   | _        |d   | _        |d   | _        y)zInitialize a DifferentialCutsite.

        Each member (as listed in the class description) should be included as a
        keyword.
        startenzymecuts_in
blocked_inN)intr   r	   r
   r   )selfkwdss     I/home/agent/.friday_env/lib/python3.12/site-packages/Bio/CAPS/__init__.py__init__zDifferentialCutsite.__init__$   s6     g'
8nI|,    N)__name__
__module____qualname____doc__r    r   r   r   r      s    	-r   r   c                       e Zd ZdZy)!AlignmentHasDifferentLengthsErrorz>Exception where sequences in alignment have different lengths.N)r   r   r   r   r   r   r   r   r   0   s    Hr   r   c                   $    e Zd ZdZddZd Zd Zy)CAPSMapzA map of an alignment showing all possible dcuts.

    Members:
     - alignment - The alignment that is mapped.
     - dcuts - A list of possible CAPS markers in the form of
       DifferentialCutsites.

    Nc                    |g }t        |t              r|D cg c]  }|j                   c}| _        t	        | j                        | _        t	        | j                  d         | _        | j                  D ]   }t	        |      | j                  k7  st         n7|D cg c]  }t        |       c}| _        |j                  \  | _        | _        || _
        || _        | j                          yc c}w c c}w )zInitialize the CAPSMap.

        Required:
         - alignment - The alignment to be mapped.

        Optional:
         - enzymes - List of enzymes to be used to create the map.
           Defaults to an empty list.

        Nr   )
isinstancer   seq	sequenceslensizelengthr   r   shape	alignmentenzymes_digest)r   r#   r$   recr   ss         r   r   zCAPSMap.__init__>   s     ?Gi!561:;#cgg;DNDNN+DIdnnQ/0DK~~ <s8t{{*;;< /88c!f8DN%.__"DIt{" 	 < 9s   C1C6c           	         g }g }| j                   D ]O  }|j                  |      D cg c]  }||j                  z
   }}|j                  |       |j	                  |       Q t        t        |            }|D ]{  }g }g }t        | j                         D ]/  \  }	}|||	   v r|j	                  |	       |j	                  |	       1 |sQ|sT| j                  j	                  t        ||||             } y c c}w )N)r   r	   r
   r   )
r   searchfst5extendappendsortedset	enumeratedcutsr   )
r   r	   cutsall_seq_cutsr   cutseq_cutsr
   r   is
             r   _digest_withzCAPSMap._digest_with\   s     >> 	"C5;]]35GHcfkk)HHH)KK!	" c,/0 	C GJ#DNN3 )3$q'>NN1%%%a(	) :

!!'!&'j	 Is   C8c                 V    g | _         | j                  D ]  }| j                  |        y N)r0   r$   r6   )r   r	   s     r   r%   zCAPSMap._digest~   s*    
ll 	&Ff%	&r   r8   )r   r   r   r   r   r6   r%   r   r   r   r   r   4   s    < D&r   r   N)	r   	Bio.Alignr   Bio.Seqr   r   	Exceptionr   r   r   r   r   <module>r<      s6    + - -8I	 IN& N&r   