pyXenium.multimodal.ProteinMicroEnv#
- class ProteinMicroEnv(adata, protein_obsm='protein', protein_norm_obsm='protein_norm', cluster_key='cluster', spatial_obsm='spatial', obs_xy=('x_centroid', 'y_centroid'), random_state=0)#
Bases:
objectMicroenvironment analysis for protein heterogeneity within an RNA cluster.
- Parameters:
- __init__(adata, protein_obsm='protein', protein_norm_obsm='protein_norm', cluster_key='cluster', spatial_obsm='spatial', obs_xy=('x_centroid', 'y_centroid'), random_state=0)#
Methods
__init__(adata[, protein_obsm, ...])analyze(cluster_id, protein[, group_key, ...])Run the full microenvironment pipeline.
build_kdtree_full([radius])Build a KDTree on all cells and decide a heuristic radius if not provided.
build_spatial_graph(cluster_id[, radius])CSR adjacency within the chosen cluster; used for Moran's I.
de_within_cluster(cluster_id, protein_status_col)RNA DE within a cluster between protein-high vs protein-low.
microenv_predict_from_comp(focus_index, ...)Predict protein-high from neighborhood fractions; report AUC and feature coefficients.
neighbor_composition_global(focus_index, ...)Compute neighborhood composition for focus_index cells against all cells (global KDTree), grouped by obs[group_key].
neighbor_enrichment_from_comp(focus_index, ...)Permutation test on neighborhood fractions between protein-high vs protein-low (within focus_index).
normalize_protein([method, cofactor])Store normalized protein matrix in obsm[protein_norm_obsm].
plot_spatial(color[, title, s, alpha, cmap])Robust spatial scatter for numeric or categorical obs/obsm fields (with alias/status auto-fix).
protein_moransI(names_sub, A_sub, protein[, ...])Moran's I of protein expression within the cluster.
split_high_low(cluster_id, protein[, ...])Split within a cluster into protein_high vs protein_low by thresholding.
Attributes
- normalize_protein(method='clr', cofactor=5.0)#
Store normalized protein matrix in obsm[protein_norm_obsm].
- split_high_low(cluster_id, protein, method='gmm', quantile=0.5)#
Split within a cluster into protein_high vs protein_low by thresholding. Returns (table, status_col, threshold).
- build_spatial_graph(cluster_id, radius=None)#
CSR adjacency within the chosen cluster; used for Moran’s I.
- build_kdtree_full(radius=None)#
Build a KDTree on all cells and decide a heuristic radius if not provided. Returns (tree, coords_all, radius_used).
- neighbor_composition_global(focus_index, tree, coords_all, radius, group_key)#
Compute neighborhood composition for focus_index cells against all cells (global KDTree), grouped by obs[group_key].
- neighbor_enrichment_from_comp(focus_index, comp, protein_status_col, permutations=999, random_state=0)#
Permutation test on neighborhood fractions between protein-high vs protein-low (within focus_index).
- microenv_predict_from_comp(focus_index, comp, protein_status_col, C=1.0, max_iter=1000)#
Predict protein-high from neighborhood fractions; report AUC and feature coefficients.
- protein_moransI(names_sub, A_sub, protein, use_norm=True, permutations=999)#
Moran’s I of protein expression within the cluster.
- de_within_cluster(cluster_id, protein_status_col, layer='rna', method='wilcoxon', n_top_hvg=3000)#
RNA DE within a cluster between protein-high vs protein-low. Auto normalize_total + log1p (avoid raw-count warning), optional HVG selection for speed.
- plot_spatial(color, title='', s=2.0, alpha=0.9, cmap='viridis')#
Robust spatial scatter for numeric or categorical obs/obsm fields (with alias/status auto-fix).
- analyze(cluster_id, protein, group_key='cluster', radius=None, status_method='gmm', status_quantile=0.5, de_layer='rna', permutations=999, save_dir=None)#
Run the full microenvironment pipeline.
- Returns dict with keys:
status_col, threshold
radius_cluster, radius_global
neighbor_enrichment (DataFrame)
moransI (dict)
de (DataFrame)
predict_auc (float), predict_coef (DataFrame)