
    DUf                      8   d dl Z d dlZd dlZd dlZddlmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ d	 Z ej                     ej        d
d           ej        ddd ej        g d          dd           ej        ddd ed                     ej        dddddd           ej        dd d!"           ej        d#d$d%d&           ej        d'd(d)e           ej        d*d+ed,-           ej        d.d/d0ddd           ej        d1d2d3ddd           ej        d4d5ddd           ej        d6d7 ed                     ej        d8d9dd:           ej        d;d<dd:           ej        d=d>d?ed@d           ej        dAdBdCD          dE                                                                                                                                                                                                             ZdS )F    N   )api)	CSRReaderDirectRangeQuery2DFillLowerRangeQuery2Dregion_to_extent)parse_region   )cli)DelimitedTuplec                 &      fd}|S )Nc                 b   ut                    }	 	|         }n=# t          $ r0}t          d|            t          j        d           Y d }~nd }~ww xY wt          j        | ddg         |d          }r9t          j        | 	dg                   }|d         |d	         z  | d
         z  | d<   
rt          j        | 	g d         d          } t          j        | |gd          } rdD ]}|| j	        v r| |xx         dz  cc<   rdD ]}|| j	        v r| |xx         dz  cc<   | S )NzColumn not found:
 r
   bin1_idbin2_idT)replaceweightweight1weight2countbalanced)chromstartend)axis)r   r   )start1start2)
listKeyErrorprintsysexitr   annotatepdconcatcolumns)chunkextra_fields
extra_colseextradfcolr"   r   binsjoinone_based_idsone_based_startss          L/var/www/html/software/conda/lib/python3.11/site-packages/cooler/cli/dump.py	annotatorz!make_annotator.<locals>.annotator   s   >>L!,/

   0Q00111 Ly),-z4  E  	OeT8*%566B "99 =g NE* 	WL-F-F-F(GQUVVVEIuen1555E 	$- $ $%-''#JJJ!OJJJ 	$+ $ $%-''#JJJ!OJJJs    
A&AA )r-   r   r.   r"   r/   r0   r2   s   `````` r1   make_annotatorr4      sC                       D     cool_uri	COOL_PATH)metavarz--tablez-tzWhich table to dump. Choosing 'chroms' or 'bins' will cause all pixel-related options to be ignored. Note that for coolers stored in symmetric-upper mode, 'pixels' only holds the upper triangle values of the matrix.)chromsr-   pixelsr:   T)helptypedefaultshow_defaultz	--columnsz-czKRestrict output to a subset of columns, provided as a comma-separated list.,)sep)r;   r<   z--headerz-Hz2Print the header of column names as the first row.F)r;   is_flagr=   r>   z--na-repz1Missing data representation. Default is empty ''. )r;   r=   z--float-formatz@Format string for floating point numbers (e.g. '.12g', '03.2f').g)r;   r=   r>   z--rangez-rzThe coordinates of a genomic region shown along the row dimension, in UCSC-style notation. (Example: chr1:10,000,000-11,000,000). If omitted, the entire contact matrix is printed.z--range2z-r2zThe coordinates of a genomic region shown along the column dimension. If omitted, the column range is the same as the row range.)r<   r;   z--fill-lowerz-fzFor coolers using 'symmetric-upper' storage, populate implicit areas of the genomic query box by generating lower triangle pixels. If not specified, only upper triangle pixels are reported. This option has no effect on coolers stored in 'square' mode.z--balanced/--no-balancez-bzRApply balancing weights to data. This will print an extra column called `balanced`z--joinzPrint the full chromosome bin coordinates instead of bin IDs. This will replace the `bin1_id` column with `chrom1`, `start1`, and `end1`, and the `bin2_id` column with `chrom2`, `start2` and `end2`.z
--annotatezJoin additional columns from the bin table against the pixels. Provide a comma separated list of column names (no spaces). The merged columns will be suffixed by '1' and '2' accordingly.z--one-based-idsz2Print bin IDs as one-based rather than zero-based.)r;   rA   r=   z--one-based-startsz<Print start coordinates as one-based rather than zero-based.z--chunksizez-kzSets the number of pixel records loaded from disk at one time. Can affect the performance of joins on high resolution datasets. i@B z--outz-ozsOutput text file If .gz extension is detected, file is written using zlib. Default behavior is to stream to stdout.)r;   c           
        ! t          j        |           }||dk    rt          j        }n;|                    d          rt          j        |d          }nt          |d          }|dk    r8|                                }||t          |                   }|dd         f}n|dk    r8|	                                }||t          |                   }|dd         f}n|	                                dd         }t          |          }|t          |          }|	r8d|j        vr/t          d	t          j        
           t          j        d           |                    d          }t          |d         |d         dd                   }d!|rtt!          ||j        t%          ||j                  |j                  \  }}|4t!          ||j        t%          ||j                  |j                  \  }}n||}}||||f}nd|d|f}|r|j        dk    rt-          |!||          }nt/          |!||          }!fd|D             }|	s|
s|r$t1          ||	|
|||          }t3          ||          }|d|z   }d}|D ]H} |r(|r$| dd                             |dddd||           d}|                     |dddd||           I|                                 dS )zc
    Dump a cooler's data to a text stream.

    COOL_PATH : Path to COOL file or cooler URI.

    N-z.gzwtwr9   r-   r   zBalancing weights not found)filer
   rr:   zindexes/bin1_offsetr   )binsizer   zsymmetric-upperc              3   J   K   | ]}t          j        |d dg          V  dS )r   r   )r%   N)r#   	DataFrame).0dctfields     r1   	<genexpr>zdump.<locals>.<genexpr>  sW       
 

 	 L"Iu5  
 
 
 
 
 
r5   %T	
F)r@   lineterminatorindexheaderfloat_formatna_rep)r   Coolerr    stdoutendswithgzipopenr9   r   r-   lenr%   r   stderrr!   r   r   	_chromidsr	   
chromsizesrJ   storage_moder   r   r4   mapto_csvflush)"r6   tabler%   rV   rX   rW   rangerange2
fill_lowerr   r.   r"   r/   r0   	chunksizeoutclrfselectorchunksr-   n_binsh5readeri0i1j0j1bboxenginer2   is_first_chunkr&   rO   s"                                    @r1   dumprz   9   s   V *X

C {cSjjJ	e		 Ic4  cNN ::<<W.H111+	&88::W.H111+ xxzz!!!}TD		I 	44/cjAAAAHQKKKXXc]]2h<,A)B111)EFF 	*%UCN33	  FB !)M 88K	  BB RBB#DD vq&)D 	H#*.???*65$	JJFF'tYGGF
 
 
 

 
 
 
  	,t 	,x 	,&hh?O I F++F\)N   	# 	ac
!!#'!-! "    #N% 	 	
 	
 	
 	
 	
					r5   )r\   r    clickpandasr#   rB   r   corer   r   r   r   utilr	   r   _utilr   r4   commandargumentoptionChoicestrintrz   r3   r5   r1   <module>r      s(    



                                    ! ! ! ! ! !# # #L 
K000
 
222	3	3
 
 
 
	C	 	 	    	=   HRT   	K	   
8 
   		
A	   
1 
 
 
 
   
K    
F 
C	 	 	    	=	   	G	   
H	   
;  D D       
 
      
 
 10 fD D Dr5   