
    tf                     (    d dl Z d Zd ZddZddZy)    Nc                 T   t        j                  |       }|j                         }|j                  d      j	                         }t        t        |j                         }d|vrd}nt        ||j                  d               }d|vrd}n||j                  d         }|d   |d   |d   |d   |d	   |d
   dg|d   g||t        t        |d   j                  d      |d   j                  d      D cg c]  }t        |       c}            dd}|j                          |S c c}w )NzSELECT * from tileset_infoversion   header r                  	   2)	zoom_step
max_lengthassembly	tile_sizemax_zoom	max_widthmin_posmax_posr   r   
chromsizesinfo_version)sqlite3connectcursorexecutefetchonenextzipdescriptionintindexlistsplitclose)	db_fileconnr   rowcolnamesr   r   csts_infos	            ]/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/clodius/tiles/beddb.pytileset_infor.      s*   ??7#D[[]F
..5
6
?
?
ACC++,-H c(..345xX^^H-. V!fFVFV3F8AT"s1v||D7I$JSW$JK
 G  	JJLN %Ks   3D%"c                    g }|D ]  }|j                  d      d   }|j                  d      }t        |d         }t        |d         }d}i }	g }	t        d|z        D ]"  }
d|z  |z  |
z   }t        | ||z   |      }|	|z  }	$ |||	fgz  } |S )a;  
    Generate tiles from this dataset.

    Parameters
    ----------
    filepath: str
        The filename of the sqlite db file
    tile_ids: [str...]
        A list of tile ids of the form

    Returns
    -------
    tiles: [(tile_id, tile_value),...]
        A list of values indexed by the tile position
    |r   .r   r   )r%   r"   rangeget_1D_tiles)filepathtile_ids	to_returntile_idtile_no_optionspartszoomxpos
extra_zoomnew_rowsjhigher_xposold_rowss                r-   tilesrA   +   s      I +!--,Q/%%c*58}58}
qJ' 	!A z/D014K#HdZ.?MH H	! 	w)**	)+,     c           
         t        |       }|d   }t        j                  |       }|j                         }|d   d|z  z  }||z  }	|	||z  z   }
dj	                  ||	|
      }|dk(  rdj	                  ||	|
      }|dk(  rdj	                  ||	|
      }|j                  |      j                         }g }|D ]  }	 |d   j                  d	      }|d
   }|d   }t        |||z         D ]U  }||z  }|dz   |z  }||k  s||k\  s|d
   |d   |d   |d   ||d   j                  d      d}|dk(  r|d   |d<   ||gz  }W  |j                          |S # t        $ r |d   }Y w xY w)a  
    Retrieve a contiguous set of tiles from a db tile file.

    Parameters
    ----------
    db_file: str
        The filename of the sqlite db file
    zoom: int
        The zoom level
    tile_x_pos: int
        The position of the first tile
    num_tiles: int
        The number of tiles to retrieve

    Returns
    -------
    tiles: {pos: tile_value}
        A set of tiles, indexed by position
    r   r   r   
    SELECT startPos, endPos, chrOffset, importance, fields, uid
    FROM intervals,position_index
    WHERE
        intervals.id=position_index.id AND
        zoomLevel <= {} AND
        rEndPos >= {} AND
        rStartPos <= {}
    3  
        SELECT startPos, endPos, chrOffset, importance, fields, uid
        FROM intervals,position_index
        WHERE
            intervals.id=position_index.id AND
            rStartZoomLevel <= {} AND
            rEndZoomLevel >= 0 AND
            rEndPos >= {} AND
            rStartPos <= {}
        r   9  
        SELECT startPos, endPos, chrOffset, importance, fields, uid, name
        FROM intervals,position_index
        WHERE
            intervals.id=position_index.id AND
            rStartZoomLevel <= {} AND
            rEndZoomLevel >= 0 AND
            rEndPos >= {} AND
            rStartPos <= {}
        r	   utf-8r   r   r   r   xStartxEnd	chrOffset
importanceuidfieldsr
   name)r.   r   r   r   formatr   fetchalldecodeAttributeErrorr2   r%   r&   )r'   r:   
tile_x_pos	num_tilesr,   r   r(   c
tile_widthtile_start_postile_end_posqueryrowsr=   rrM   x_startx_enditile_x_start
tile_x_endto_adds                         r-   r3   r3   V   s   ( 7#Gi G??7#DA%T	1J*,N!I
$::L 	nl	 
 !|	 F.,
 	 !|	 F.,
 	 99U$$&D H %	A$++g&C A$!z:	#9: 	%Az>La%:-J#(=daD!"1"#A$djj. a<%&qTF6NVH$#	%%6 	JJLO5  	A$C	s   8EE"!E"c           	      \   t        |       }|d   }t        j                  |       }|j                         }d}dj	                  |||      }	|dk(  rdj	                  |||      }	|dk(  rdj	                  |||      }	||	dj	                  |      z  }	|j                  |	      j                         }
g }|
D ]Q  }	 |d	   j                  d
      }|d   |d   |d   |d   ||d   j                  d      d}|dk(  r|d   |d<   ||gz  }S |j                          |S # t        $ r |d	   }Y ^w xY w)aP  
    List the entries between start and end

    Parameters
    ----------
    db_file: str
        The filename of the sqlite db file
    start_pos: int
        The start position from where to retrieve data
    end_pos: int
        The end position to get data
    max_entries: int
        The maximum number of results to return
    r   i rD   r   rE   r   rF   z	 LIMIT {}r	   rG   r   r   r   r   rH   r
   rO   )r.   r   r   r   rP   r   rQ   rR   rS   r%   r&   )r'   startendmax_entriesr,   r   r(   rV   r:   rZ   r[   r=   r\   rM   rb   s                  r-   
list_itemsrg      s    7#Gi G??7#DA D 	eS	 
 !|	 F%
 	 !|	 F%
 	 ##K0099U$$&DH 	A$++g&C
 daD1A$djj&
 a<qTF6NVH%& 	JJLO%  	A$C	s   8DD+*D+)r   )N)r   r.   rA   r3   rg    rB   r-   <module>ri      s!    $N(Vl^\rB   