SMODER modules

SMODER: spatial multi-omics deconvolution toolkit.

smoder.omics_reconstruct(omics_type: str, expr_path: str, spatial_path: str, target_genes: Sequence[str] | None, hidden_dim: int = 64, n_layers: int = 3, epochs: int = 500, lr: float = 0.0001, patience: int = 30, save_path: str | None = None, encoder_key: str | None = None, device: str | None = None, seed: int = 42, n_angles: int = 100, batch_size: int = 64, print_interval: int = 10, do_lognorm: bool = True, target_sum: float = 10000.0, spatial_k: int = 12, do_preprocess: bool | None = None, pre_k: int = 8, pre_quantile: float = 0.8, pre_support: float = 0.3) anndata.AnnData[source]

Reconstruct selected RNA or second-modality gene/feature signals.

Parameters:
  • omics_type – One of "RNA", "ATAC", "PEAK", "EPIGENOMICS", "ADT", or "PROTEIN".

  • expr_path – Path to an AnnData file containing the target expression/signal matrix.

  • spatial_path – Path to a SMODER result AnnData file containing spatial coordinates and encoder representations.

  • target_genes – Genes or features to reconstruct. If None, all features are used.

  • encoder_key – Key in spatial_path.obsm used as model input. If None, a default is selected based on omics_type.

  • save_path – Optional output path for saving the reconstructed AnnData object.

Returns:

Reconstructed AnnData object. .X stores denoised/reconstructed signals, .obsm["spatial"] stores spatial coordinates, and .layers["original_label"] stores the target labels used for fitting.

Return type:

AnnData

smoder.get_cell_type_proportions(adata: anndata.AnnData, obsm_key: str = 'cell_type_proportions', obs_start_col: int | None = None, cell_type_names: Sequence[str] | None = None) pandas.DataFrame[source]

Extract cell-type proportion matrix from a SMODER result AnnData object.

Priority: 1. use adata.obsm[obsm_key] if available; 2. otherwise use adata.obs.iloc[:, obs_start_col:].

smoder.plot_all_cell_type_proportions(adata: anndata.AnnData, out_path: str, obsm_key: str = 'cell_type_proportions', obs_start_col: int | None = None, cell_type_names: Sequence[str] | None = None, ncols: int = 6, point_size: float = 2, cmap: str = 'viridis', vmin: float = 0, vmax: float = 1, title: str = 'Spatial heatmaps of cell-type proportions', spatial_key: str = 'spatial', flip_y: bool = True, dpi: int = 200) pandas.DataFrame[source]

Save one panel containing all cell-type proportion heatmaps.

smoder.plot_cell_type_proportion_panel(adata: anndata.AnnData, out_path: str, obsm_key: str = 'cell_type_proportions', obs_start_col: int | None = None, cell_type_names: Sequence[str] | None = None, selected_cell_types: Sequence[str] | None = None, top_n: int | None = 12, ncols: int = 4, point_size: float = 4, cmap: str = 'viridis', vmin: float | None = None, vmax: float | None = None, title: str = 'Spatial heatmaps of cell-type proportions', spatial_key: str = 'spatial', flip_y: bool = True, dpi: int = 300) pandas.DataFrame[source]

Save a multi-panel figure of selected cell-type proportion heatmaps.

smoder.plot_embedding_spatial_clustering(adata: anndata.AnnData, out_path: str, embedding_key: str = 'embedding', cluster_key: str = 'smoder_cluster', method: str = 'leiden', resolution: float = 0.6, n_neighbors: int = 15, spatial_key: str = 'spatial', flip_y: bool = True, point_size: float = 6, dpi: int = 300) anndata.AnnData[source]

Cluster a learned embedding and save a spatial cluster map.

smoder.plot_reconstruction_heatmaps(recon_adata: anndata.AnnData, out_dir: str, prefix: str, title_prefix: str, spatial_key: str = 'spatial', flip_y: bool = True, point_size: float = 6, cmap: str = 'viridis', dpi: int = 300) None[source]

Save spatial heatmaps for all reconstructed genes/features in recon_adata.