# Path: scib/utils.py
# def check_adata(adata):
#     if type(adata) is not anndata.AnnData:
#         raise TypeError('Input is not a valid AnnData object')
# 
# def check_batch(batch, obs, verbose=False):
#     if batch not in obs:
#         raise ValueError(f'column {batch} is not in obs')
#     elif verbose:
#         print(f'Object contains {obs[batch].nunique()} batches.')


import numpy as np
import pandas as pd
import scanpy as sc
from scipy import sparse
from sklearn.linear_model import LinearRegression
from ..utils import check_adata, check_batch
    else:
        return pcr_after - pcr_before


def pcr(
        adata,
        covariate,
        embed=None,
        n_comps=50,
        recompute_pca=True,
        verbose=False
):
    """
    Principal component regression for anndata object

    Checks whether to
        + compute PCA on embedding or expression data (set `embed` to name of embedding matrix e.g. `embed='X_emb'`)
        + use existing PCA (only if PCA entry exists)
        + recompute PCA on expression matrix (default)

    :param adata: Anndata object
    :param covariate: Key for adata.obs column to regress against
    :param embed: Embedding to use for principal components.
        If None, use the full expression matrix (`adata.X`), otherwise use the embedding
        provided in `adata_post.obsm[embed]`.
    :param n_comps: Number of PCs, if PCA is recomputed
    :return:
        R2Var of regression
    """


# Path: scib/utils.py
# def check_adata(adata):
#     if type(adata) is not anndata.AnnData:
#         raise TypeError('Input is not a valid AnnData object')
# 
# def check_batch(batch, obs, verbose=False):
#     if batch not in obs:
#         raise ValueError(f'column {batch} is not in obs')
#     elif verbose:
#         print(f'Object contains {obs[batch].nunique()} batches.')


# Path: scib/metrics/pcr.py
import numpy as np
import pandas as pd
import scanpy as sc
from scipy import sparse
from sklearn.linear_model import LinearRegression
from ..utils import check_adata, check_batch

    else:
        return pcr_after - pcr_before


def pcr(
        adata,
        covariate,
        embed=None,
        n_comps=50,
        recompute_pca=True,
        verbose=False
):
    """
    Principal component regression for anndata object

    Checks whether to
        + compute PCA on embedding or expression data (set `embed` to name of embedding matrix e.g. `embed='X_emb'`)
        + use existing PCA (only if PCA entry exists)
        + recompute PCA on expression matrix (default)

    :param adata: Anndata object
    :param covariate: Key for adata.obs column to regress against
    :param embed: Embedding to use for principal components.
        If None, use the full expression matrix (`adata.X`), otherwise use the embedding
        provided in `adata_post.obsm[embed]`.
    :param n_comps: Number of PCs, if PCA is recomputed
    :return:
        R2Var of regression
    """


    check_adata(adata)