OSCR

Riemannian metric learning for alignment of spatial multiomics.

Code ↔ Paper

1 match between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 1 match
  1. [1] § 3 Results › 3.1 Spatiotemporal transcriptomics of mouse-embryo ↔ demos/mouse_align.ipynb, lines 13–76 · score 0.57 · E10.5, mouse embryo, e9, Spatiotemporal, geodesic, GW

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 207 lines · 6.4 KB · no license · 1 match

  1. # %%
  2. import os
  3. os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
  4. os.environ["MKL_CBWR"] = "COMPATIBLE"
  5. os.environ["ATEN_CPU_CAPABILITY"] = "avx2"
  6. os.environ["OMP_NUM_THREADS"] = os.environ["MKL_NUM_THREADS"] = os.environ["OPENBLAS_NUM_THREADS"] = "8"
  7. os.environ["NPY_DISABLE_CPU_FEATURES"] = "AVX512F AVX512CD AVX512_KNL AVX512_KNM AVX512_SKX AVX512_CLX AVX512_CNL AVX512_ICL AVX512_SPR"
  8. os.environ["OPENBLAS_CORETYPE"] = "Haswell"
  9. import sys
  10. sys.path.append("..")
  11. # %% [markdown]
  12. # # Example Alignment on Spatiotemporal Mouse Embryo
  13. #
  14. # We provide an example alignment on two spatiotemporal mouse embryo slices -- `E9.5` and `E10.5` -- from Chen et al '22 (link: https://pubmed.ncbi.nlm.nih.gov/35512705/).
  15. #
  16. # In particular, we show the alignment of `MGW` on the public `E9.5_E1S1.MOSTA.h5ad` and `E10.5_E1S1.MOSTA.h5ad` files. A key point is that no fused FGW feature information is used, so this alignment is treated as if the data were "multimodal."
  17. # %%
  18. # ============================================================
  19. # M-GW: Pairwise Alignment of Spatiotemporal Mouse Embryo Slices
  20. # ============================================================
  21. import scanpy as sc
  22. import anndata as ad
  23. import numpy as np, torch, scipy.sparse as sp
  24. from mgw import util, models, plotting, geometry
  25. from mgw import pullback_metric_field, knn_graph
  26. from mgw.gw import solve_gw_ott
  27. import importlib
  28. import matplotlib.pyplot as plt
  29. import os
  30. # ----------------------------
  31. # Runtime & device setup
  32. # ----------------------------
  33. device = 'cuda' if torch.cuda.is_available() else 'cpu'
  34. torch.set_default_dtype(torch.float64)
  35. print("Device:", device)
  36. # ----------------------------
  37. # Input files & parameters
  38. # ----------------------------
  39. filehandles_embryo_adata = [
  40. '/scratch/gpfs/BRAPHAEL/ph3641/mouse_embryo/E9.5_E1S1.MOSTA.h5ad',
  41. '/scratch/gpfs/BRAPHAEL/ph3641/mouse_embryo/E10.5_E1S1.MOSTA.h5ad'
  42. ]
  43. timepoints = ['E9.5', 'E10.5']
  44. # Embedding / network parameters
  45. PCA_comp = 30
  46. knn_k = 12
  47. geodesic_eps = 0.01
  48. gw_params = dict(verbose=True, inner_maxit=3000, outer_maxit=3000,
  49. inner_tol=1e-7, outer_tol=1e-7, epsilon=1e-4)
  50. save_dir = "/scratch/gpfs/BRAPHAEL/ph3641/mgw/ME_Alignments"
  51. os.makedirs(save_dir, exist_ok=True)
  52. # ============================================================
  53. # 1. Load datasets and prepare
  54. # ============================================================
  55. print('Loading AnnData slices...')
  56. adatas = []
  57. for i, fh in enumerate(filehandles_embryo_adata):
  58. adata = sc.read_h5ad(fh)
  59. adata.X = adata.layers['count']
  60. adata.obs['timepoint'] = [timepoints[i]] * adata.shape[0]
  61. adatas.append(adata)
  62. # Intersect genes across all slices
  63. common_genes = sorted(set.intersection(*[set(a.var_names) for a in adatas]))
  64. adatas = [a[:, common_genes] for a in adatas]
  65. print(f"Common genes: {len(common_genes)}")
  66. # %%
  67. from mgw import metrics
  68. from mgw import mgw as mgw
  69. from scipy.spatial.distance import cdist
  70. ad1, ad2 = adatas[0], adatas[1]
  71. tp1, tp2 = timepoints[0], timepoints[1]
  72. print(f"\n--- Aligning {tp1} → {tp2} ---")
  73. # Normalization, log1p, PCA
  74. joint = ad.concat([ad1, ad2], join='inner')
  75. sc.pp.normalize_total(joint)
  76. sc.pp.log1p(joint)
  77. sc.pp.pca(joint, n_comps=PCA_comp)
  78. # Split back into slices
  79. A = joint[joint.obs['timepoint'] == tp1].copy()
  80. B = joint[joint.obs['timepoint'] == tp2].copy()
  81. # ========================================================
  82. # (a) Feature preprocessing (PCA + CCA "feeler")
  83. # ========================================================
  84. pre = mgw.mgw_preprocess(
  85. A, B,
  86. PCA_comp=30,
  87. CCA_comp=3,
  88. use_cca_feeler=True,
  89. use_pca_X=True,
  90. use_pca_Z=True,
  91. log1p_X=True,
  92. log1p_Z=True,
  93. verbose=True,
  94. feature_only=False,
  95. spatial_only=True,
  96. rep_norm="zscore",
  97. )
  98. # %%
  99. PCA_component = 30
  100. CCA_component = 3
  101. PHI_ARC = (128,256,256,128)
  102. KNN_K= 12
  103. DEFAULT_GW_PARAMS = dict(verbose=True, inner_maxit=3000, outer_maxit=3000, inner_tol=1e-7, outer_tol=1e-7, epsilon=1e-4)
  104. DEFAULT_LR = 1e-3
  105. DEFAULT_EPS = 1e-2
  106. DEFAULT_ITER = 20_000
  107. SEED = 1
  108. # %%
  109. EXP_PATH = None #specify the path to save your trained phi psi model (None: retrain without caching)
  110. EXP_TAG = f'ME_CCA_seed{SEED}' #specify the name of your experiment
  111. # %%
  112. out = mgw.mgw_align_core(
  113. pre,
  114. widths=PHI_ARC,
  115. lr=DEFAULT_LR,
  116. niter=DEFAULT_ITER,
  117. knn_k=KNN_K,
  118. geodesic_eps=DEFAULT_EPS,
  119. save_dir=EXP_PATH,
  120. tag=EXP_TAG,
  121. verbose=True,
  122. plot_net=True,
  123. gw_params = DEFAULT_GW_PARAMS,
  124. seed=SEED,
  125. deterministic=True,
  126. n_restarts=1,
  127. )
  128. # %% [markdown]
  129. # # We can plot the associated alignment after rigid-transformation into a common frame with Procrustes.
  130. # %%
  131. xs = out["xs"]
  132. xs2 = out["xs2"]
  133. P = out["P"]
  134. xs_aligned, xt_aligned, R, tvec = plotting.procrustes_from_coupling(xs, xs2, P)
  135. plotting.plot_alignment_lines_dense(xs, xs2, P, alpha=0.01)
  136. # %% [markdown]
  137. # # We can check the orientation of the alignment.
  138. # %%
  139. Y = (P @ xs2) / P.sum(1, keepdims=True)
  140. U, _, Vt = np.linalg.svd((xs - xs.mean(0)).T @ (Y - Y.mean(0)))
  141. print(f"orientation det = {np.linalg.det(U @ Vt):+.0f}")
  142. PAPER_P = '/scratch/gpfs/BRAPHAEL/ph3641/mgw/ME_Alignments/P_E9.5_E10.5.npz'
  143. if os.path.isfile(PAPER_P):
  144. P_ref = sp.load_npz(PAPER_P)
  145. Y_ref = np.asarray(P_ref @ xs2) / np.asarray(P_ref.sum(1))
  146. print(f"distance to paper MGW map = {np.sqrt(((Y - Y_ref) ** 2).sum(1).mean()):.3f}")
  147. # %% [markdown]
  148. # # We can also view the alignment as two tilted layers joined by the coupling's peak links.
  149. # %%
  150. from mgw import align_vis
  151. top, bottom, _ = align_vis.coarsen_to_shared_annotations(A.obs["annotation"].astype(str).to_numpy(),
  152. B.obs["annotation"].astype(str).to_numpy(), max_classes=7)
  153. _ = align_vis.plot_tilted_alignment(
  154. A.obsm["spatial"], B.obsm["spatial"], top, bottom, P,
  155. dataset_title=f"Mouse embryo {tp1} → {tp2} · MGW", top_name=tp1, bottom_name=tp2,
  156. label_description="original tissue annotations", k_per_point=3)
  157. # %% [markdown]
  158. # # One can also project the annotations through the alignment to find the `mgw` predicted clusters.
  159. # %%
  160. A_labels = plotting._labels_or_cluster(A, key="annotation")
  161. B_labels = plotting._labels_or_cluster(B, key="annotation")
  162. A_pred, A_conf, _ = plotting.project_labels_via_P(P.T, B_labels, direction="A_to_B")
  163. plotting.plot_projected_labels(B.obsm['spatial'], A.obsm['spatial'],
  164. B_labels, A_pred, conf_thresh=0.5, s=10)

