o
    Rŀg                     @   sL   d Z ddlmZ ddlmZ G dd dZG dd deZG dd	 d	Zd
S )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                   @   s   e Zd ZdZdd ZdS )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                 K   s0   t |d | _|d | _|d | _|d | _dS )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kwds r   E/var/www/html/myenv/lib/python3.10/site-packages/Bio/CAPS/__init__.py__init__$   s   

zDifferentialCutsite.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )!AlignmentHasDifferentLengthsErrorz>Exception where sequences in alignment have different lengths.N)r   r   r   r   r   r   r   r   r   0   s    r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
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                 C   s   |du rg }t |tr1dd |D | _t| j| _t| jd | _| jD ]}t|| jkr/tq$ndd |D | _|j\| _| _|| _|| _	| 
  dS )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.

        Nc                 S   s   g | ]}|j qS r   )seq).0recr   r   r   
<listcomp>L   s    z$CAPSMap.__init__.<locals>.<listcomp>r   c                 S   s   g | ]}t |qS r   r   )r   sr   r   r   r   S   s    )
isinstancer   	sequenceslensizelengthr   shape	alignmentenzymes_digest)r   r!   r"   r   r   r   r   r   >   s    

zCAPSMap.__init__c           
   	      s   g }g }| j D ]} fdd |D }|| || qtt|}|D ]1}g }g }t| j D ]\}	}|||	 v rC||	 q3||	 q3|rY|rY| jt| ||d q(d S )Nc                    s   g | ]}| j  qS r   )fst5)r   cutr   r   r   r   c   s    z(CAPSMap._digest_with.<locals>.<listcomp>)r   r   r   r	   )	r   searchextendappendsortedset	enumeratedcutsr   )
r   r   cutsall_seq_cutsr   seq_cutsr%   r   r	   ir   r&   r   _digest_with\   s,   

zCAPSMap._digest_withc                 C   s    g | _ | jD ]}| | qd S N)r-   r"   r2   )r   r   r   r   r   r#   ~   s   
zCAPSMap._digestr3   )r   r   r   r   r   r2   r#   r   r   r   r   r   4   s
    
	"r   N)	r   	Bio.Alignr   Bio.Seqr   r   	Exceptionr   r   r   r   r   r   <module>   s   
