o
    Rŀg]                     @   s\   d Z ddlmZ ddlmZ ddlmZ ejejejej	ej
ejejdZG dd dZdS )	zRepresent information for graphical display.

Classes in this module are designed to hold information in a way that
makes it easy to draw graphical figures.
    )colors)ChromosomeSegment)TelomereSegment))   r   )   r   )   r   )   r   )   r	   )   r
   )      c                   @   sX   e Zd ZdZefddZdddZddd	Zd
d Zdd Z	dd Z
dd Zdd ZdS )ChromosomeCountsa  Represent a chromosome with count information.

    This is used to display information about counts along a chromosome.
    The segments are expected to have different count information, which
    will be displayed using a color scheme.

    I envision using this class when you think that certain regions of
    the chromosome will be especially abundant in the counts, and you
    want to pick those out.
    c                 C   sL   || _ i | _i | _i | _| j D ]}d| j|< d| j|< d| j|< q|| _dS )a  Initialize a representation of chromosome counts.

        Arguments:
         - segment_names - An ordered list of all segment names along
           the chromosome. The count and other information will be added
           to these.
         - color_scheme - A coloring scheme to use in the counts. This
           should be a dictionary mapping count ranges to colors (specified
           in reportlab.lib.colors).

        r   Nr   )_names_count_info_label_info_scale_info_color_scheme)selfsegment_namescolor_schemename r   V/var/www/html/myenv/lib/python3.10/site-packages/Bio/Graphics/DisplayRepresentation.py__init__,   s   



zChromosomeCounts.__init__r   c                 C   s:   z| j |  |7  < W dS  ty   td| ddw )a6  Add counts to the given segment name.

        Arguments:
         - segment_name - The name of the segment we should add counts to.
           If the name is not present, a KeyError will be raised.
         - count - The counts to add the current segment. This defaults to
           a single count.

        Segment name  not found.Nr   KeyError)r   segment_namecountr   r   r   	add_countC   s
   
zChromosomeCounts.add_countNc                 C   s:   z| j |  |  < W dS  ty   td| ddw )zDivide the counts for a segment by some kind of scale value.

        This is useful if segments aren't represented by raw counts, but
        are instead counts divided by some number.
        r   r   Nr   )r   r   scale_valuer   r   r   scale_segment_valueR   s
   z$ChromosomeCounts.scale_segment_valuec                 C   s(   || j v r|| j |< dS td| d)zrAdd a label to a specific segment.

        Raises a KeyError is the specified segment name is not found.
        r   r   N)r   r   )r   r   labelr   r   r   	add_label]   s   
zChromosomeCounts.add_labelc                 C   s(   || j v r|| j|< dS td| d)zSet the scale for a specific chromosome segment.

        By default all segments have the same scale -- this allows scaling
        by the size of the segment.

        Raises a KeyError is the specified segment name is not found.
        r   r   N)r   r   r   )r   r   scaler   r   r   	set_scaleg   s   
zChromosomeCounts.set_scalec                 C   s.   g }| j D ]}|| j| | j| f q|S )a0  Retrieve the color and label info about the segments.

        Returns a list consisting of two tuples specifying the counts and
        label name for each segment. The list is ordered according to the
        original listing of names. Labels are set as None if no label
        was specified.
        )r   appendr   r   )r   
order_infoseg_namer   r   r   get_segment_infot   s   
z!ChromosomeCounts.get_segment_infoc                 C   s   t t| jD ]V}d}|dkrt }d}n|t| jd kr%td}d}nt }| j| }| j| dkr?| | j| }||_| j| durL| j| |_	|rRd|_
n| j| |_
|| q|S )a  Add the collected segment information to a chromosome for drawing.

        Arguments:
         - chromosome - A Chromosome graphics object that we can add
           chromosome segments to.

        This creates ChromosomeSegment (and TelomereSegment) objects to
        fill in the chromosome. The information is derived from the
        label and count information, with counts transformed to the
        specified color map.

        Returns the chromosome with all of the segments added.
        r   r   Nr   )rangelenr   r   r   r   _color_from_count
fill_colorr   r#   r%   r   add)r   
chromosomeseg_numis_end_segmentcur_segmentr)   colorr   r   r   fill_chromosome   s(   
z ChromosomeCounts.fill_chromosomec                 C   sB   | j D ]\}}||kr||kr| j ||f   S qtd| d)zHTranslate the given count into a color using the color scheme (PRIVATE).zCount value z# was not found in the color scheme.)r   
ValueError)r   r   count_start	count_endr   r   r   r-      s
   z"ChromosomeCounts._color_from_count)r   )N)__name__
__module____qualname____doc__RAINBOW_COLORSr   r    r"   r$   r&   r*   r5   r-   r   r   r   r   r       s    


-r   N)r<   reportlab.libr   Bio.Graphics.BasicChromosomer   r   violetindigobluegreenyelloworangeredr=   r   r   r   r   r   <module>   s   