
    DUf(                        d dl Z d dlZddlmZ ddlmZ ddlmZ ddlmZ d dl	Z	 ej
                     e j        dd	ed
           e j        ddde           e j        dddde           e j        ddded           e j        ddd e j        d          d           e j        ddedd           e j        d d!ed"d           e j        d#d$ed%d           e j        d&d'ed d           e j        d(d)ed d           e j        d*d+d,           e j        d-d.d,           e j        d/d0ed1d           e j        d2d3d,           e j        d4d5dd6          d7                                                                                                                                                                                                 ZdS )8    N   )cli   )api)make_cooler_view)read_viewframe_from_filein_pathIN_PATH)metavartypenargswindowWINDOW)r   r   r   z--nprocz-pzPNumber of processes to split the work between.[default: 1, i.e. no process pool])helpdefaultr   z--outputz-ozASpecify output file name to store the insulation in a tsv format.F)r   r   requiredz--viewz	--regionsa  Path to a BED file containing genomic regions for which insulation scores will be calculated. Region names can be provided in a 4th column and should match regions and their names in expected. Note that '--regions' is the deprecated name of the option. Use '--view' instead. T)existsz--ignore-diagszjThe number of diagonals to ignore. By default, equals the number of diagonals ignored during IC balancing.)r   r   r   show_defaultz--clr-weight-namezxUse balancing weight with this name. Provide empty argument to calculate insulation on raw data (no masking bad pixels).weightz--min-frac-valid-pixelszgThe minimal fraction of valid pixels in a sliding diamond. Used to mask bins during boundary detection.gQ?z--min-dist-bad-binzwThe minimal allowed distance to a bad bin. Use to mask bins after insulation calculation and during boundary detection.z--thresholdzRule used to threshold the histogram of boundary strengths to exclude weakboundaries. 'Li' or 'Otsu' use corresponding methods from skimage.thresholding.Providing a float value will filter by a fixed thresholdz--window-pixelsz=If set then the window sizes are provided in units of pixels.)r   is_flagz--append-raw-scoreszXAppend columns with raw scores (sum_counts, sum_balanced, n_pixels) to the output table.z--chunksize i -1z	--verbosezReport real-time progress.z--bigwigzoAlso save insulation tracks as a bigWig files for different window sizes with the names output.<window-size>.bw)r   r   r   c                    t          j        |           t                    }||}nt          |d          }|	rfd|D             }t          j                            ||||r|nd||||
|||          }|r|                    |ddd	           n%t          |                    ddd	                     |r;|D ]:}t          j	        |j
        |d
z   t          |          z   dz   d|            9dS dS )a  
    Calculate the diamond insulation scores and call insulating boundaries.

    IN_PATH : The path to a .cool file with a balanced Hi-C map.

    WINDOW : The window size for the insulation score calculations.
             Multiple space-separated values can be provided.
             By default, the window size must be provided in units of bp.
             When the flag --window-pixels is set, the window sizes must
             be provided in units of pixels instead.
    NT)check_sortingc                 0    g | ]}|j         d          z  S )zbin-size)info).0winclrs     U/var/www/html/software/conda/lib/python3.11/site-packages/cooltools/cli/insulation.py
<listcomp>zinsulation.<locals>.<listcomp>   s%    ???#,,???    )view_df	window_bpignore_diagsclr_weight_namemin_frac_valid_pixelsmin_dist_bad_bin	thresholdappend_raw_scores	chunksizeverbosenproc	Fnan)sepindexna_rep.z.bwlog2_insulation_score_)value_field)coolerCoolerr   r   r   
insulationto_csvprintbioframe	to_bigwig
chromsizesstr)r	   r   outputviewr%   r&   r'   r(   r)   window_pixelsr*   r+   r,   bigwigr-   cooler_view_dfr#   	ins_tablewr   s                      @r    r8   r8      sy   n -
 
 C &c**N|  +4DIII  @???????))!+:D3)+ *  I   ETuEEEE 	i4uUCCDDD   	 	As1vv%-8Q88	     	 	r"   )clickr6   r   r   r   
lib.commonr   lib.ior   r;   commandargumentr>   intoptionPathfloatr8    r"   r    <module>rP      sR                 ) ) ) ) ) ) - - - - - -  	93a@@@H3???
)	   	L	   
Z
 
4	 	 	 
 
 
 
<	   
Z	   
3	   
S	   
? 
   	H  
 
	   m"3tTTTk <dKKK
.  J J  LK UT       
 
   @? A@ tJ J Jr"   