
    DUfe                    *   d dl mZ d dlZ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mZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZ d	d
gZh dZ G d d	          Z d6dZ!	 	 	 d7d8dZ"	 	 	 d7d8dZ#	 	 	 	 d9d:dZ$	 d;d<d$Z%	 	 	 	 	 	 	 	 	 d=d>d5Z&dS )?    )annotationsN)is_integer_dtype)
coo_matrix   )	CSRReaderDirectRangeQuery2DFillLowerRangeQuery2DRangeSelector1DRangeSelector2Dgetregion_to_extentregion_to_offset)list_coolers)closing_hdf5	open_hdf5parse_cooler_uriparse_regionCoolerannotate>   KRVCVC_SQRTc                     e Zd ZdZd9d:dZd;d
Zd<dZd=dZd>d?dZe	d@d            Z
e	dAd            Ze	dBd            Ze	dCd            ZdDdZdEd!Ze	dFd"            Ze	dGd#            ZdHd%ZdHd&ZdIdJd*Z	 	 	 	 	 	 	 	 dKdLd7Zd@d8ZdS )Mr   a]  
    A convenient interface to a cooler data collection.

    Parameters
    ----------
    store : str, :py:class:`h5py.File` or :py:class:`h5py.Group`
        Path to a cooler file, URI string, or open handle to the root HDF5
        group of a cooler data collection.
    root : str, optional [deprecated]
        HDF5 Group path to root of cooler group if ``store`` is a file.
        This option is deprecated. Instead, use a URI string of the form
        :file:`<file_path>::<group_path>`.
    kwargs : optional
        Options to be passed to :py:class:`h5py.File()` upon every access.
        By default, the file is opened with the default driver and mode='r'.

    Notes
    -----
    If ``store`` is a file path, the file will be opened temporarily in
    when performing operations. This allows :py:class:`Cooler` objects to be
    serialized for multiprocess and distributed computations.

    Metadata is accessible as a dictionary through the :py:attr:`info`
    property.

    Table selectors, created using :py:meth:`chroms`, :py:meth:`bins`, and
    :py:meth:`pixels`, perform range queries over table rows,
    returning :py:class:`pd.DataFrame` and :py:class:`pd.Series`.

    A matrix selector, created using :py:meth:`matrix`, performs 2D matrix
    range queries, returning :py:class:`numpy.ndarray` or
    :py:class:`scipy.sparse.coo_matrix`.

    Nstorestr | h5py.Grouproot
str | Nonec                <   t          |t                    r|t          |          \  | _        | _        nat          j        |          r>t          |fi |5 }|j        j        | _        || _        d d d            n# 1 swxY w Y   nt          d          | j        dz   | j        z   | _
        | j        | _        || _        nG|j        j        | _        |j        | _        | j        dz   | j        z   | _
        |j        | _        i | _        |                                  d S )Nz!Not a valid path to a Cooler file::)
