
    DUf                     4   d dl Z d dlZd dlZddlmZ ddlmZ ddlmZ  e	d          Z
 e	d          Zd	 Zd
 Zd Z ej                     ej        dd           ej        de           ej        dded           ej        ddddd           ej        ddd           ej        de	d            ej        d!d" ej        g d#          d$d%&           ej        d'd(ddd)           ej        d*ed+           ej        d,ed-           ej        d.d/d01           ej        d2d3dd45          d6                                                                                                                                                             ZdS )7    N   )util)Cooler   )clig    חAg    cAc                     |                      |          d         |                      |          d         z
  }|                      |          d         |                      |          d         z
  }||z  S )Nr   r   )extent)c
row_region
col_regionnrowsncolss        L/var/www/html/software/conda/lib/python3.11/site-packages/cooler/cli/show.pyget_matrix_sizer      sd    HHZ  #ahhz&:&:1&==EHHZ  #ahhz&:&:1&==E5=    c                     |                      ||                              ||          }|dk    rt          j        |          }n|dk    rt          j        |          }|S )N)balancefieldlog2log10)matrixfetchnpr   r   )r
   r   r   r   balancedscalemats          r   load_matrixr      s\    
((85(
1
1
7
7
J
O
OCgcll	'		hsmmJr   c                    	
 dd l m d 
d  	
fd}t          j        d                   j                 j                 	g  
                                          d                                j                            d|           	                                 d S )Nr   c                 D    | j         j        \  }}}}||z   }||z   }||||fS )N)viewLimbounds)axxstartystartxdeltaydeltaxendyends          r   
get_extentzinteractive.<locals>.get_extent'   s6    )+):&tVT))r   c           	         t          t          j        | d         |z            |z            }t          t          j        | d         |z            |z            }t          t          j        | d         |z            |z            }t          t          j        | d         |z            |z            }t	          d|          }t	          d|          }t          |t          t          j        ||z            |z                      }t          |t          t          j        ||z            |z                      }||||fS )Nr   r      r   )intr   floorceilmaxmin)r	   binsizerow_chrom_lencol_chrom_lenr#   r'   r$   r(   s           r   round_trim_extentz&interactive.<locals>.round_trim_extent-   s   RXfQi'122W<==276!9w.//'9::RXfQi'122W<==276!9w.//'9::QQ 4RXmg&=>>HIIJJ4RXmg&=>>HIIJJtT6))r   c           
                              d                      } |
          }|d         k    rd S |d<   t          |d                   t          |d                   f}t          |d                   t          |d                   f}j        d         }t          ||          }|t          k    r|                    t          j        d          d d d f         t          j        z             d         sN	                    dddgdddgd	d
          \  }
                    d
d
dddj                  }||gd<   ncd         r4d                                                                          d         4|                    t          ||	                     |                    |           j        j                                         d S )NFprev_extentr   r   r+   r   placeholderskg      ?)r
   lwz@The requested region is too large
to display at this resolution.center)horizontalalignmentverticalalignment	transform)set_autoscale_onr,   imagesr   MAX_MATRIX_SIZE_INTERACTIVEset_datar   onesnanplottext	transAxespopremover   
set_extentfigurecanvas	draw_idle)eventr	   new_col_regionnew_row_regionimnelemboxtxtr"   r   r1   r
   	col_chromr3   r   r)   	plotstatepltr4   	row_chromr2   r   s           r   update_heatmapz#interactive.<locals>.update_heatmap:   s   
