U
    ¦ºeØ
  ã                   @   s   ddd„Z dd„ Zdd„ ZdS )	Tc           
      C   s¶   ddl }ddl}ddl}|j | ¡ ¡}| sH|dddƒ}|j|dgdS |dddƒ}g }| ¡ D ]:\}}||d	d
ƒ}||d	dƒ}	| |t	|ƒt	|	ƒ|f¡ q`|j|ddddgdS dS )a”  Obtain the name and description of known contexts

    Parameters
    ----------
    detail : bool, optional
        If True, obtain additional context detail.

    Returns
    -------
    DataFrame
        Containing context information.

    Redis command summary
    ---------------------
    HGETALL state:contexts
    SCARD <context>:samples-represented
    SCARD <context>:features-represented
    é    NÚstateZHKEYSÚcontextsZContextName)ÚcolumnsZHGETALLZSCARDzsamples-representedzfeatures-representedZSamplesWithDataZFeaturesWithDataÚDescription)
ZpandasÚredbiomÚredbiom._requestsÚ	_requestsZmake_getZ
get_configZ	DataFrameÚitemsÚappendÚint)
ÚdetailÚpdr   Úgetr   ÚresultÚnameÚdescZ
ctx_n_sampZ
ctx_n_feat© r   úp/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2023.9/lib/python3.8/site-packages/redbiom/summarize.pyr      s"    
þr   c                 C   sF   ddl }|j | ¡ ddl}|j ||d| g¡}ddl}|j ||¡S )av  Summarize a metadata category from samples from a set of features

    Parameters
    ----------
    context : str
        A context to search in.
    category : str
        The category to summarize.
    features : Iterable of str
        The features to search for samples with.
    exact : bool
        If true, all samples must contain all specified features. If false,
        all samples contain at least one of the features.

    Returns
    -------
    pandas.Series
        A series indexed by the sample ID and valued by its category value. A
        None is used if the sample does not have that piece of metadata.
    r   NÚfeature)	r   r   ÚvalidZredbiom.utilÚutilZids_fromÚredbiom.fetchÚfetchÚcategory_sample_values)ÚcontextÚcategoryÚfeaturesÚexactr   Úsamplesr   r   r   Úcategory_from_features+   s    r   c                 C   s   ddl }|j | |¡S )a”  Summarize a metadata category from samples

    Parameters
    ----------
    category : str
        The category to summarize.
    samples : Iterable of str
        The samples to search for samples with.

    Returns
    -------
    pandas.Series
        A series indexed by the sample ID and valued by its category value. A
        None is used if the sample does not have that piece of metadata.
    r   N)r   r   r   )r   r   r   r   r   r   Úcategory_from_samplesJ   s    r    N)T)r   r   r    r   r   r   r   Ú<module>   s   
*