### Install kBET R Package Source: https://github.com/theislab/scib/blob/main/docs/source/installation.rst Installs the kBET R package, which is a dependency for certain functionalities within the scib ecosystem. This requires R to be installed. ```R install.packages('remotes') remotes::install_github('theislab/kBET') ``` -------------------------------- ### Install scib Python Package from GitHub via Pip Source: https://github.com/theislab/scib/blob/main/docs/source/installation.rst Installs the scib Python package directly from its GitHub repository. This is useful for installing the latest development version. ```bash pip install git+https://github.com/theislab/scib.git ``` -------------------------------- ### Install scib Package Source: https://context7.com/theislab/scib/llms.txt Installs the scib package using pip. Optional dependencies like 'rpy2' and 'bbknn' can be included by specifying them in brackets. ```bash pip install scib # With optional dependencies pip install 'scib[rpy2,bbknn]' ``` -------------------------------- ### Install Optional Python Dependencies for Integration Methods Source: https://github.com/theislab/scib/blob/main/docs/source/installation.rst Installs optional Python dependencies for specific integration methods. These are not installed by default due to potential dependency conflicts. Users can install dependencies for methods like BBKNN and Scanorama individually or together. ```bash pip install scib[bbknn] # using BBKNN ``` ```bash pip install scib[scanorama] # using Scanorama ``` ```bash pip install scib[bbknn,scanorama] # Multiple methods in one go ``` -------------------------------- ### Install scib Python Package via Pip Source: https://github.com/theislab/scib/blob/main/docs/source/installation.rst Installs the scib Python package from the Python Package Index (PyPI). This is the standard method for installing the core package. ```bash pip install scib ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/theislab/scib/blob/main/README.md Installs the pre-commit framework to automatically run checks before each git commit. This helps maintain code quality and consistency by enforcing development standards. ```shell pre-commit install ``` -------------------------------- ### Install Optional Python Dependencies with Zsh Shell Source: https://github.com/theislab/scib/blob/main/docs/source/installation.rst Installs optional Python dependencies for integration methods when using the Zsh shell. Zsh requires quotation marks around commands containing square brackets to avoid syntax errors. ```bash pip install 'scib[bbknn]' ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/theislab/scib/blob/main/README.md Installs the necessary dependencies for developing the scib package, including tools for testing and pre-commit hooks. This command uses pip to install the package in editable mode with the 'test' and 'dev' extras. ```shell pip install -e '.[test,dev]' ``` -------------------------------- ### Install scib with Optional R Dependencies Source: https://github.com/theislab/scib/blob/main/README.md Installs the scib package along with optional dependencies required for R integration, such as 'rpy2' and 'bbknn'. This enables the use of R-based integration methods within the scib workflow. ```commandline pip install 'scib[rpy2,bbknn]' ``` -------------------------------- ### Compute k-nearest neighbor Batch Effect Test (kBET) Source: https://context7.com/theislab/scib/llms.txt Performs the k-nearest neighbor Batch Effect Test (kBET) to assess local batch mixing. Higher kBET scores suggest better mixing of cells from different batches in local neighborhoods, indicating successful batch correction. This metric requires the R package 'kBET' to be installed. ```python import scib kbet_score = scib.me.kBET( adata, batch_key="batch", label_key="celltype", type_="embed", embed="X_emb", scaled=True ) # Returns: 0.72 (higher means better batch mixing) # Note: Requires R package 'kBET' to be installed ``` -------------------------------- ### Compute Optimal Clustering Resolution - Python Source: https://github.com/theislab/scib/blob/main/docs/source/user_guide.rst Computes the optimal clustering resolution for a given AnnData object, using specified cluster and label keys. This is often a prerequisite for graph-based metrics. ```python scib.me.cluster_optimal_resolution(adata, cluster_key="cluster", label_key="celltype") ``` -------------------------------- ### Reduce Data for Feature Space - Python Source: https://github.com/theislab/scib/blob/main/docs/source/user_guide.rst A wrapper function to perform initial data reduction steps for feature space representation, including highly variable gene selection and PCA. It can optionally compute the kNN graph. ```python scib.pp.reduce_data( adata, n_top_genes=2000, batch_key="batch", pca=True, neighbors=False ) ``` -------------------------------- ### Compute kNN Graph - Python Source: https://github.com/theislab/scib/blob/main/docs/source/user_guide.rst Computes the kNN graph for an AnnData object, typically using an embedding stored in adata.obsm. This is a common preprocessing step for graph-based metrics. ```python sc.pp.neighbors(adata, use_rep="X_emb") ``` -------------------------------- ### Complete Integration and Benchmarking Workflow (Python) Source: https://context7.com/theislab/scib/llms.txt Demonstrates a full workflow for single-cell data integration and benchmarking using scib and scanpy. This includes loading data, preprocessing, running an integration method (Scanorama), post-integration processing, benchmarking with all metrics, and displaying the results. ```python import scib import scanpy as sc # 1. Load data adata = sc.read_h5ad("multi_batch_data.h5ad") # 2. Preprocessing scib.pp.reduce_data( adata, batch_key="batch", n_top_genes=2000, pca=True, neighbors=False ) # Keep unintegrated copy for comparison adata_unintegrated = adata.copy() # 3. Run integration adata_integrated = scib.ig.scanorama(adata.copy(), batch="batch") # 4. Post-integration processing sc.pp.neighbors(adata_integrated, use_rep="X_emb") sc.tl.umap(adata_integrated) # 5. Benchmark with all metrics results = scib.me.metrics_all( adata_unintegrated, adata_integrated, batch_key="batch", label_key="celltype", embed="X_emb", organism="human", n_cores=4 ) # 6. Display results print(results.T) # 0 # NMI_cluster/label 0.847 # ARI_cluster/label 0.782 # ASW_label 0.723 # ASW_label/batch 0.891 # PCR_batch 0.765 # cell_cycle_conservation 0.934 # isolated_label_F1 0.651 # isolated_label_silhouette 0.582 # graph_conn 0.943 # kBET 0.724 # iLISI 0.856 # cLISI 0.921 # hvg_overlap 0.412 # trajectory 0.814 ``` -------------------------------- ### scANVI Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Utilizes scANVI, a semi-supervised integration method based on scVI, which can leverage cell type labels for improved batch correction. Requires count data in the 'counts' layer. ```python import scib adata.layers["counts"] = adata.X.copy() adata_integrated = scib.ig.scanvi( adata, batch="batch", labels="celltype", # Cell type annotations hvg=None, max_epochs=None # Auto-determined ) ``` -------------------------------- ### Compute All Available Metrics (Python) Source: https://context7.com/theislab/scib/llms.txt Computes all available metrics, including LISI and kBET, for a comprehensive assessment of data integration. This function requires unintegrated and integrated AnnData objects, batch and label keys, and the embedding key. Optional parameters include organism and number of cores for parallel processing. ```python import scib results = scib.me.metrics_all( adata_unintegrated, adata_integrated, batch_key="batch", label_key="celltype", embed="X_emb", organism="human", n_cores=4 ) print(results) # Returns DataFrame with all 14 metrics ``` -------------------------------- ### BBKNN Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Implements BBKNN (Batch Balanced K-Nearest Neighbors) for batch correction. This method focuses on identifying and correcting for batch effects by balancing nearest neighbors across batches. It primarily returns a kNN graph. ```python import scib adata_integrated = scib.ig.bbknn( adata, batch="batch", hvg=None, neighbors_within_batch=3 # For large datasets ) # Returns kNN graph output (no corrected features) ``` -------------------------------- ### Compute Principal Component Regression (PCR) Comparison Source: https://context7.com/theislab/scib/llms.txt Compares the variance explained by batch effects in the principal components before and after integration using Principal Component Regression (PCR). A higher PCR score indicates that more batch effect has been removed. ```python import scib pcr_score = scib.me.pcr_comparison( adata_unintegrated, adata_integrated, covariate="batch", embed="X_emb", # Use embedding, or None for full features scale=True ) # Returns: 0.76 (higher means more batch effect removed) ``` -------------------------------- ### ComBat Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Applies ComBat, a method for adjusting data for known sources of variation (like batch effects), using scanpy's implementation. This function modifies the expression matrix `adata.X` in-place. ```python import scib adata_integrated = scib.ig.combat(adata, batch="batch") # Corrected expression in adata_integrated.X ``` -------------------------------- ### Run Integration Method (Python) Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst General function to run an integration method on an AnnData object. Requires the AnnData object and the name of the batch column. Some methods may require additional parameters like cell type labels. ```python scib.ig.integration_method(adata, batch="batch") ``` ```python scib.ig.scanorama(adata, batch="batch") ``` ```python scib.ig.scgen(adata, batch="batch", cell_type="cell_type") scib.ig.scanvi(adata, batch="batch", labels="cell_type") ``` -------------------------------- ### Run Metrics (Python) Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst Wrapper function to compute multiple scib metrics on integrated and unintegrated AnnData objects. Allows specifying which metrics to compute. Returns results in a pandas DataFrame. ```python scib.metrics.metrics(adata, adata_int, ari=True, nmi=True) ``` -------------------------------- ### Select Custom Metrics for Computation (Python) Source: https://context7.com/theislab/scib/llms.txt Allows fine-grained control over which specific metrics to compute during the evaluation of data integration. Users can enable or disable individual biological conservation and batch correction metrics by setting boolean flags. This function also accepts parameters for organism, cluster key, number of cores, and verbosity. ```python import scib results = scib.me.metrics( adata_unintegrated, adata_integrated, batch_key="batch", label_key="celltype", embed="X_emb", # Biological conservation ari_=True, nmi_=True, silhouette_=True, cell_cycle_=True, hvg_score_=True, isolated_labels_f1_=True, isolated_labels_asw_=True, trajectory_=False, clisi_=True, # Batch correction pcr_=True, graph_conn_=True, kBET_=False, ilisi_=True, # Options organism="human", cluster_key="cluster", n_cores=4, verbose=True ) ``` -------------------------------- ### Run scGen for Batch Correction Source: https://context7.com/theislab/scib/llms.txt Integrates single-cell data using scGen for batch correction, leveraging cell type information. Requires an AnnData object and specifies batch and cell type keys. ```python import scib adata_integrated = scib.ig.scgen( adata, batch="batch", cell_type="celltype", epochs=100, hvg=None ) ``` -------------------------------- ### Compute Integration Local Inverse Simpson's Index (iLISI) Source: https://context7.com/theislab/scib/llms.txt Calculates the integration Local Inverse Simpson's Index (iLISI) to measure local batch diversity. Higher iLISI values indicate better mixing of cells from different batches within local neighborhoods, suggesting successful batch correction. ```python import scib ilisi_score = scib.me.ilisi_graph( adata, batch_key="batch", type_="embed", # Options: full, embed, knn use_rep="X_emb", scale=True, n_cores=4 ) # Returns: 0.85 (scaled 0-1, higher is better) ``` -------------------------------- ### Import scib in Python Source: https://github.com/theislab/scib/blob/main/README.md Imports the scib package into a Python script or environment. This allows access to the package's modules and functions for data integration and analysis. ```python import scib ``` -------------------------------- ### Metrics API Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst Comprehensive suite of metrics for benchmarking scRNA-seq data integration performance, categorized into biological conservation and batch removal metrics. ```APIDOC ## Metrics API ### Description Provides a comprehensive set of metrics for evaluating the performance of scRNA-seq data integration. Metrics are classified into biological conservation and batch removal categories. Scores are typically scaled between 0 and 1, with higher values indicating better performance. ### Biological Conservation Metrics Quantify the integrity of biological information after integration. #### Available Functions: - `scib.metrics.ari` (Adjusted Rand Index) - `scib.metrics.cell_cycle` - `scib.metrics.clisi_graph` - `scib.metrics.hvg_overlap` - `scib.metrics.isolated_labels_asw` - `scib.metrics.isolated_labels_f1` - `scib.metrics.nmi` (Normalized Mutual Information) - `scib.metrics.silhouette` - `scib.metrics.trajectory_conservation` ### Batch Correction Metrics Evaluate the effectiveness of batch effect removal. #### Available Functions: - `scib.metrics.graph_connectivity` - `scib.metrics.ilisi_graph` - `scib.metrics.kBET` (k-Bet) - `scib.metrics.pcr_comparison` - `scib.metrics.silhouette_batch` ### Metrics Wrapper Functions Convenience functions to apply multiple metrics simultaneously. #### `scib.metrics.metrics` Applies a specified subset of metrics. ##### Usage Example: ```python scib.metrics.metrics(adata, adata_int, ari=True, nmi=True) ``` #### `scib.metrics.metrics_fast` Applies a preconfigured subset of metrics that require minimal preprocessing. #### `scib.metrics.metrics_slow` Applies a preconfigured subset of metrics that may require more extensive preprocessing. ### Publication For a detailed description of the metrics, please refer to the publication: https://doi.org/10.1038/s41592-021-01336-8 ``` -------------------------------- ### Batch-aware Scaling (Python) Source: https://context7.com/theislab/scib/llms.txt Scales the count matrix of an AnnData object such that each batch has a mean of 0 and a standard deviation of 1. This is performed independently for each specified batch. ```python import scib # Scale each batch independently adata_scaled = scib.pp.scale_batch(adata, batch="batch") ``` -------------------------------- ### Compute Cell-type Local Inverse Simpson's Index (cLISI) Source: https://context7.com/theislab/scib/llms.txt Calculates the cell-type Local Inverse Simpson's Index (cLISI) to quantify local cell type diversity. Lower cLISI values suggest better preservation of the original cell type structure within local neighborhoods. This function can use different representations of the data. ```python import scib clisi_score = scib.me.clisi_graph( adata, label_key="celltype", type_="embed", # Options: full, embed, knn use_rep="X_emb", scale=True, n_cores=4 ) # Returns: 0.92 (scaled 0-1, higher is better) ``` -------------------------------- ### Scanorama Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Performs batch correction using Scanorama, which leverages mutual nearest neighbors to align datasets. The corrected embedding is stored in `adata.obsm['X_emb']` and the corrected expression matrix in `adata.X`. ```python import scib adata_integrated = scib.ig.scanorama( adata, batch="batch", hvg=None ) # Corrected embedding in adata_integrated.obsm['X_emb'] # Corrected expression in adata_integrated.X ``` -------------------------------- ### Harmony Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Applies Harmony, a method for batch correction that aims to preserve biological variation while removing technical artifacts from different batches. The corrected embedding is stored in `adata.obsm['X_emb']`. ```python import scib # Run Harmony integration adata_integrated = scib.ig.harmony( adata, batch="batch", hvg=None # Use all genes, or pass list of HVGs ) # Results in adata_integrated.obsm['X_emb'] ``` -------------------------------- ### scVI Integration (Python) Source: https://context7.com/theislab/scib/llms.txt Applies scVI, a deep generative model for single-cell data integration. This method requires raw count data, which should be stored in the 'counts' layer of the AnnData object. The latent representation is saved in `adata.obsm['X_emb']`. ```python import scib # Ensure counts are in layers adata.layers["counts"] = adata.X.copy() adata_integrated = scib.ig.scvi( adata, batch="batch", hvg=None, max_epochs=400 ) # Latent representation in adata_integrated.obsm['X_emb'] ``` -------------------------------- ### Compute Fast Metrics for Rapid Assessment (Python) Source: https://context7.com/theislab/scib/llms.txt Calculates a subset of fast metrics for quick evaluation of data integration. It requires unintegrated and integrated AnnData objects, along with keys for batch and cell type labels, and the embedding key. The output is a DataFrame containing metrics like hvg_overlap, ASW_label, and graph_conn. ```python import scib import scanpy as sc # Prepare integrated data sc.pp.neighbors(adata_integrated, use_rep="X_emb") # Run fast metrics results = scib.me.metrics_fast( adata_unintegrated, adata_integrated, batch_key="batch", label_key="celltype", embed="X_emb" ) print(results) # Returns DataFrame with: # - hvg_overlap # - ASW_label # - isolated_label_silhouette # - graph_conn # - ASW_label/batch # - PCR_batch ``` -------------------------------- ### Integration API Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst Functions for integrating scRNA-seq datasets using various methods. Requires a preprocessed AnnData object and batch information. ```APIDOC ## Integration API ### Description Functions for performing data integration on scRNA-seq datasets. These methods require a preprocessed AnnData object and the name of the batch column. ### Usage ```python scib.ig.integration_method(adata, batch="batch") ``` ### Example: Scanorama ```python scib.ig.scanorama(adata, batch="batch") ``` ### Methods Requiring Cell Type Labels Some integration methods, such as scgen and scanvi, also utilize cell type labels. ```python scib.ig.scgen(adata, batch="batch", cell_type="cell_type") scib.ig.scanvi(adata, batch="batch", labels="cell_type") ``` ### Deprecated Notation ```python # Deprecated scib.integration.runIntegrationMethod(adata, batch="batch") ``` ### Available Integration Methods (via `scib.integration` module): (Note: The following are examples and the actual available methods might vary. Refer to `automodapi` output for a complete list.) - `scib.integration.scgen` - `scib.integration.scanvi` - `scib.integration.scanorama` - `scib.integration.runBBKNN` (Deprecated, use snake_case) - `scib.integration.runCombat` (Deprecated, use snake_case) - `scib.integration.runMNN` (Deprecated, use snake_case) - `scib.integration.runDESC` (Deprecated, use snake_case) - `scib.integration.runSaucie` (Deprecated, use snake_case) - `scib.integration.runScvi` (Deprecated, use snake_case) - `scib.integration.runTrVae` (Deprecated, use snake_case) - `scib.integration.runTrVaep` (Deprecated, use snake_case) - `scib.integration.issparse` (Utility function) ``` -------------------------------- ### Data Reduction Pipeline (Python) Source: https://context7.com/theislab/scib/llms.txt A streamlined function to perform feature selection, PCA, and neighbor graph computation. It modifies the AnnData object in-place, adding annotations for HVGs, PCA embeddings, and the kNN graph. ```python import scib import scanpy as sc adata = sc.read_h5ad("pbmc_data.h5ad") # Full preprocessing pipeline scib.pp.reduce_data( adata, batch_key="batch", n_top_genes=2000, # HVG selection pca=True, # Compute PCA pca_comps=50, # Number of PCs neighbors=True, # Compute kNN graph umap=False # Skip UMAP ) # adata now contains: # - adata.var['highly_variable']: HVG annotations # - adata.obsm['X_pca']: PCA embeddings # - adata.uns['neighbors']: kNN graph ``` -------------------------------- ### Preprocessing API Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst Functions for preprocessing scRNA-seq data, including normalization, scaling, feature selection, cell cycle scoring, PCA, kNN graph construction, UMAP, and clustering. ```APIDOC ## Preprocessing API ### Description Provides functions for essential preprocessing steps in scRNA-seq analysis, preparing data for integration and postprocessing results. ### Key Preprocessing Steps: - Normalization - Scaling (batch-aware) - Highly variable gene selection (batch-aware) - Cell cycle scoring - Principal Component Analysis (PCA) - k-nearest neighbor graph (kNN graph) construction - Uniform Manifold Approximation and Projection (UMAP) - Clustering Note: Some preprocessing steps have dependencies on others. Refer to the "Single Cell Best Practices Book" for more details. ### Available Functions: - `scib.preprocessing.normalize` - `scib.preprocessing.scale_batch` - `scib.preprocessing.hvg_intersect` - `scib.preprocessing.hvg_batch` - `scib.preprocessing.score_cell_cycle` - `scib.preprocessing.get_cell_cycle_genes` - `scib.preprocessing.reduce_data` ``` -------------------------------- ### Find Optimal Clustering Resolution (Python) Source: https://context7.com/theislab/scib/llms.txt Determines the optimal clustering resolution by maximizing the Normalized Mutual Information (NMI) between computed clusters and known cell type labels. This function requires an AnnData object, keys for cell type and cluster assignments, and a list of resolutions to test. It utilizes a specified clustering function (e.g., Leiden or Louvain) and can use a pre-computed embedding. ```python import scib import scanpy as sc sc.pp.neighbors(adata, use_rep="X_emb") res_max, score_max = scib.me.cluster_optimal_resolution( adata, label_key="celltype", cluster_key="cluster", cluster_function=sc.tl.leiden, # or sc.tl.louvain resolutions=[0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0], use_rep="X_emb", verbose=True ) print(f"Optimal resolution: {res_max}, NMI: {score_max}") # Cluster assignments stored in adata.obs['cluster'] ``` -------------------------------- ### Compute Isolated Label Scores (F1 and ASW) Source: https://context7.com/theislab/scib/llms.txt Evaluates the preservation of isolated or rare cell types using both F1-score (clustering-based) and ASW (silhouette-based) metrics. These scores are crucial for understanding how well rare populations are maintained after integration. ```python import scib import scanpy as sc # Isolated label F1 (clustering-based) sc.pp.neighbors(adata, use_rep="X_emb") il_f1 = scib.me.isolated_labels_f1( adata, label_key="celltype", batch_key="batch", embed="X_emb" ) # Returns: 0.65 # Isolated label ASW (silhouette-based) il_asw = scib.me.isolated_labels_asw( adata, label_key="celltype", batch_key="batch", embed="X_emb" ) # Returns: 0.58 ``` -------------------------------- ### Compute Batch Silhouette Score Source: https://context7.com/theislab/scib/llms.txt Calculates the silhouette score for batch mixing, evaluating how well cells from the same batch cluster together. Scores close to 0 indicate good mixing between batches. The `scale=True` option adjusts the score so higher values are better. ```python import scib asw_batch = scib.me.silhouette_batch( adata, batch_key="batch", label_key="celltype", embed="X_emb", metric="euclidean", scale=True # Scaled so higher is better ) # Returns: 0.89 (higher means better batch mixing) ``` -------------------------------- ### Clustering API Source: https://github.com/theislab/scib/blob/main/docs/source/api.rst Functions related to clustering scRNA-seq data, often used in conjunction with integration metrics to evaluate performance. ```APIDOC ## Clustering API ### Description Functions related to clustering scRNA-seq data, primarily used for evaluating integration quality by comparing clusters to original annotations. ### Available Functions: - `scib.metrics.cluster_optimal_resolution` - `scib.metrics.get_resolutions` - `scib.metrics.opt_louvain` ``` -------------------------------- ### Cell Cycle Scoring (Python) Source: https://context7.com/theislab/scib/llms.txt Assigns cell cycle phase scores (S and G2M) and determines the phase for each cell based on provided organism-specific gene sets. The results are stored in the `adata.obs` DataFrame. ```python import scib # Score cell cycle for human data scib.pp.score_cell_cycle(adata, organism="human") # Supported organisms: mouse, human, c_elegans, zebrafish # Results stored in adata.obs['S_score'], adata.obs['G2M_score'], adata.obs['phase'] ``` -------------------------------- ### Batch-aware Highly Variable Gene Selection (Python) Source: https://context7.com/theislab/scib/llms.txt Selects highly variable genes (HVGs) while considering batch effects. It can return either a list of gene names or a subset AnnData object containing only the HVGs. ```python import scib import scanpy as sc # Load and prepare data adata = sc.read_h5ad("pbmc_data.h5ad") # Batch-aware HVG selection hvg_list = scib.pp.hvg_batch( adata, batch_key="batch", target_genes=2000, flavor="cell_ranger", n_bins=20, adataOut=False # Return list of genes ) # Returns: ['GENE1', 'GENE2', ..., 'GENE2000'] # Or return subset AnnData adata_hvg = scib.pp.hvg_batch( adata, batch_key="batch", target_genes=2000, adataOut=True # Return AnnData subset ) ``` -------------------------------- ### Compute Cell Type Silhouette Score (ASW) Source: https://context7.com/theislab/scib/llms.txt Measures the separation of cell types in the embedding space using the silhouette score. It assesses how well-defined each cell type is, with higher scores indicating better separation. This function can operate on reduced data or embeddings. ```python import scib # For feature output scib.pp.reduce_data(adata, n_top_genes=2000, batch_key="batch", pca=True, neighbors=False) asw_label = scib.me.silhouette( adata, label_key="celltype", embed="X_pca", metric="euclidean", scale=True # Scale to 0-1 ) # Returns: 0.72 (higher means better cell type separation) # For embedding output asw_label = scib.me.silhouette(adata, label_key="celltype", embed="X_emb") ``` -------------------------------- ### Compute Normalized Mutual Information (NMI) Source: https://context7.com/theislab/scib/llms.txt Calculates the Normalized Mutual Information (NMI) score to assess how well cluster assignments align with known cell type labels. This metric is useful for evaluating the biological conservation of cell types after integration. It requires pre-computed neighbors and cluster assignments. ```python import scib import scanpy as sc # Prepare data sc.pp.neighbors(adata, use_rep="X_emb") scib.me.cluster_optimal_resolution( adata, cluster_key="cluster", label_key="celltype" ) # Compute NMI nmi_score = scib.me.nmi( adata, cluster_key="cluster", label_key="celltype", implementation="arithmetic" # Options: max, min, geometric, arithmetic ) # Returns: 0.85 (score between 0-1, higher is better) ``` -------------------------------- ### Compute Graph Connectivity Score Source: https://context7.com/theislab/scib/llms.txt Measures the connectivity of cell type subgraphs within the neighborhood graph after data integration. Higher scores indicate better preservation of cell type structure and connectivity within each cell type group. ```python import scib import scanpy as sc sc.pp.neighbors(adata, use_rep="X_emb") gc_score = scib.me.graph_connectivity( adata, label_key="celltype" ) # Returns: 0.94 (higher means better connectivity per cell type) ``` -------------------------------- ### Compute Trajectory Conservation Score Source: https://context7.com/theislab/scib/llms.txt Measures the preservation of developmental trajectories after data integration. This metric requires pre-computed pseudotime values in the unintegrated data and compares trajectories in both integrated and unintegrated datasets. ```python import scib import scanpy as sc # Requires pre-computed pseudotime in unintegrated data # adata_unintegrated.obs['dpt_pseudotime'] must exist sc.pp.neighbors(adata_integrated, use_rep="X_emb") trajectory_score = scib.me.trajectory_conservation( adata_unintegrated, adata_integrated, label_key="celltype", pseudotime_key="dpt_pseudotime" ) # Returns: 0.81 (scaled 0-1, higher means better trajectory preservation) ``` -------------------------------- ### Compute Adjusted Rand Index (ARI) Source: https://context7.com/theislab/scib/llms.txt Calculates the Adjusted Rand Index (ARI) to evaluate the pairwise accuracy between clustering results and ground truth cell type labels. A higher ARI score indicates better agreement between the predicted clusters and the true cell types. ```python import scib ari_score = scib.me.ari( adata, cluster_key="cluster", label_key="celltype" ) # Returns: 0.78 (score between 0-1, higher is better) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.