
    DUf                     N   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	 d dl
Z
ddlmZmZ ddlmZ  ej                     e
j        dd	e
           e
j        dd edd          d           e
j        dddde           e
j        ddedd           e
j        ddedd           e
j        ddddd            e
j        d!d"d#d$           e
j        d%d&dd           d'                                                                                                             ZdS )(    N   )	eigdecomp)make_cooler_view   )TabularFilePathsniff_for_header)cli	cool_path	COOL_PATH)metavartypez--phasing-trackziPhasing track for orienting and ranking eigenvectors,provided as /path/to/track::track_value_column_name.T   )existsdefault_column_index
TRACK_PATH)helpr   r   z--viewz	--regionszPath to a BED file which defines which regions of the chromosomes to use (only implemented for cis contacts).  Note that '--regions' is the deprecated name of the option. Use '--view' instead. )r   defaultr   z--n-eigsz"Number of eigenvectors to compute.)r   r   r   show_defaultz--clr-weight-namez\Use balancing weight with this name. Using raw unbalanced data is not supported for saddles.weightz-vz	--verbosezEnable verbose outputF)r   is_flagr   z-oz--out-prefixzSave compartment track as a BED-like file. Eigenvectors and corresponding eigenvalues are stored in out_prefix.contact_type.vecs.tsv and out_prefix.contact_type.lam.txt)r   requiredz--bigwigzZAlso save compartment track (E1) as a bigWig file with the name out_prefix.contact_type.bwc                 `   t          j        |           }t          |          }	|s|\  }
}t          |
          \  }}|Yt	          |t
                    s't          j        d                    |                    d}t          dddd|gddd	|g
          }nt	          |t
                    rS	 ||         }n# t          $ r< t          j        d                    |d                    |                              w xY w||vr;t          j        d                    |d                    |                              |}t          dddd	|g          }t          j        |fdt          dt          j        d	t          j        |t          j        id|d|}|}||	}nt%          d          t'          j        ||||dd          \  }}|                    |dz   dz   dd           |                    |dz   dz   dd           |r%t-          j        ||j        |dz   dz   d           dS dS )a  
    Perform eigen value decomposition on a cooler matrix to calculate
    compartment signal by finding the eigenvector that correlates best with the
    phasing track.


    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.

    TRACK_PATH : the path to a BedGraph-like file that stores phasing track as
    track-name named column.

    BedGraph-like format assumes tab-separated columns chrom, start, stop and
    track-name.

    Nz:No header found. Cannot find "{}" column without a header.refr   r   r   chromstartend)headerusecolsnamesz+Column #{} not compatible with header "{}".,z$Column "{}" not found in header "{}"infer)r   r   #)dtypecommentverbosez6views are not currently implemented for CLI eigs-trans)clrphasing_trackn_eigsclr_weight_name	partitionsort_metricz.transz.lam.txt	F)sepindexz	.vecs.tsvz.bwE1)value_field)coolerCoolerr   r   
isinstanceintclickBadParameterformatdict
IndexErrorjoinpd
read_tablestrnpint64float64NotImplementedErrorr   
eigs_transto_csvbioframe	to_bigwig
chromsizes)r
   r'   viewr(   r)   r%   
out_prefixbigwigr&   cooler_view_df
track_pathcolbufr   
track_namekwargstrack_dfview_dfeigvalseigvec_tables                       U/var/www/html/software/conda/lib/python3.11/site-packages/cooltools/cli/eigs_trans.pyrB   rB      s   X -	
"
"C%c**N  (
C%j11
U=c3'' (@@Fs  
 JAq#
;  FF #s## *CC!   ,ELL%    e##,>EE%    J7GUJ2WXXXF=
 rxBJ	 
 
 
 
 ! | !D
 
 	
 &0#'  G\ NN:(:54uNMMM
X-;USSS 
N!E)		
 	
 	
 	
 	
 	

 
s   /B8 8AC>)pandasr;   numpyr>   r1   rD   apir   
lib.commonr   r5   utilr   r    r	   commandargumentr=   optionr4   rB        rT   <module>r`      s=                   ) ) ) ) ) )  3 3 3 3 3 3 3 3       [s;;;
;	1	=	=	=   
Z 	   	-	   	g	   +3T5   
L    
0  r
 r
        <; dr
 r
 r
r_   