isinstancestrr   filenamer   h5pyis_hdf5r   file
ValueErrorurir   open_kwsname_refresh)selfr   r   kwargsh5s        G/var/www/html/software/conda/lib/python3.11/site-packages/cooler/api.py__init__zCooler.__init__D   sE   eS!! 	|+;E+B+B(tyye$$ Fu//// %2$&G$4DM $DI% % % % % % % % % % % % % % % !!DEEE}t+di7DHDJ"DMM "J/DM
DI}t+di7DHDJDMs   A;;A?A?returnNonec                   	 t          | j        fi | j        5 }|| j                 }t	          |          }|d                             t                    |d<   |                    d          d         | _        t          t          |d         t          t          |                                        | _        t          |          | _        | j                            dd          }|dk    | _        d d d            d S # 1 swxY w Y   d S # t$          $ rK d| j         d}t'          | j                  }t          |          r|d| dd	z   z  }t%          |          d w xY w)
Nr)   lengthstorage-modesymmetric-upperzNo cooler found at: .z Coolers found in z. z Use '::' to specify a group path)r   r   r(   r   chromsastypeobject	set_index_chromsizesdictziprangelen	_chromidsinfo_infor   _is_symm_upperKeyErrorr   )r+   r-   grp_ctmodeerr_msglistings          r.   r*   zCooler._refreshZ   s   	.4:7777 @2mSkk!&k0088F#&==#8#8#B !%c#f+uSXX&G&G!H!H!#YY
z~~n6GHH&*.?&?#@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @  	. 	. 	.:TZ:::G"4:..G7|| 444489 7##-	.s0   D CD5D DD 	D
D AE$pathr!   
np.ndarrayc                    t          | j        fi | j        5 }|| j                 }||         d d          cd d d            S # 1 swxY w Y   d S N)r   r   r(   r   r+   rJ   r-   rE   s       r.   
_load_dsetzCooler._load_dseto   s    tz33T]33 	 rTY-Ct9QQQ<	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   AA	Ar<   c                    t          | j        fi | j        5 }|| j                 }t	          ||         j                  cd d d            S # 1 swxY w Y   d S rM   )r   r   r(   r   r<   attrsrN   s       r.   _load_attrszCooler._load_attrst   s    tz33T]33 	)rTY-CD	((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   'AAArrG   
h5py.Groupc                f    t          j        | j        |fi || j                 }t	          |          S )a  Open the HDF5 group containing the Cooler with :py:mod:`h5py`

        Functions as a context manager. Any ``open_kws`` passed during
        construction are ignored.

        Parameters
        ----------
        mode : str, optional [default: 'r']
            * ``'r'`` (readonly)
            * ``'r+'`` or ``'a'`` (read/write)

        Notes
        -----
            For other parameters, see :py:class:`h5py.File`.

        )r#   Filer"   r   r   )r+   rG   r,   rE   s       r.   openzCooler.openy   s4    " it66v66tyAC       c                8    | j                             dd          S )zIndicates whether ordinary sparse matrix encoding is used
        (``"square"``) or whether a symmetric matrix is encoded by storing only
        the upper triangular elements (``"symmetric-upper"``).
        r4   r5   )rB   r   r+   s    r.   storage_modezCooler.storage_mode   s     z~~n.?@@@rX   
int | Nonec                    | j         d         S )z-Resolution in base pairs if uniform else Nonezbin-sizerB   rZ   s    r.   binsizezCooler.binsize   s     z*%%rX   	pd.Seriesc                    | j         S )z=Ordered mapping of reference sequences to their lengths in bp)r;   rZ   s    r.   
chromsizeszCooler.chromsizes   s     rX   	list[str]c                4    t          | j        j                  S )z List of reference sequence names)listr;   indexrZ   s    r.   
chromnameszCooler.chromnames   s     D$*+++rX   regionstr | tuple[str, int, int]intc           	         t          | j        fi | j        5 }|| j                 }t	          || j        t          || j                  | j                  cddd           S # 1 swxY w Y   dS )a'  Bin ID containing the left end of a genomic region

        Parameters
        ----------
        region : str or tuple
            Genomic range

        Returns
        -------
        int

        Examples
        --------
        >>> c.offset('chr3')  # doctest: +SKIP
        1311

        N)	r   r   r(   r   r   r@   r   r;   r_   r+   rh   r-   rE   s       r.   offsetzCooler.offset       $ tz33T]33 	rTY-C#VT%566	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   <A!!A%(A%tuple[int, int]c           	         t          | j        fi | j        5 }|| j                 }t	          || j        t          || j                  | j                  cddd           S # 1 swxY w Y   dS )aG  Bin IDs containing the left and right ends of a genomic region

        Parameters
        ----------
        region : str or tuple
            Genomic range

        Returns
        -------
        2-tuple of ints

        Examples
        --------
        >>> c.extent('chr3')  # doctest: +SKIP
        (1311, 2131)

        N	r   r   r(   r   r   r@   r   r;   r_   rl   s       r.   extentzCooler.extent   rn   ro   c                    t          | j        fi | j        5 }|| j                 }t	          |          cddd           S # 1 swxY w Y   dS )zUFile information and metadata

        Returns
        -------
        dict

        N)r   r   r(   r   rA   )r+   r-   rE   s      r.   rA   zCooler.info   s     tz33T]33 	rTY-C99	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                $    | j         d         fdz  S )Nnbins   r^   rZ   s    r.   shapezCooler.shape   s    
