
    (tf%                        d dl Z d dlmc m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
mZ d dlmZ  e j                           e j"                  d       e j$                  ddd	
       e j$                  ddd
       e j$                  ddd
       e j$                  ddd
       e j$                  ddd
       e j$                  ddd
       e j$                  dddd       e j$                  ddd
       e j$                  dddd       e j$                  ddd
      	 	 	 	 	 	 	 	 	 d#d                                                                                     Z	 	 	 	 	 	 	 	 	 d#d!Zd" Zy)$    N)fill_filetype_and_datatype)import_file)get_temp_dir)_startfilenamez	--hg-namedefaultz8The name of the higlass container to import this file to)r   helpz
--filetypez(The type of file to ingest (e.g. cooler)z
--datatypez0The data type of in the input file (e.g. matrix)z
--assemblyz(The assembly that this data is mapped toz--namezThe name to use for this filez--uidzThe uuid to use for this filez--no-uploadTzYDo not copy the file to the media directory. File must already be in the media directory.)r   is_flagr	   z--chromsizes-filenamez8A set of chromosome sizes to use for bed and bedpe filesz--has-headerFzYDoes the input file have column header information (only relevant for bed or bedpe files)z--project-namez;Group this tileset with others by specifying a project namec                 .    t        | |||||||||	|
       y)z
    Ingest a dataset
    N)_ingest)r   hg_namefiletypedatatypeassemblynamechromsizes_filename
has_headeruid	no_uploadproject_names              _/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/higlass_manage/ingest.pyingestr      s.    p     c                 |   	 t        |       |	sGt	        j
                  |       s2t	        j                  |       st        d| t        j                         y t        | ||      \  }}t        |      }t        | |||||	|      \  }}t        ||||||||	|
	      S # t        $ r t        d       t        |       Y w xY w)Nz HiGlass not running. Starting...)r   zFile not found:file)r   	Exceptionprintr   opexistsislinksysstderrr   aggregate_filer   )r   r   r   r   r   r   r   r   r   r   r   temp_dir	to_imports                r   r   r   T   s     W
 bii1"))H:M

; 6h(SXxG$H*Y 
 
-   01w s   B  B;:B;c                    |dk(  r|rt        dt        j                        ||t        dt        j                         y t	        j
                  |t        j                  |       dz         }t        d       t        j                  | ||d|d dd |d	d
       |}d}||fS |dk(  r|rt        dt        j                        ||t        dt        j                         y t	        j
                  || dz         }t        dj                  |             t        j                  | ||d|d d|d
	       |}d}||fS | |fS )NbedfilezcBedfile files need to be aggregated and cannot be linked. Consider not using the --link-file optionr   zAn assembly or set of chromosome sizes is required when importing bed files. Please specify one or the other using the --assembly or --chromsizes-filename parametersz.beddbzAggregating bedfilerandom2   r   i   )importance_columnr   
chromosomemax_per_tile	delimiterr   offset	tile_sizebeddbbedpezaBedpe files need to be aggregated and cannot be linked. Consider not using the --link-file optionz.bed2ddbz"Aggregating bedpe (output_file: {})r+   r   r,   r-   r   r0   bed2ddb)r   r"   r#   r   r   joinntpathbasenamecca_bedfileformat_bedpe)	r   r   r   r   r   r   tmp_diroutput_filer&   s	            r   r$   r$      sy    9uZZ 
  3 ; xZZ gggvx'@8'KL#$&! 3	
  	 8$$	W	sZZ   3 ; xZZ gggx*'<=299+FG

&! 3
	
  	 8$$(##r   )	NNNNNFNNN)clickclodius.cli.aggregatecli	aggregater7   r5   os.pathpathr   r"   higlass_manage.commonr   r   r   higlass_manage.startr   commandargumentoptionr   r   r$    r   r   <module>rI      s    # #   
 < - . ' 
	C
 $%O $%W $%O h+JKgt*IJ	d	 	C
 	d	 	F 	 K L  PD 	0fI$r   