
    DUf
                        d dl m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mZ  ej                     ej        d	d
           ej        dddedd           ej        ddddde           ej        ddde ed          d           ej        dded           ej        dddd            ej        d!d"dd#d$%          d&                                                                                                 ZdS )'    N   )lock)coarsen_cooler)parse_cooler_uri   )cliparse_field_paramcool_uri	COOL_PATH)metavarz--factorz-kzyGridding factor. The contact matrix is coarsegrained by grouping each chromosomal contact block into k-by-k element tilesT)helptypedefaultshow_defaultz--nprocz-nz-pzcNumber of processes to use for batch processing chunks of pixels [default: 1, i.e. no process pool])r   r   r   z--chunksizez-cz*Number of pixels allocated to each processg    cAz--fieldzSpecify the names of value columns to merge as '<name>'. Repeat the `--field` option for each one. Use '<name>,dtype=<dtype>' to specify the dtype. Include ',agg=<agg>' to specify an aggregation function different from 'sum'.)r   r   multiplez--outz-ozOutput file or URI)requiredr   z--appendz-aFz_Pass this flag to append the output cooler to an existing file instead of overwriting the file.)is_flagr   r   c                    t          |           \  }}t          |          \  }	}t          j        |          t          j        |	          k    }
t          |          rOd |D             }t	          | \  }}}}d t	          ||          D             }d t	          ||          D             }ndgdd}}}t          | ||||||||
rt          nd|rdnd
  
         dS )	z
    Coarsen a cooler to a lower resolution.

    Works by pooling *k*-by-*k* neighborhoods of pixels and aggregating.
    Each chromosomal block is coarsened individually.

    COOL_PATH : Path to a COOL file or Cooler URI.

    c                 0    g | ]}t          |d           S )F)includes_colnumr	   ).0args     O/var/www/html/software/conda/lib/python3.11/site-packages/cooler/cli/coarsen.py
<listcomp>zcoarsen.<locals>.<listcomp>I   s3     
 
 
>Ac5999
 
 
    c                     i | ]
\  }}|||S N )r   coldts      r   
<dictcomp>zcoarsen.<locals>.<dictcomp>M   s    PPPgc2#rr   c                     i | ]
\  }}|||S r   r   )r   r    fs      r   r"   zcoarsen.<locals>.<dictcomp>N   s    GGG&#qsAr   countNaw)	chunksizenproccolumnsdtypesaggr   mode)r   oprealpathlenzipr   r   )r   factorr)   r(   fieldoutappendinfile_outfile	same_filefield_specifiersr*   r+   r,   s                  r   coarsenr;      s&   p !**IFA!#&&JGQF##r{7';';;I
5zz 
5
 
EJ
 
 
 #&'7"8FCPPWf)=)=PPPGGC$5$5GGG !(y$(TTD#SS     r   )os.pathpathr.   clickparallelr   reducer   utilr    r   _utilr
   commandargumentoptionintstrr;   r   r   r   <module>rI      s                # # # # # # # # # # # #       $ $ $ $ $ $ 
K000
?	   
)	   	5	CII   
L 
   gtd1EFFF
'  % %  GF     10 \% % %r   