o
    RÅ€gè  ã                   @   s²   d 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d
l
mZ ddlmZ ddlmZ ddlmZ ddlmZ G dd„ dƒZdS )z÷Plots to compare information between different sources.

This file contains high level plots which are designed to be used to
compare different types of information. The most basic example is comparing
two variables in a traditional scatter plot.
é    )ÚLinePlot)ÚmakeEmptyCircle)ÚmakeEmptySquare)ÚmakeFilledCircle)ÚmakeFilledDiamond)ÚmakeFilledSquare)Ú
makeSmiley)ÚDrawing)ÚString)Úcolors)Úletter)Úinch)Ú_writec                   @   sB   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚComparativeScatterPlota6  Display a scatter-type plot comparing two different kinds of info.

    Attributes;
     - display_info - a 2D list of the information we'll be outputting. Each
       top level list is a different data type, and each data point is a
       two-tuple of the coordinates of a point.

    So if you had two distributions of points, it should look like::

       display_info = [[(1, 2), (3, 4)],
                       [(5, 6), (7, 8)]]

    If everything is just one set of points, display_info can look like::

        display_info = [[(1, 2), (3, 4), (5, 6)]]

    Úpdfc                 C   sR   d| _ t| _d| _|| _g | _tjtjtj	tj
tjtjg| _ttttttg| _dS )zInitialize the class.é   é   N)Únumber_of_columnsr   Ú	page_sizeÚ
title_sizeÚoutput_formatÚdisplay_infor   ÚredÚgreenÚblueÚyellowÚorangeÚblackÚcolor_choicesr   r   r   r   r   r   Úshape_choices)Úselfr   © r!   úL/var/www/html/myenv/lib/python3.10/site-packages/Bio/Graphics/Comparative.pyÚ__init__1   s&   ú	
úzComparativeScatterPlot.__init__c           
      C   sl   | j \}}t||ƒ}|  ||||¡ td }|td  }|dt  }dt }	|  |||	||¡ t||| jƒS )zéWrite the comparative plot to a file.

        Arguments:
         - output_file - The name of the file to output the information to,
           or a handle to write to.
         - title - A title to display on the graphic.

        g      à?g      ø?)r   r	   Ú_draw_titler   Ú_draw_scatter_plotr   r   )
r    Úoutput_fileÚtitleÚwidthÚheightÚcur_drawingÚstart_xÚend_xÚend_yÚstart_yr!   r!   r"   Údraw_to_fileO   s   
	
z#ComparativeScatterPlot.draw_to_filec                 C   s6   t |d |t |ƒ}d|_| j|_d|_| |¡ dS )z4Add a title to the page we are outputting (PRIVATE).é   zHelvetica-BoldÚmiddleN)r
   r   ÚfontNamer   ÚfontSizeÚ
textAnchorÚadd)r    r*   r'   r(   r)   Útitle_stringr!   r!   r"   r$   e   s
   z"ComparativeScatterPlot._draw_titlec                 C   s¬   t ƒ }||_||_t|| ƒ|_t|| ƒ|_| j|_d|_|  	| j¡\}}}	}
||j
_||j
_|| d |j
_|	|j_|
|j_|
|	 d |j_|  || j¡ | |¡ dS )zHDraw a scatter plot on the drawing with the given coordinates (PRIVATE).r   g      $@N)r   ÚxÚyÚabsr(   r)   r   ÚdataÚjoinedLinesÚ_find_min_maxÚ
xValueAxisÚvalueMinÚvalueMaxÚ	valueStepÚ
yValueAxisÚ_set_colors_and_shapesr5   )r    r*   Úx_startÚy_startÚx_endÚy_endÚscatter_plotÚx_minÚx_maxÚy_minÚy_maxr!   r!   r"   r%   n   s    z)ComparativeScatterPlot._draw_scatter_plotc                 C   sr   t t|ƒƒD ]0}|d t| jƒk r$| j| |j| _| j| |j| _q| jd |j| _| jd |j| _qdS )aN  Set the colors and shapes of the points displayed (PRIVATE).

        By default this just sets all of the points according to the order
        of colors and shapes defined in self.color_choices and
        self.shape_choices. The first 5 shapes and colors are unique, the
        rest of them are just set to the same color and shape (since I
        ran out of shapes!).

        You can change how this function works by either changing the
        values of the color_choices and shape_choices attributes, or
        by inheriting from this class and overriding this function.
        r   éÿÿÿÿN)ÚrangeÚlenr   ÚlinesÚstrokeColorr   Úsymbol)r    rG   r   Ú	value_numr!   r!   r"   rB   Š   s   ÿöz-ComparativeScatterPlot._set_colors_and_shapesc           	      C   s”   |d d d }|d d d }|d d d }|d d d }|D ]!}|D ]\}}||kr0|}||k r6|}||kr<|}||k rB|}q&q"||||fS )zEFind min and max for x and y coordinates in the given data (PRIVATE).r   r   r!   )	r    ÚinforH   rI   rJ   rK   Ú
two_d_listr7   r8   r!   r!   r"   r<   £   s"   €ø
z$ComparativeScatterPlot._find_min_maxN)r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r/   r$   r%   rB   r<   r!   r!   r!   r"   r      s    
	r   N)rX   Ú#reportlab.graphics.charts.lineplotsr   Ú!reportlab.graphics.charts.markersr   r   r   r   r   r   Úreportlab.graphics.shapesr	   r
   Úreportlab.libr   Úreportlab.lib.pagesizesr   Úreportlab.lib.unitsr   ÚBio.Graphicsr   r   r!   r!   r!   r"   Ú<module>   s   