7#%))rX   r
   c                L      fd}t          d|d j        d                   S )z[Chromosome table selector

        Returns
        -------
        Table selector

        c                    t          j        fi j        5 }|j                 }t	          |||| fi cd d d            S # 1 swxY w Y   d S rM   )r   r   r(   r   r7   fieldslohir-   rE   r,   r+   s        r.   _slicezCooler.chroms.<locals>._slice   s    4:7777 =2mc2r6<<V<<= = = = = = = = = = = = = = = = = =   AA
ANnchromsr
   rB   )r+   r,   r   s   `` r.   r7   zCooler.chroms   s?    	= 	= 	= 	= 	= 	=
 tVT4:i3HIIIrX   c                V      fd} fd}t          d|| j        d                   S )zTBin table selector

        Returns
        -------
        Table selector

        c                    t          j        fi j        5 }|j                 }t	          |||| fi cd d d            S # 1 swxY w Y   d S rM   )r   r   r(   r   binsr{   s        r.   r   zCooler.bins.<locals>._slice  s    4:7777 ;2mCR::6::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;r   c           	         t          j        fi j        5 }|j                 }t	          |j        t          | j                  j                  cd d d            S # 1 swxY w Y   d S rM   rr   )rh   r-   rE   r+   s      r.   _fetchzCooler.bins.<locals>._fetch	  s    4:7777 2m'N )9::L	                  s   <A""A&)A&Nrv   r   )r+   r,   r   r   s   ``  r.   r   zCooler.bins   sX    	; 	; 	; 	; 	; 	;
	 	 	 	 	 tVVTZ5HIIIrX   Fjoinboolc                Z      fd} fd}t          d|| j        d                   S )a  Pixel table selector

        Parameters
        ----------
        join : bool, optional
            Whether to expand bin ID columns into chrom, start, and end
            columns. Default is ``False``.

        Returns
        -------
        Table selector

        c                    t          j        fi j        5 }|j                 }t	          |||| fi cd d d            S # 1 swxY w Y   d S rM   )r   r   r(   r   pixels)r|   r}   r~   r-   rE   r   r,   r+   s        r.   r   zCooler.pixels.<locals>._slice$  s    4:7777 C2mc2r64BB6BBC C C C C C C C C C C C C C C C C Cs   AAAc           	     <   t          j        fi j        5 }|j                 }t	          |j        t          | j                  j                  \  }}|d         d         |         }|d         d         |         }||fcd d d            S # 1 swxY w Y   d S )Nindexesbin1_offsetrr   )rh   r-   rE   i0i1r}   r~   r+   s          r.   r   zCooler.pixels.<locals>._fetch)  s    4:7777 