mouse_align.ipynb at commit 944e84a, no license · at the source

Overview

Authors: Peter Halmos1, Yufan Xia1, Benjamin J Raphael1
  1. Department of Computer Science, Princeton University, Princeton, NJ 08544, United States
Institutions: Princeton University (United States)
Journal: Bioinformatics (Oxford, England), volume 42, issue Suppl 1, article btag220
Dates: received 9 April 2026; accepted 16 April 2026; published online 7 July 2026; in print July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1093/bioinformatics/btag220 · PMID 42412825 · PMCID PMC13340267 · OpenAlex W4417262380
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: genetics / omics (modality), human (organism), mouse (organism), methods / tools (subfield)
Methods: Machine learning
MeSH: Machine Learning*, Multiomics*, Algorithms, Animals, Colorectal Neoplasms, Humans, Metabolomics, Mice, Spatial Transcriptomics (* major topic)
Topic: Single-cell and spatial transcriptomics (Molecular Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: NCI NIH HHS (U24 CA264027, U24CA248453, U24CA264027, U24 CA248453); Princeton Catalysis Initiative, and Ludwig Cancer Research
Citations: not cited yet (Europe PMC); 46 references in the paper

Abstract

Motivation: Recent spatial technologies measure the transcriptome, epigenome, proteome, metabolome, and other modalities from thousands of cells across a tissue. Most assays typically profile only one modality from a tissue slice, raising the question of how to align spatial data from heterogeneous feature spaces. While multiple approaches have been developed for multi-modal integration of single-cell datasets, few existing techniques perform spatial alignment across arbitrary modalities incorporating both spatial and feature information.

Results: We introduce Manifold Gromov-Wasserstein (MGW), a metric-learning framework that exploits the product structure of spatial multiomics to infer modality-specific Riemannian pull-back metrics with neural fields. MGW aligns Riemannian distances induced by these metrics via Gromov-Wasserstein optimal transport, yielding a hyperparameter-free cost across arbitrary modalities sharing a spatial base. The formulation enjoys theoretical invariances—including orthogonal transformations of the spatial and feature domains as well as global feature scalings. We demonstrate the advantages of MGW on multiple alignment tasks, including Stereo-Seq spatiotemporal transcriptomics of mouse embryo, Xenium and Visium spatial transcriptomics of colorectal cancer, and spatial metabolomics-transcriptomics from human striatum and kidney cancer. MGW recovers biologically meaningful correspondences and spatially coherent tissue structures, outperforming existing OT and non-OT based multi-modal baselines.

Availability and implementation: Software is available at https://github.com/raphael-group/MGW.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.

raphael-group/MGW

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 944e84a286bc434e513cc940524576c0de071cb6, 24 September 2026
Languages: Python (32), Jupyter (29)
Size: 63 files, 61 scripts
Software Heritage: not archived
Found in: “Data availability”
Holds: README, 16 notebooks
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: anndata (5 files), NumPy (5 files), PyTorch (5 files), Scanpy (5 files), SciPy (3 files), Squidpy (3 files), Matplotlib (2 files), scikit-learn (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
6 files

Zenodo 20074368

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Data availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)

Availability and implementation

Software is available at https://github.com/raphael-group/MGW.

Reproduced under the paper's license (CC BY), from the paper cited above.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 5 scripts, each with its path and the digest of its content;
  • 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability

The spatial multiomics datasets analyzed in this study are publicly available from their original publications and associated data repositories:

- The spatiotemporal mouse transcriptomics Stereo-Seq data (Chen 2022) is available via the MOSTA database.

- The Visium and Xenium colorectal cancer (CRC) dataset (Oliveira 2024) is available from the 10x Genomics spatial genomics data repository.

- The MALDI-MSI metabolomics and Visium transcriptomics dataset of human striatum (Vicari 2023) is available at Mendeley Data under accession: https://data.mendeley.com/datasets/w7nw4km7xd/1

- The AFADESI-MSI metabolomics and Visium transcriptomics dataset of human clear cell renal carcinoma (ccRCC) (Tian 2025) is available at Zenodo under accession (https://zenodo.org/records/14986870).

The open-source Python implementation of MGW, along with tutorials and scripts to reproduce the experiments described in this manuscript, is freely available on GitHub at https://github.com/raphael-group/MGW and archived on Zenodo at DOI: 10.5281/zenodo.20074368 (https://doi.org/10.5281/zenodo.20074368).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 3 authors, 9 MeSH terms, 2 funders, 35 references.

Cite

This paper

Halmos, P., Xia, Y., & Raphael, B. J. (2026). Riemannian metric learning for alignment of spatial multiomics. Bioinformatics (Oxford, England), 42(Suppl 1), btag220. https://doi.org/10.1093/bioinformatics/btag220

BibTeX

@article{halmos2026riemannian,
author = {Halmos, Peter and Xia, Yufan and Raphael, Benjamin J},
title = {{Riemannian metric learning for alignment of spatial multiomics}},
journal = {Bioinformatics (Oxford, England)},
year = {2026},
month = jul,
volume = {42},
number = {Suppl 1},
pages = {btag220},
publisher = {Oxford University Press},
issn = {1367-4803},
doi = {10.1093/bioinformatics/btag220},
url = {https://doi.org/10.1093/bioinformatics/btag220},
pmid = {42412825},
pmcid = {PMC13340267}
}

RIS

TY - JOUR
AU - Halmos, Peter
AU - Xia, Yufan
AU - Raphael, Benjamin J
TI - Riemannian metric learning for alignment of spatial multiomics
T2 - Bioinformatics (Oxford, England)
J2 - Bioinformatics
PY - 2026
DA - 2026/07/01
VL - 42
IS - Suppl 1
SP - btag220
SN - 1367-4803
PB - Oxford University Press
DO - 10.1093/bioinformatics/btag220
UR - https://doi.org/10.1093/bioinformatics/btag220
LA - en
ER -

CSL-JSON

{
"id": "10.1093/bioinformatics/btag220",
"type": "article-journal",
"title": "Riemannian metric learning for alignment of spatial multiomics",
"container-title": "Bioinformatics (Oxford, England)",
"author": [
{
"family": "Halmos",
"given": "Peter"
},
{
"family": "Xia",
"given": "Yufan"
},
{
"family": "Raphael",
"given": "Benjamin J"
}
],
"container-title-short": "Bioinformatics",
"volume": "42",
"issue": "Suppl 1",
"page": "btag220",
"DOI": "10.1093/bioinformatics/btag220",
"PMID": "42412825",
"PMCID": "PMC13340267",
"ISSN": "1367-4803",
"publisher": "Oxford University Press",
"URL": "https://doi.org/10.1093/bioinformatics/btag220",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1093/bioinformatics/btag540 [code]
Deciphering spatial heterogeneity by multimodal spatial transcriptomics modelling with SpatialModal.
Journal: Bioinformatics (Oxford, England)
In common: Squidpy, anndata, Scanpy, 5 other tools, methods / tools, genetics / omics, mouse, 8 references
[2] doi:10.1093/bib/bbag331 [code]
SPOmiAlign: a modality-agnostic computational framework for multimodal spatial omics alignment enabled by a feature matching foundation model.
Journal: Briefings in bioinformatics
In common: anndata, Scanpy, PyTorch, 3 other tools, Zenodo 14986870, methods / tools, genetics / omics, mouse, 5 references
[3] doi:10.1038/s41592-026-03194-8 [code]
Beyond benchmarking: an expert-guided consensus approach to spatially aware clustering.
Journal: Nature methods
In common: Squidpy, anndata, Scanpy, 5 other tools, methods / tools, genetics / omics, 6 references
[4] doi:10.1002/advs.77003 [code]
SemanticST: A Scalable Multi-Contextual Graph Learning Framework for Uncovering Spatial Niches and Robust Multi-Sample Integration in Spatial Transcriptomics.
Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)
In common: anndata, Scanpy, PyTorch, 4 other tools, methods / tools, genetics / omics, 7 references
[5] doi:10.21203/rs.3.rs-9676637/v1 [code]
A Comprehensive Benchmarking of Spatial Deconvolution and Domain Detection Methods across Diverse Tissues and Spatial Transcriptomic Technologies
Journal: Research Square (preprint)
In common: Squidpy, anndata, Scanpy, 5 other tools, methods / tools, genetics / omics, 4 references
[6] doi:10.1038/s42003-026-10462-y [code]
SpaDC enables sequence-based integrative analysis and regulatory inference of spatial chromatin accessibility data.
Journal: Communications biology
In common: Squidpy, anndata, Scanpy, 5 other tools, genetics / omics, mouse, 4 references
[7] doi:10.1093/bib/bbag298 [code]
Empowering multifaceted analysis of spatial transcriptomics data with RGAST.
Journal: Briefings in bioinformatics
In common: anndata, Scanpy, PyTorch, 4 other tools, methods / tools, genetics / omics, mouse, 5 references
[8] doi:10.1038/s42003-026-10259-z [code]
Spatial transcriptomic profiling of developing mouse hearts reveals a spatially patterned signaling environment.
Journal: Communications biology
In common: Squidpy, anndata, Scanpy, 5 other tools, genetics / omics, mouse, 3 references
[9] doi:10.1093/bioinformatics/btag430 [code]
SPIDER: spatially integrated denoising via embedding regularization with single cell supervision.
Journal: Bioinformatics (Oxford, England)
In common: anndata, Scanpy, PyTorch, 4 other tools, genetics / omics, 5 references
[10] doi:10.1016/j.isci.2026.117206 [code]
ReliST: A model-agnostic risk layer for spatial transcriptomics deconvolution.
Journal: iScience
In common: anndata, Scanpy, PyTorch, 4 other tools, genetics / omics, mouse, 4 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.