
    DUf                         d dl Z d dlZd dlmZ d dlZd dlmZ d dlm	Z	 d dl
Z
d dlZd dlZd dlZddlmZ  G d de
j        j                  Zdd
ZddZd Zd Zed             Zd ZdS )    N)contextmanagerwraps   )utilc                   6    e Zd ZdefdZed             Zd ZdS )DelimitedTuple,c                 \    || _         t          j                            |          | _        d S N)sepclicktypesconvert_typetype)selfr   r   s      M/var/www/html/software/conda/lib/python3.11/site-packages/cooler/cli/_util.py__init__zDelimitedTuple.__init__   s$    K,,T22			    c                     d| j          dS )Nz
separated[])r   )r   s    r   namezDelimitedTuple.name   s    'DH''''r   c                      ||S t          |t                    r|                    d          }n|}t           fd|D                       S )Nr
   c              3   F   K   | ]}                     |          V  d S r   )r   ).0xctxparamr   s     r   	<genexpr>z)DelimitedTuple.convert.<locals>.<genexpr>#   s3      ==!TYYq%--======r   )
isinstancestrsplittuple)r   valuer   r   partss   ` `` r   convertzDelimitedTuple.convert   sd     =Ls## 	KK$$EEE======u======r   N)__name__
__module____qualname__r!   r   propertyr   r&    r   r   r	   r	      sW        S 3 3 3 3 ( ( X(
> 
> 
> 
> 
>r   r	   r
   =c                    ddl m} dd l}|dk    r|                     |d          } d|                     |d          z   dz   } 	 |                     ||                     }n*# |j        $ r}t          j        d|            |d }~ww xY w|S )Nr   )StringIOr
   {z: }zError parsing key-value pairs: )ior.   yamlreplace	safe_load	YAMLErrorr   BadParameter)argitem_sepkv_sepr.   r2   resultes          r   parse_kv_list_paramr<   &   s    KKK3kk(C((
FD))
)C
/CQ..> Q Q Q !H3!H!HIIqPQMs   A# #
B
-BB
Tc                    |                      d          }|d         }t          |          dk    rd }n0t          |          dk    r	|d         }nt          j        |           |r|                     d          }|d         }t          |          dk    rd }nt          |          dk    rj	 t	          |d                   dz
  }n3# t
          $ r&}t          j        d|d          d|           |d }~ww xY w|dk     rt          j        d	|           nt          j        |           |d         }d }d }	d }
||                     d
          D ]}	 |                     d          \  }}n'# t
          $ r}t          j        |           |d }~ww xY w|dk    rt          j        |          }	^|dk    r|r|}
it          j        d| d|           |||	|
fS )N:r      r   r,   zNot a number: '')
param_hintzField numbers start at 1.r
   dtypeaggzInvalid property: 'z'.)r"   lenr   r6   int
ValueErrornprB   )r7   includes_colnumincludes_aggr%   prefixpropsr   colnumr;   rB   rC   itempropr$   s                 r   parse_field_paramrO   5   s-   IIcNNE1XF
5zzQ	Uqa %%% S!!Qxu::??FFZZ1__U1X*   (1eAh111c   zz()DQTUUUU  $S)))QxE
CKK$$ 
	Y 
	YD5"jjooee 5 5 5(--145w<()Gt)G)G)GTWXXXX##s0   -C 
C6!C11C6E++
F5F

Fc                    t          j        |           d         }d|v r|                     dd          \  }}t          j        |          st	          d| d          	 t          |          }n&# t          $ r}t	          d| d          |d }~ww xY wt          j        |d	          }t          j        ||          }nt          j        |           r	 t          j
        | d
g dg ddt          i          }n2# t          j        j        $ r}t	          d|  d|          |d }~ww xY w|                    dgd          ddg                             d                              ddd          }t#          |d                   t#          |d                   }	}t          j        ||	          }nt	          d          ||fS )Nr?   r>   )maxsplitzFile "z" not foundz-Expected integer binsize argument (bp), got ""T)	all_names	)chromstartend)r   r?   r   rU   )r   namesusecolsrB   zFailed to parse bins file "z": last)keeprW   )dropr   length)rU   rW   )columns)indexdataz\Expected BINS to be either <Path to bins file> or <Path to chromsizes file>:<binsize in bp>.)op
splitdriversplitexistsrF   rE   r   read_chromsizesbinnifypdread_csvr!   parserCParserErrordrop_duplicatesreset_indexrenamelistSeries)
r7   arg_nodrivechromsizes_filebinsizer;   
chromsizesbins
chromtablechromslengthss
             r   
parse_binsrx   d   s.   -$$Q'K
k#&::cA:#>#> y)) 	DBoBBBCCC	'llGG 	 	 	JJJJ 	 )/TJJJ
|J00 
3 
		Q;///!		n  DD y% 	Q 	Q 	QH3HH1HHIIqP	Q   ' 88'59IJ[d[##VfX>>V?? 	
 z&122DH9M4N4NYV':::

 9
 
 	

 ts0   !A1 1
B;BB$C> >D-D((D-c                     t          |           } | dk    rt          j        d          t          | t	          j                              S )Nr   zn_cpus must be >= 1)rE   r   r6   minmp	cpu_count)	arg_values    r   check_ncpusr~      s>    IIA~~ !67779blnn---r   c              #      K   	 d V  d S # t           $ r-}|j        t          j        k    r | |           n Y d }~d S d }~ww xY wr   )OSErrorerrnoEPIPE)handlerr;   s     r   on_broken_piper      si         7ek!!GAJJJJ  JJJJJs   
 
A"<Ac                       fd}|S )a  
    Decorator to catch a broken pipe (EPIPE) error and exit cleanly.

    Use this decorator to prevent the "[Errno 32] Broken pipe" output message.

    Notes
    -----
    A SIGPIPE signal is sent to a process writing to a pipe while the other
    end has been closed. For example, this happens when piping output to
    programs like head(1). Python traps this signal and translates it into an
    exception. It is presented as an IOError in PY2, and a subclass of OSError
    in PY3 (aliased by IOError), both using POSIX error number 32 (EPIPE).

    Some programs exit with 128 + signal.SIGPIPE == 141. However, according to
    the example in the docs, Python exits with the generic error code of 1
    on EPIPE.

    The equivalent system error when trying to write on a socket which has
    been shutdown for writing is ESHUTDOWN (108). It also raises
    BrokenPipeError on PY3.

    [1] https://docs.python.org/3.7/library/signal.html#note-on-sigpipe
    [2] https://www.quora.com/How-can-you-avoid-a-broken-pipe-error-on-Python

    c                 @     t                      fd            }|S )Nc                  T   	  | i | d S # t           $ r}|j        t          j        k    rot          j        t          j        t          j                  }t          j        |t          j	        
                                           t          j                   n Y d }~d S d }~ww xY wr   )r   r   r   osopendevnullO_WRONLYdup2sysstdoutfilenoexit)argskwargsr;   r   	exit_codefuncs       r   	decoratedz9exit_on_broken_pipe.<locals>.decorator.<locals>.decorated   s    d%f%%%%% 
 
 
7ek)) !gbj"+>>GGGSZ%6%6%8%8999HY''''  ('''''
s    
B'BB""B'r   )r   r   r   s   ` r   	decoratorz&exit_on_broken_pipe.<locals>.decorator   s:    	t	 	 	 	 	 
	 r   r+   )r   r   s   ` r   exit_on_broken_piper      s$    6    & r   )r
   r,   )TT)r   r   os.pathpathra   r   
contextlibr   	functoolsr   r   multiprocessr{   numpyrG   pandasrg    r   r   	ParamTyper	   r<   rO   rx   r~   r   r   r+   r   r   <module>r      s@    				       



 % % % % % %                         > > > > >U[* > > >,   ,$ ,$ ,$ ,$^+ + +\. . .   . . . . .r   