o
    Nrf
                     @   s   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 ejd	d
dejdddedddejdddddedejdddeedddejddeddejddddd ejd!d"dd#d$d%d&d' ZdS )(    N   )lock)coarsen_cooler)parse_cooler_uri   )cliparse_field_paramcool_uriZ	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defaultZ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   Z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.)Zis_flagr   r   c                 C   s   t | \}}t |\}	}t|t|	k}
t|r>dd |D }t| \}}}}dd t||D }dd t||D }n	dgdd}}}t| ||||||||
rTtnd|rYdnd	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                 S   s   g | ]}t |d dqS )F)Zincludes_colnumr   ).0arg r   [/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/cooler/cli/coarsen.py
<listcomp>I   s    zcoarsen.<locals>.<listcomp>c                 S      i | ]\}}|d ur||qS Nr   )r   coldtr   r   r   
<dictcomp>M       zcoarsen.<locals>.<dictcomp>c                 S   r   r   r   )r   r   fr   r   r   r   N   r   countNaw)	chunksizenproccolumnsdtypesaggr   mode)r   oprealpathlenzipr   r   )r
   factorr    r   fieldoutappendinfile_outfileZ	same_fileZfield_specifiersr!   r"   r#   r   r   r   coarsen   s.   8


r0   )Zos.pathpathr%   ZclickZparallelr   reducer   utilr    r   Z_utilr	   commandargumentoptionintstrr0   r   r   r   r   <module>   s`    			