2m)N )9::L	 B ^M226^M2262v
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   A+BBBNnnzr   )r+   r   r,   r   r   s   ```  r.   r   zCooler.pixels  se    	C 	C 	C 	C 	C 	C 	C
	 	 	 	 	 tVVTZ5FGGGrX   T逖 fieldbalance
bool | strsparse	as_pixelsignore_indexdivisive_weightsbool | None	chunksizer   c	                     t           v rd fd}	d fd	}
t          ||	|
 j        d         fdz            S )a  Contact matrix selector

        Parameters
        ----------
        field : str, optional
            Which column of the pixel table to fill the matrix with. By
            default, the 'count' column is used.
        balance : bool, optional
            Whether to apply pre-calculated matrix balancing weights to the
            selection. Default is True and uses a column named 'weight'.
            Alternatively, pass the name of the bin table column containing
            the desired balancing weights. Set to False to return untransformed
            counts.
        sparse: bool, optional
            Return a scipy.sparse.coo_matrix instead of a dense 2D numpy array.
        as_pixels: bool, optional
            Return a DataFrame of the corresponding rows from the pixel table
            instead of a rectangular sparse matrix. False by default.
        join : bool, optional
            If requesting pixels, specifies whether to expand the bin ID
            columns into (chrom, start, end). Has no effect when requesting a
            rectangular matrix. Default is True.
        ignore_index : bool, optional
            If requesting pixels, don't populate the index column with the
            pixel IDs to improve performance. Default is True.
        divisive_weights : bool, optional
            Force balancing weights to be interpreted as divisive (True) or
            multiplicative (False). Weights are always assumed to be
            multiplicative by default unless named KR, VC or SQRT_VC, in which
            case they are assumed to be divisive by default.

        Returns
        -------
        Matrix selector

        Notes
        -----
        If ``as_pixels=True``, only data explicitly stored in the pixel table
        will be returned: if the cooler's storage mode is symmetric-upper,
        lower triangular elements will not be generated. If
        ``as_pixels=False``, those missing non-zero elements will
        automatically be filled in.

        NTc                    t          j        fi j        5 }|j                 }t	          |||||| 
	j                  cd d d            S # 1 swxY w Y   d S rM   )r   r   r(   r   matrixrC   )r   r   r   j0j1r-   rE   r   r   r   r   r   r   r+   r   s          r.   r   zCooler.matrix.<locals>._slicer  s    4:7777 2m $'                  s   .AAAc                d   t          	j        fi 	j        5 }|	j                 }|| }t	          | 	j                  }t	          |	j                  }t          |	j        |	j                  \  }}t          |	j        |	j                  \  }}||||fcd d d            S # 1 swxY w Y   d S rM   )	r   r   r(   r   r   r;   r   r@   r_   )
rh   region2r-   rE   region1r   r   r   r   r+   s
            r.   r   zCooler.matrix.<locals>._fetch  s    4:7777 &2m?$G&vt/?@@&w0@AA)#t~wUUB)#t~wUUB2r2~& & & & & & & & & & & & & & & & & &s   A?B%%B),B)rv   rw   rM   )_4DN_DIVISIVE_WEIGHTSr   rB   )r+   r   r   r   r   r   r   r   r   r   r   s   ` ```````  r.   r   zCooler.matrix8  s    n +++0@0H#	 	 	 	 	 	 	 	 	 	 	 	(		& 		& 		& 		& 		& 		& ufftz'7J6Lq6PQQQrX   c                    t          | j        t                    r1t          j                            | j                  }| d| j         }nt          | j                  }d| dS )Nr   z	<Cooler "z">)r    r   r!   osrJ   basenamer   repr)r+   r"   	containers      r.   __repr__zCooler.__repr__  sd    dj#&& 	)w''
33H#22ty22IITZ((I(9((((rX   rM   )r   r   r   r   )r0   r1   )rJ   r!   r0   rK   )rJ   r!   r0   r<   )rS   )rG   r!   r0   rT   )r0   r!   )r0   r\   )r0   r`   )r0   rc   )rh   ri   r0   rj   )rh   ri   r0   rp   )r0   r<   )r0   rp   )r0   r
   F)r   r   r0   r
   )NTFFFTNr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rj   r0   r   )__name__
