ENVI 本地文档+教程+源码 - 100%覆盖13个文件(Sphinx build + 手动转换 notebooks/py)
Comprehensive assistance with ENVI (Environmental Niche Integration) for spatial transcriptomics and single-cell RNA sequencing data integration.
This skill should be triggered when:
Core ENVI Tasks:
Data Analysis Workflows:
Technical Implementation:
Visualization and Downstream Analysis:
Example 1 (python):
# Environment setup for GPU/CPU usage
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0" # Change to -1 for CPU
import warnings
warnings.filterwarnings('ignore')
Example 2 (python):
# Install and import ENVI
!pip install scenvi
import scenvi
Example 3 (python):
# Load spatial and single-cell data
import scanpy as sc
st_data = sc.read_h5ad('st_data.h5ad') # Spatial transcriptomics
sc_data = sc.read_h5ad('sc_data.h5ad') # Single-cell RNA-seq
Example 4 (python):
# Prepare single-cell data with highly variable genes
sc_data.layers['log'] = np.log(sc_data.X + 1)
sc.pp.highly_variable_genes(sc_data, layer='log', n_top_genes=2048)
Example 5 (python):
# Initialize ENVI model with default parameters
envi_model = scenvi.ENVI(
spatial_data=st_data,
sc_data=sc_data,
spatial_key='spatial',
covet_batch_size=256
)
Example 6 (python):
# Train the model and run inference
envi_model.train()
envi_model.impute_genes()
envi_model.infer_niche_covet()
envi_model.infer_niche_celltype()
Example 7 (python):
# Extract ENVI results and create joint UMAP
st_data.obsm['envi_latent'] = envi_model.spatial_data.obsm['envi_latent']
sc_data.obsm['envi_latent'] = envi_model.sc_data.obsm['envi_latent']
fit = umap.UMAP(n_neighbors=100, min_dist=0.3, n_components=2)
latent_umap = fit.fit_transform(
np.concatenate([st_data.obsm['envi_latent'], sc_data.obsm['envi_latent']])
)
Example 8 (python):
# Advanced analysis: Diffusion maps on COVET matrices
def run_diffusion_maps(data_df, n_components=10, knn=30, alpha=0):
"""Run diffusion maps using adaptive anisotropic kernel"""
# Implementation for niche trajectory analysis
return diffusion_components
DC_COVET = run_diffusion_maps(
np.concatenate([
st_data.obsm['COVET_SQRT'].reshape([st_data.shape[0], -1]),
sc_data.obsm['COVET_SQRT'].reshape([sc_data.shape[0], -1])
])
)
ENVI (Environmental Niche Integration): A deep learning framework that integrates spatial transcriptomics data with dissociated single-cell RNA sequencing data using a conditional variational autoencoder (CVAE).
COVET (Cellular Niche Covariance): A method that quantifies cellular microenvironments by computing gene-gene covariance matrices for each cell based on its spatial neighbors.
Latent Space Integration: ENVI learns a shared latent representation where spatial and single-cell cells co-embed, enabling cross-modal inference.
Niche Cell Type Composition: Predictions of the proportion of different cell types in each cell's local microenvironment.
Gene Imputation: Prediction of missing gene expression values in spatial data using information learned from single-cell data.
This skill includes comprehensive documentation in references/:
obsm['spatial'] and both datasets have matching gene namesnum_cov_genes and k_nearest for your tissue typespatial_dist='pois' for count data, sc_dist='nb' for single-cellcov_genes or sc_genes parametersnum_layers, num_neurons, and latent_dim for complex datasetsspatial_coeff, sc_coeff, cov_coeff, kl_coeffcovet_use_obsm or covet_use_layer for alternative data representationscode.md for the ENVI class constructor and utility functionsdocs.md for step-by-step tutorials with real datatutorials.md for notebook-style exploration and advanced visualizationsSpatial Integration: tutorials.md:1188-1215 shows complete ENVI setup and training
Niche Analysis: docs.md:666-808 provides COVET analysis and diffusion maps
Visualization: tutorials.md:1304-1327 demonstrates publication-ready plotting
Comprehensive documentation containing:
Add helper scripts for:
Include:
covet_batch_size based on memoryTo refresh this skill with updated documentation: