
    DUf                        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
mZ d dlZd dlmZ ddlmZ dd	lmZmZ d dlZ ej                     ej        d
de           ej        dde           ej        dddde           ej        dded eed                     ej        ddedd           ej        ddd ej        g d d!"                     ej        d#d$ed%d           ej        d&d'd(d)           ej        d*d+d, ej        d,d-gd!"          d.           ej        d/d0dd!1           ej        d2d3d4de           ej        d5d6edd           ej        d7d8d9 ej        g d:d!"          d.           ej        d;d<d=dd!1          d>                                                                                                                                                                                     ZdS )?    N   )api)make_cooler_view)read_viewframe_from_fileread_expected_from_file)partial   )cli)sniff_for_headervalidate_csv	cool_path	COOL_PATH)metavartypefeaturesFEATURES_PATHz--viewz	--regionszPath to a BED file which defines which regions of the chromosomes to use.  Required if EXPECTED_PATH is provided Note that '--regions' is the deprecated name of the option. Use '--view' instead. )helpdefaultr   z
--expectedzgPath to the expected table. If provided, outputs OOE pileup.  if not provided, outputs regular pileup. zbalanced.avg)default_column)r   r   r   callbackz--flankzSize of flanks.i T)r   r   r   show_defaultz--features-formatzInput features format.auto)r   BEDBEDPEF)case_sensitivez--clr-weight-namez$Use balancing weight with this name.weightz-oz--outz$Save output pileup as NPZ/HDF5 file.)r   requiredz--out-formatzType of output.NPZHDF5)r   r   r   r   z--store-snipsz0Flag indicating whether snips should be stored. )r   is_flagr   z-pz--nproczQNumber of processes to split the work between. [default: 1, i.e. no process pool]z--ignore-diagszjThe number of diagonals to ignore. By default, equals the number of diagonals ignored during IC balancing.z--aggregatez+Function for calculating aggregate signal. none)r!   meanmedianstdminmaxz-vz	--verbosezEnable verbose outputc                 f   t          j        |           }t          |          }t          |          \  }}|                                dk    rg d}g d}t
          t          j        t          j        t
          t          j        t          j        d}|t          d|||          }nt          |          dk     rt          d          t          d||	          }n|                                d
k    rrg d}g d}t
          t          j        t          j        d}|t          d|||          }nDt          |          dk     rt          d          t          d||	          }nt          d          t          j        |fd|d|}||}nt          ||d          }|d}n|\  }}|g}t          |d|||          }t           j                            |||||||||
	  	        }|                                }||dk    s|dk    rt          j        }n_|dk    rt          j        }nL|dk    rt          j        }n9|dk    rt          j        }n&|dk    rt          j        }nt          d| d           ||d !          }|                                d"k    r3|	rt          j        |||#           dS t          j        ||$           dS |                                d%k    rGt3          j        |d&          }|                    d'|(           |	r|                    d)|(           dS dS dS )*a  
    Perform retrieval of the snippets from .cool file.

    COOL_PATH : The paths to a .cool file with a balanced Hi-C map. Use the
    '::' syntax to specify a group path in a multicooler file.

    FEATURES_PATH : the path to a BED or BEDPE-like file that contains features for snipping windows.
    If BED, then the features are on-diagonal. If BEDPE, then the features
    can be off-diagonal (but not in trans or between different regions in the view).

    bedpe)r   r	   r            )chrom1start1end1chrom2start2end2N)headerusecolsdtypenames   zToo few columns for BEDPEinfer)r2   r3   r4   bed)r   r	   r   )chromstartend)r2   r3   r5   r4   r)   zToo few columns for BEDzoAutomatic detection of features format is not implemented yet. Please provide BED or BEDPE as --features-format#)commentverboseT)check_sortingcis)contact_typeexpected_value_colsverify_viewverify_cooler)view_dfexpected_dfexpected_value_colflankmin_diagclr_weight_namenprocr"   r!   r#   r%   r&   r$   zAggregation mode z3 not supported. Please use mean/median/min/max/std.r   )axisnpz)pileupstack)rN   hdf5wrN   )datarO   )coolerCoolerr   r   lowerstrnpint64dictlen
ValueErrorNotImplementedErrorpd
read_tabler   r   r   snippingrN   nanmean	nanmediannanminnanmaxnanstdsavezh5pyFilecreate_dataset) r   r   viewexpectedrH   features_formatrJ   out
out_formatstore_snipsrK   ignore_diags	aggregater>   clrcooler_view_dfbufr5   default_cols
bedpe_colsdtypeskwargsbed_colsfeatures_dfrE   rG   expected_pathrB   rO   agg_funcrN   h5s                                    Q/var/www/html/software/conda/lib/python3.11/site-packages/cooltools/cli/pileup.pyrN   rN      s   f -	
"
"C%c**N "(++JC')))))MMM
hHhH
 
 =$ 	  FF 5zzA~~ !<===*FKKKFF				 	 E	)	) yy,,,"(CC=\  FF 5zzA~~ !:;;;(&IIIFF "?
 
 	

 -LS'LLVLLK |  +4DIII !,4))
 + 3
 
 
 L-'   
 
E !!II//93F3F:	h		<	e		9	e		9	e		9^	^^^
 
 	
 Xe!$$$F U"" 	)HSu555555HS((((((					v	%	%YsC  
(000 	3gE22222	 
&	%	3 	3    )pandasr]   numpyrW   rS    r   
lib.commonr   lib.ior   r   click	functoolsr   r
   utilr   r   rf   commandargumentrV   optionintChoicerN    r~   r}   <module>r      s                  ) ) ) ) ) ) F F F F F F F F              0 0 0 0 0 0 0 0  [s;;;
O#>>>
Z 	   
1	W\.AAA   		   	!	...u	E	E	E	   	/	   	/	   		ufoe	<	<	<   	;	   
*	   
<	   	6	777
 
 
    +3T5  Z3 Z3             ?> <; nZ3 Z3 Z3r~   