__module____qualname____doc__r/   r*   rO   rR   rW   propertyr[   r_   rb   rg   rm   rs   rA   rx   r7   r   r   r   r    rX   r.   r   r       s       ! !F    ,. . . .*       
) ) ) )
! ! ! ! !( A A A XA & & & X&       X  , , , X,   6   6 
 
 
 X
 * * * X*J J J J J J J J4!H !H !H !H !HJ !"!(,!YR YR YR YR YRv) ) ) ) ) )rX   r-   rT   r0   r<   c                    i }| j                                         D ]E\  }}t          |t                    r&	 t	          j        |          }n# t          $ r Y nw xY w|||<   F|S )z
    File and user metadata dict.

    Parameters
    ----------
    h5 : :py:class:`h5py.File` or :py:class:`h5py.Group`
        Open handle to cooler file.

    Returns
    -------
    dict

    )rQ   itemsr    r!   jsonloadsr&   )r-   dkvs       r.   rA   rA     s~     	A    1a 	JqMM   !Hs   A
AAr}   rj   r~   r\   r|   list[str] | Nonepd.DataFramec                    |et          j        ddg                              t          j        | d                                                                                             }t          | d         |||fi |S )a  
    Table describing the chromosomes/scaffolds/contigs used.
    They appear in the same order they occur in the heatmap.

    Parameters
    ----------
    h5 : :py:class:`h5py.File` or :py:class:`h5py.Group`
        Open handle to cooler file.
    lo, hi : int, optional
        Range of rows to select from the table.
    fields : sequence of str, optional
        Subset of columns to select from table.

    Returns
    -------
    :py:class:`DataFrame`

    Nr)   r3   r7   )pdIndexappendkeysdrop_duplicatesr   )r-   r}   r~   r|   r,   s        r.   r7   r7     st    2 ~Hfh'((VBHR\..001122_ 	
 r(|RV66v666rX   c                p   |et          j        g d                              t          j        | d                                                                                             }t          | d         |||fi |}d|v r|                    dd          }t          |t                    r|}n|d         }t          |j	                  rj|rht          | d          }t           j                            ||d	          }t          |t                    rt          j        ||j                  }n||d<   |S )
a  
    Table describing the genomic bins that make up the axes of the heatmap.

    Parameters
    ----------
    h5 : :py:class:`h5py.File` or :py:class:`h5py.Group`
        Open handle to cooler file.
    lo, hi : int, optional
        Range of rows to select from the table.
    fields : sequence of str, optional
        Subset of columns to select from table.

    Returns
    -------
    :py:class:`DataFrame`

    Nchromstartendr   r   convert_enumTr)   )r|   )ordered)r   r   r   r   r   r   r    r!   r   dtyper7   Categorical
from_codesSeriesrf   )	r-   r}   r~   r|   r,   outr   	chrom_colrg   s	            r.   r   r     s2   0 ~H...//VBHRZ__..//00_ 	 bj"b&
3
3F
3
3C &zz.$77fc"" 	%IIGIIO,, 	) 	)6222J11)ZQU1VVI&#&& )i	3955(GJrX   Tr   r   c                X   |et          j        ddg                              t          j        | d                                                                                             }t          | d         |||fi |}|r*t          | d         ddg dfi |}t          ||d	          }|S )
aG  
    Table describing the nonzero upper triangular pixels of the Hi-C contact
    heatmap.

    Parameters
    ----------
    h5 : :py:class:`h5py.File` or :py:class:`h5py.Group`
        Open handle to cooler file.
    lo, hi : int, optional
        Range of rows to select from the table.
    fields : sequence of str, optional
        Subset of columns to select from table.
    join : bool, optional
        Whether or not to expand bin ID columns to their full bin description
        (chrom, start, end). Default is True.

    Returns
    -------
    :py:class:`DataFrame`

    Nbin1_idbin2_idr   r   r   r   Treplace)r   r   r   r   r   r   r   )r-   r}   r~   r|   r   r,   dfr   s           r.   r   r     s    : ~Hi+,,VBHR\..001122_ 	 
