o
    Rŀg                     @   s.   d Z ddlmZ ddlmZ G dd dZdS )zGraphSet module.

Provides:
 - GraphSet - container for GraphData objects

For drawing capabilities, this module uses reportlab to draw and write
the diagram: http://www.reportlab.com
    )colors   )	GraphDatac                	   @   s   e Zd ZdZdddZddejejdddddf	ddZd	d
 Z	dd Z
dd Zdd Zdd ZdddZdd Zdd Zdd ZdS )GraphSetz{Graph Set.

    Attributes:
     - id        Unique identifier for the set
     - name      String describing the set

    Nc                 C   s   t | _ d| _i | _|| _dS )zhInitialize.

        Arguments:
         - name      String identifying the graph set sensibly

        r   N)id_next_id_graphsname)selfr	    r   X/var/www/html/myenv/lib/python3.10/site-packages/Bio/Graphics/GenomeDiagram/_GraphSet.py__init__*   s   
zGraphSet.__init__barr   c                 C   s`   |dur|}|	dur|	}|
dur|
}| j }t|||||||}||_|| j|< |  j d7  _ |S )a  Add a GraphData object to the diagram.

        Arguments:
         - data      List of (position, value) int tuples
         - name      String, description of the graph
         - style     String ('bar', 'heat', 'line') describing how the graph
           will be drawn
         - color    colors.Color describing the color to draw all or 'high'
           (some styles) data (overridden by backwards compatible
           argument with UK spelling, colour).
         - altcolor  colors.Color describing the color to draw 'low' (some
           styles) data (overridden by backwards compatible argument
           with UK spelling, colour).
         - linewidth     Float describing linewidth for graph
         - center        Float setting the value at which the x-axis
           crosses the y-axis (overridden by backwards
           compatible argument with UK spelling, centre)

        Add a GraphData object to the diagram (will be stored internally).
        Nr   )r   r   	linewidthr   )r
   datar	   stylecoloraltcolorr   centercolour	altcolourcentrer   graphr   r   r   	new_graph6   s   "
zGraphSet.new_graphc                 C   s   | j |= dS )z1Remove a graph from the set, indicated by its id.Nr   )r
   graph_idr   r   r   	del_graphf   s   zGraphSet.del_graphc                    s    fddt  jD S )zsReturn list of all graphs in the graph set, sorted by id.

        Sorting is to ensure reliable stacking.
        c                    s   g | ]} j | qS r   r   ).0r   r
   r   r   
<listcomp>o   s    z'GraphSet.get_graphs.<locals>.<listcomp>)sortedr   r   r   r   r   
get_graphsj   s   zGraphSet.get_graphsc                 C   s   t | j S )z+Return a list of all ids for the graph set.)listr   keysr   r   r   r   get_idsq   s   zGraphSet.get_idsc                 C   sJ   g g }}| j  D ]}| \}}|| || q
t|t|fS )z@Return the lowest and highest base (or mark) numbers as a tuple.)r   valuesrangeappendminmax)r
   lowshighsr   lowhighr   r   r   r&   u   s   

zGraphSet.rangec                 C   sh   g }| j  D ]}|t|j 7 }q|  t|}|d ||d  ||d  |d| d  |d fS )zEReturn (minimum, lowerQ, medianQ, upperQ, maximum) values as a tuple.r            )r   r%   r"   r   sortlen)r
   r   r   datalenr   r   r   data_quartiles~   s   

zGraphSet.data_quartilesr   c                 C   s^   |s|  S d| j  d| j dg}|dt| j  | jD ]}|| j|   qd|S )zReturn a formatted string with information about the set.

        Arguments:
            - verbose - Flag indicating whether a short or complete account
              of the set is required

        
<: >	%d graphs
	__class__r	   r'   r3   r   join)r
   verboseoutstrkeyr   r   r   	to_string   s   

zGraphSet.to_stringc                 C   s
   t | jS )z'Return the number of graphs in the set.)r3   r   r   r   r   r   __len__      
zGraphSet.__len__c                 C   s
   | j | S )zReturn a graph, keyed by id.r   )r
   r@   r   r   r   __getitem__   rC   zGraphSet.__getitem__c                 C   s:   d| j  d| j dg}|dt| j  d|}|S )zAReturn a formatted string with information about the feature set.r6   r7   r8   r9   r:   r;   )r
   r?   r   r   r   __str__   s   
zGraphSet.__str__)N)r   )__name__
__module____qualname____doc__r   r   
lightgreendarkseagreenr   r   r!   r$   r&   r5   rA   rB   rD   rE   r   r   r   r   r   !   s,    

0	
r   N)rI   reportlab.libr   _Graphr   r   r   r   r   r   <module>   s   