E"""B""67M=QQY}---F#)	- "Cq	NNCq	NNB"Cq	NNCq	NNBYr]>>BB///KK

111d7+bf4555^, 7}aMJq!]MJ	 "   hh5(0&. l    .1#J	.) N+ 9.)--//66888 N+ 9 KKA~~uhPUVV   	f
	""$$$$$r   zbin-size)r8   r6   button_release_event)
matplotlib.pyplotpyplotr,   info
chromsizesgcagcfrL   mpl_connectshow)r"   r
   rX   rU   r   r   r   rY   r1   r3   r)   rV   rW   r4   r2   s   ``````` @@@@@@@r   interactiverc      s    $#####
* * ** * *-% -% -% -% -% -% -% -% -% -% -% -% -% -% -% -% -% -%^ !&$%%GL+ML+M!#JJswwyy4I4IJJIGGII  !7HHHHHJJJJJr   cool_uri	COOL_PATH)metavarrange)typez--range2z-r2zThe coordinates of a genomic region shown along the column dimension. If omitted, the column range is the same as the row range. Use to display asymmetric matrices or trans interactions.)rh   helpz
--balancedz-bTFzQShow the balanced contact matrix. If not provided, display the unbalanced counts.)is_flagdefaultri   z--outz-ozSave the image of the contact matrix to a file. If not specified, the matrix is displayed in an interactive window. The figure format is deduced from the extension of the file, the supported formats are png, jpg, svg, pdf, ps and eps.)ri   z--dpiz*The DPI of the figure, if saving to a filez--scalez-slinearr   r   zNScale transformation of the colormap: linear, log2 or log10. Default is log10.r   )rh   ri   rk   z--forcez-fzkForce display very large matrices (>=10^8 pixels). Use at your own risk as it may cause performance issues.z--zminzThe minimal value of the color scale. Units must match those of the colormap scale. To provide a negative value use a equal sign and quotes, e.g. -zmin='-0.5'z--zmaxzThe maximal value of the color scale. Units must match those of the colormap scale. To provide a negative value use a equal sign and quotes, e.g. -zmax='-0.5'z--cmapYlOrRdzThe colormap used to display the contact matrix. See the full list at http://matplotlib.org/examples/color/colormaps_reference.html)rk   ri   z--fieldcountzPixel values to display.)rk   show_defaultri   c           
      P   	 ddl }||                    d           ddlm} n?# t          $ r2 t          dt          j                   t          j        d           Y nw xY wt          |           }|j
        }|}||n|}t          j        ||          \  }}}t          j        ||          \  }}}t          |||          t          k    r1|s/t          dt          j                   t          j        d           |                    d	           |                                                    d
           |                    d           |                    t)          ||||||          d||||g||	|
           |                    | d           |                    | d           |                                }|                    dddd|                    |r|                    ||           dS t5          |                                ||||||           dS )z
    Display and browse a cooler in matplotlib.

    COOL_PATH : Path to a COOL file or Cooler URI.

    RANGE : The coordinates of the genomic region to display, in UCSC notation.
    Example: chr1:10,000,000-11,000,000

    r   NAggz%Install matplotlib to use cooler show)filer   zThe matrix of the selected region is too large. Try using lower resolution, selecting a smaller region, or use the '--force' flag to override this safety limit.)   
   )figsizezContact matrix none)interpolationr	   vminvmaxcmapz coordinatezrelative contact frequencyz$log 2 ( relative contact frequency )z%log 10 ( relative contact frequency )rl   )dpi)
matplotlibuser[   r\   ImportErrorprintsysstderrexitr   r^   r   parse_regionr   MAX_MATRIX_SIZE_FILErK   get_current_fig_managerset_window_titletitleimshowr   ylabelxlabelcolorbar	set_labelsavefigrc   r_   )rd   rg   range2r   outr}   r   forcezminzmaxr|   r   mplrW   r
   r^   r   r   rX   row_lorow_hirU   col_locol_hicbs                            r   rb   rb   q   s   ^    ?GGENNN'''''''   5CJGGGG 	xAJJ%~6J $ 1*j I IIvv $ 1*j I IIvv 	:z226JJJ 	K@ 		
 	
 	
 	
 	JJxJ   !!223CDDDIIbMMMJJAz:uhFF/     JJ)((()))JJ)((()))	BLL2:<	
 	
 		    PCS!!!!!CGGIIq)YxOOOOOs   !$ 9A A )r   clicknumpyr   rw   r   apir   r   r,   r   rA   r   r   rc   commandargumentstroptionChoicefloatrb    r   r   <module>r      s   



                       s3xx !c#hh     O O Od 
K000c"""		
@	   
6   
@   gC&RSSS	111	2	2
   
?   	
Q   	
Q   
Y   wT8R  DP DP       TS    #" 10 FDP DP DPr   