R\2r6	4	4V	4	4B .2f:q$(A(A(ALLVLLb$---IrX   Fr   r   pd.DataFrame | RangeSelector1Dr   c                   | j         t          |t                    rd }nd }g }dv r| d                                                             t
          j        dd          }t          |          dk    rdx}}nNt          |          t          |           k    r)|                                |	                                }}nd\  }} ||||          }|
                    |j        ||z
                               d	 
                              d                     dv r| d                                                             t
          j        dd          }	t          |	          dk    rdx}}nNt          |          t          |           k    r)|	                                |		                                }}nd\  }} ||||          }
|
                    |
j        |	|z
                               d 
                              d                     |r%fddD             }|                     |d          } t          j        g ||                     d          d          }| j        |_        |S )a  
    Add bin annotations to a data frame of pixels.

    This is done by performing a relational "join" against the bin IDs of a
    table that describes properties of the genomic bins. New columns will be
    appended on the left of the output data frame.

    .. versionchanged:: 0.8.0
       The default value of ``replace`` changed to False.

    Parameters
    ----------
    pixels : :py:class:`DataFrame`
        A data frame containing columns named ``bin1_id`` and/or ``bin2_id``.
        If columns ``bin1_id`` and ``bin2_id`` are both present in ``pixels``,
        the adjoined columns will be suffixed with '1' and '2' accordingly.
    bins : :py:class:`DataFrame` or DataFrame selector
        Data structure that contains a full description of the genomic bins of
        the contact matrix, where the index corresponds to bin IDs.
    replace : bool, optional
        Remove the original ``bin1_id`` and ``bin2_id`` columns from the
        output. Default is False.

    Returns
    -------
    :py:class:`DataFrame`
    c                $    | |||dz   nd          S )Nr   r   )selbegr   s      r.   
_loc_slicezannotate.<locals>._loc_slicea  s    sS1WWTABBrX   c                     | j         ||         S rM   )loc)r   r   r   s      r.   r   zannotate.<locals>._loc_slicef  s    6#c'?"rX   r   Fsafe)copycastingr   )r   Nc                    | dz   S )N1r   xs    r.   <lambda>zannotate.<locals>.<lambda>{  
    a#g rX   )columnsT)dropr   c                    | dz   S )N2r   r   s    r.   r   zannotate.<locals>.<lambda>  r   rX   c                    g | ]}|v |	S r   r   ).0colr   s     r.   
<listcomp>zannotate.<locals>.<listcomp>  s    PPPrX   )r   r   r   )axis)r   r    r
   to_numpyr8   npint64r?   minmaxr   ilocrenamereset_indexr   r   concatrf   )r   r   r   r   annsbin1bminbmaxann1bin2ann2cols_to_dropr   r   s                @r.   r   r   <  s   @ nG $(( 	#	C 	C 	C 	C
	# 	# 	# D Gi ))++2228%QW2XXt99>>OD44YYV$$TXXZZ$DD JD$z$d++IdTk"V--V..[d[##	
 	
 	
 Gi ))++2228%QW2XXt99>>OD44YYV$$TXXZZ$DD JD$z$d++IdTk"V--V..[d[##	
 	
 	
  3PPPP'=PPP\22 ):d:F..D.99:
C
C
CCCIJrX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
fill_lower&np.ndarray | coo_matrix | pd.DataFramec                J   |d}t          |t                    r|}n|rd}|r#|| d         vrt          d| ddz   dz             t          | d	         | d
         dd                   }|rt	          ||||||f||
           }|                                }|rt          |                                           |g         }t          ||d          }|r(d||dz            z  ||dz   <   d||dz            z  ||dz   <   ||dz            ||dz            z  ||         z  |d<   |	r;t          |                                           g d         }t          ||d          }|S |r|rt          ||||||f|          }nt	          ||||||f|          }|
                                }|rb| d         |         }|||         }||f||fk    r|n	|||         }|r
