o
    Nrf                     @   sJ  d dl Z d dlZd dlZd dlZd dlm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
mZ d dl
mZ d dl
mZ d dl
mZ d dlmZ d d	lmZ e  e jd
dde jddddede jdddde jdddde jdddde jdddde jdddde jdddde jd dd!dd"d# ZdS )$    N)fill_filetype_and_datatype)get_port)get_data_dir)get_temp_dir)md5)datatype_to_tracktype)_start)_ingestfilename   )nargsz-nz	--hg-namedefaultz"The name for this higlass instance)r   helptypez
--filetypez(The type of file to ingest (e.g. cooler))r   r   z
--datatypez0The data type of in the input file (e.g. matrix)z--tracktypez%The track type used to view this filez
--positionz,The position in the view to place this trackz--public-data/--no-public-dataTz@Include or exclude public data in the list of available tilesetsz
--assemblyz(The assembly that this data is mapped toz--chromsizes-filenamez8A set of chromosome sizes to use for bed and bedpe filesc	           !      C   s  zt |}	td|	 W n ty   t|d Y nw t|}
d}t| ||\}}|du s0|du r>td||dtjd dS zcd}t	j
d|
|d	d
}t|j}|d D ]I}tt| d }t|d }|d d}|d |td d }t|}t||}||dkrt|}t| }||kr|d } nqVW n t	jjy   tdtjd Y dS w |du rt| |||||d}|du rdS ddlm}m}m} |du r|}|du r|du rt|\}}|du rtd| dS |||||d|
ddg}||g}| }g |d< |d  d|
g7  < |r&|d  dg7  < t	j d|
d|id}|j!dkrBtd|j"|j dS t|jd } t#j$
ds]t%&dj|
| d  dS dS )!aZ  
    View a file in higlass.

    The user can specify an instance to view it in. If one is
    not specified the default will be used. If the default isn't
    running, it will be started.

    Parameters:
    -----------
    hg_name: string
        The name of the higlass instance
    filename: string
        The name of the file to view
    z	temp_dir:)hg_nameNz-Couldn't infer filetype or datatype ({}, {}),z2please specify them using the command line options)filei z-http://localhost:{}/api/v1/tilesets/?limit={}
   )timeoutresultsr   Zdatafilez
/tilesets/uuidz)Error getting a list of existing tilesets)assemblychromsizes_filename)TrackViewViewConfz1ERROR: Unknown track type for the given datatype:zhttp://localhost:{}/api/v1/   )Z
track_typepositionZtileset_uuidserverheightZtrackSourceServerszhttp://higlass.io/api/v1/z%http://localhost:{}/api/v1/viewconfs/viewconf)jsonzError posting viewconf:uidZHAS_JOSH_K_SEAL_OF_APPROVALz)http://localhost:{port}/app/?config={uid})portr!   )'r   print	Exceptionr   r   r   formatsysstderrrequestsgetr    loadscontentopsplitextntpathbasenamefindlenr   joinr   
exceptionsConnectionErrorr	   Zhiglass.clientr   r   r   r   to_dictpoststatus_codestatusosenviron
webbrowseropen)!r
   r   filetypedatatypeZ	tracktyper   Zpublic_datar   r   temp_dirr"   r   Zinferred_datatypeZMAX_TILESETSreqZtilesetsZtilesetZimport_filenameZtileset_filenameZsubpath_indexsubpathdata_dirZtileset_pathZ	checksum1Z	checksum2r   r   r   viewr   confresr!    rF   \/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/higlass_manage/view.pyrC      s   9	
	

rC   )Zclickr    r.   r9   Zos.pathpathr,   r(   r&   r;   Zhiglass_manage.commonr   r   r   r   r   r   Zhiglass_manage.startr   Zhiglass_manage.ingestr	   commandargumentoptionstrrC   rF   rF   rF   rG   <module>   sb     