
    DUf                     L   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  ej	                     e j
        dded	           e j
        d
ded	           e j        dddde           e j        ddde           e j        ddde           e j        ddde           e j        dde ed          d           e j        ddd e j        ddgd                     d!                                                                                                             ZdS )"    N   )api   )cli)sniff_for_headerin_pathIN_PATH)metavartypenargsout_pathOUT_PATHz--viewzPath to a BED-like file which defines which regions of the chromosomes to use and in what order. Using --new-chrom-col and --orientation-col you can specify the new chromosome names and whether to invert each region (optional)T)helpdefaultrequiredr   z--new-chrom-colzColumn name in the view with new chromosome names. If not provided and there is no column named 'new_chrom' in the view file, uses original chromosome names)r   r   r   z--orientation-colzColumns name in the view with orientations of each region (+ or -). If not providedand there is no column named 'strand' in the view file, assumes all are forward orientedz
--assemblyz^The name of the assembly for the new cooler. If None, uses the same as in the original cooler.z--chunksizezBThe number of pixels loaded and processed per step of computation.g    cA)r   r   r   show_defaultz--modez3(w)rite or (a)ppend to the output file (default: w)waF)case_sensitivec           
          t          j        |           }g d}	t          |          \  }
}|t          j        |
dd          }nt          j        |
|	d          }|j        }|d}n||j        vrt          d| d	          |d
}n||j        vrt          d| d	          ||                             |d                   ||<   ||                             d          ||<   t          j
                            ||||||||           dS )a5  Rearrange data from a cooler according to a new genomic view

    Parameters
    ----------
    IN_PATH : str
        .cool file (or URI) with data to rearrange.
    OUT_PATH : str
        .cool file (or URI) to save the rearrange data.
    view : str
        Path to a BED-like file which defines which regions of the chromosomes to use
        and in what order. Has to be a valid viewframe (columns corresponding to region
        coordinates followed by the region name), with potential additional columns.
        Using --new-chrom-col and --orientation-col you can specify the new chromosome
        names and whether to invert each region (optional).
        If has no header with column names, assumes the `new-chrom-col` is the fifth
        column and `--orientation-col` is the sixth, if they exist.
    new_chrom_col : str
        Column name in the view with new chromosome names.
        If not provided and there is no column named 'new_chrom' in the view file, uses
        original chromosome names.
    orientation_col : str
        Columns name in the view with orientations of each region (+ or -). - means the
        region will be inverted.
        If not providedand there is no column named 'strand' in the view file, assumes
        all are forward oriented.
    assembly : str
        The name of the assembly for the new cooler. If None, uses the same as in the
        original cooler.
    chunksize : int
        The number of pixels loaded and processed per step of computation.
    mode : str
        (w)rite or (a)ppend to the output file (default: w)
    )chromstartendname	new_chromstrandNr   	)headersep)namesr   r   zNew chrom col z not found in view columnsr   zOrientation col r   +)new_chrom_colorientation_colassembly	chunksizemode)coolerCoolerr   pd
read_tableread_csvcolumns
ValueErrorfillnar   	rearrangerearrange_cooler)r   r   viewr"   r#   r$   r%   r&   clrdefault_namesbufr    view_dfs                T/var/www/html/software/conda/lib/python3.11/site-packages/cooltools/cli/rearrange.pyr/   r/   
   sY   h -
 
 CLLLM!$''JC-A4888 +cDAAA #	go	-	-S-SSSTTT"		/	/WOWWWXXX
 %]3::77;KLLGM&7>>sCCGOM""#' # 	 	 	 	 	    )clickr'   pandasr)    r   r   utilr   commandargumentstroptionintChoicer/    r7   r6   <module>rC      s                     " " " " " " 	93a@@@
JSBBB
I 	   
! 	   
  	   
	   	M	CHH   	>	sCj	7	7	7	  H H       CB A@ `H H Hr7   