d|z  }d|z  }||j                 ||j                 z  |j        z  |_        |S |rt          ||||||f|          }nt	          ||||||f|          }|                                }|rR| d         |         }|||         }||f||fk    r|n	|||         }|r
d|z  }d|z  }|t          j        ||          z  }|S )a  
    Two-dimensional range query on the Hi-C contact heatmap.
    Depending on the options, returns either a 2D NumPy array, a rectangular
    sparse ``coo_matrix``, or a data frame of pixels.

    Parameters
    ----------
    h5 : :py:class:`h5py.File` or :py:class:`h5py.Group`
        Open handle to cooler file.
    i0, i1 : int, optional
        Bin range along the 0th (row) axis of the heatmap.
    j0, j1 : int, optional
        Bin range along the 1st (col) axis of the heatmap.
    field : str, optional
        Which column of the pixel table to fill the matrix with. By default,
        the 'count' column is used.
    balance : bool, optional
        Whether to apply pre-calculated matrix balancing weights to the
        selection. Default is True and uses a column named 'weight'.
        Alternatively, pass the name of the bin table column containing the
        desired balancing weights. Set to False to return untransformed counts.
    sparse: bool, optional
        Return a scipy.sparse.coo_matrix instead of a dense 2D numpy array.
    as_pixels: bool, optional
        Return a DataFrame of the corresponding rows from the pixel table
        instead of a rectangular sparse matrix. False by default.
    join : bool, optional
        If requesting pixels, specifies whether to expand the bin ID columns
        into (chrom, start, end). Has no effect when requesting a rectangular
        matrix. Default is True.
    ignore_index : bool, optional
        If requesting pixels, don't populate the index column with the pixel
        IDs to improve performance. Default is True.

    Returns
    -------
    ndarray, coo_matrix or DataFrame

    Notes
    -----
    If ``as_pixels=True``, only data explicitly stored in the pixel table
    will be returned: if the cooler's storage mode is symmetric-upper,
    lower triangular elements will not be generated. If ``as_pixels=False``,
    those missing non-zero elements will automatically be filled in.

    Ncountweightr   zNo column 'bins/'z(found. Use ``cooler.balance_cooler`` to z1calculate balancing weights or set balance=False.r   zindexes/bin1_offset)return_indexFr   r   r   r   balancedr   T)r    r!   r&   r   r   to_framer   r   r   r	   to_sparse_matrixrowr   datato_arrayr   outer)r-   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   readerenginer   weightsdf2r   matbias1bias2arrs                            r.   r   r     st   | }'3 	  
4r&z))&t&&&89AB
 
 	
 r(|R(=%>qqq%ABBF 8 $EBB+YEU
 
 
 __ 	LRjjoo''/G2w666C 6"#c$*o"5D3J"#c$*o"5D3J _s4#:>UKBzN 	2"::??$$%>%>%>?D"dD111B		 " 	T*652r2r:JIVVFF'BB7GSSF%%'' 	Bj&GBrENE "X"b11EEwr"u~E "E	E	SW~cg6ACH
  	T*652r2r:JIVVFF'BB7GSSFoo 	/j&GBrENE "X"b11EEwr"u~E "E	E	...C
rX   )r-   rT   r0   r<   )r   NN)
r-   rT   r}   rj   r~   r\   r|   r   r0   r   )r   NNT)r-   rT   r}   rj   r~   r\   r|   r   r   r   r0   r   r   )r   r   r   r   r   r   r0   r   )	NTFFTTFr   T)r-   rT   r   rj   r   rj   r   rj   r   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rj   r   r   r0   r  )'
__future__r   r   r#   numpyr   pandasr   
simplejsonr   pandas.api.typesr   scipy.sparser   corer   r   r	   r
   r   r   r   r   fileopsr   utilr   r   r   r   __all__r   r   rA   r7   r   r   r   r   r   rX   r.   <module>r      sG   " " " " " " 				              - - - - - - # # # # # #	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 " ! ! ! ! ! I I I I I I I I I I I IZ
  0// y) y) y) y) y) y) y) y)x   6 #	7 7 7 7 7H #	5 5 5 5 5t #* * * * *` [ [ [ [ [H "G G G G G G GrX   