
    tf
                        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y)'    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        |      rl|D cg c]  }t	        |d       }}t        | \  }}}}t        ||      D ci c]  \  }}|	|| }}}t        ||      D ci c]  \  }}|	|| }}}ndgdd}}}t        | ||||||||
rt        nd|rd
       yd
       yc c}w c c}}w c c}}w )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.

    F)includes_colnumNcountaw)	chunksizenproccolumnsdtypesaggr   mode)r   oprealpathlenr	   zipr   r   )r
   factorr   r   fieldoutappendinfile_outfile	same_fileargfield_specifiersr   r   r   coldtfs                      \/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/cooler/cli/coarsen.pycoarsenr1      s   p !*IFA!#&JGQF#r{{7';;I
5zEJ
>Ac59
 
 #&'7"8FC),Wf)=Pgc2#r'PP$'$5G&#qsAvGG !(y$TDS !$
 QGs   C.	
C3C3+
C96C9)os.pathpathr   clickparallelr   reducer   utilr    r   _utilr	   commandargumentoptionintstrr1        r0   <module>rA      s.      # #  $ 
K0
?	 
)	 	5	I 
L 
 gtd1EF
'% G 1 \%r@   