Skip to main content

GOTDiff

Grassmann-Optimal-Transport Differentiation inference

Single-cell trajectory inference based on the geodesic distance accumulated along a differentiation path on the Grassmann manifold.


Why?

Each cell can be represented by a low-dimensional subspace of active regulatory programs (NMF components, scVI / Harmony loadings, ...). This subspace is a point on a Grassmann manifold. A differentiation trajectory is therefore a curve on that manifold, and the geodesic distance accumulated along the curve is the total amount of regulatory re-wiring a cell has undergone since the root (most primitive) state.

differentiation distance = Σ  d_G( Γ(t), Γ(t + Δt) )
                            t

That scalar — the total "调控变化量" along the分化路程 — is the central output of GOTDiff.


Install

pip install GOTDiff
# with GPU / plotting extras
pip install "GOTDiff[all]"

Quick start

Raw arrays

import numpy as np
from gotdiff import GOTDiff

# H comes from any external tool: NMF, scVI, Harmony, ...
# shape: (n_gene_programs, n_cells)
H = np.random.rand(20, 500)

gd = GOTDiff(k=30, p=3, metric="geodesic", backend="faiss")
gd.fit(H)

adata.obs["gotdiff_pseudotime"]     # 伪时间
adata.obs["gotdiff_diff_distance"]  # 分化路程(核心输出)
adata.obsm["X_gotdiff_grassmann"]   # 每个细胞的 Grassmann 坐标
adata.uns["gotdiff"]                # 参数、分支点等元信息

# compare total differentiation "cost" of each lineage
lineage_costs = gd.branch_path_lengths(adata.obs["cell_type"])
import scanpy as sc
from gotdiff import GOTDiff

adata = sc.read_h5ad("hematopoiesis.h5ad")

# If you already have a factor matrix (NMF / scVI / Harmony), point GOTDiff at it:
gd = GOTDiff(k=30, p=3, backend="faiss")
gd.fit_anndata(adata, use_rep="X_pca")          # or 

# If you don't, GOTDiff runs NMF for you and stores adata.obsm['X_nmf']:
gd.fit_anndata(adata, n_programs=25)

# Results are written into adata in-place:
#   adata.obs['gotdiff_pseudotime']
#   adata.obs['gotdiff_diff_distance']
#   adata.obsm['X_gotdiff_grassmann']
#   adata.uns['gotdiff']

Plotting

from gotdiff._plot import scatter, diffusion_landscape

scatter(adata, color="gotdiff_diff_distance", basis="X_umap", show_root=True)
diffusion_landscape(adata, color="cell_type")

Pipeline

   expression matrix / factor matrix (H)
                 │
                 ▼
   cells_to_grassmann  ────────────────  (from grassmann-ot)
   → U_list : (n_cells, d, p)              each cell = a subspace
                 │
                 ▼
   grassmann_pseudotime  ───────────────  intrinsic to Grassmann space
   → pseudotime, root
                 │
                 ▼
   accumulate_geodesic_distance  ──────  ★ the differentiation path length
   → diff_distance for every cell
                 │
                 ▼
   detect_branch_points ───────────────  curvature + local anisotropy
   → branch indices & scores

API summary

Object Purpose
GOTDiff Main estimator — fit(H) or fit_anndata(adata)
grassmann_geodesic_distance Pairwise geodesic distance on Gr(p, d)
grassmann_chordal_distance Cheaper Frobenius projector distance
accumulate_geodesic_distance ★ Differentiation path length
grassmann_pseudotime Intrinsic Grassmann pseudotime
fit_geodesic_curve Smooth curve through Grassmann points
detect_branch_points Branch / lineage divergence points
extract_H_from_adata Read a factor matrix from AnnData
write_results_to_adata Persist every result to AnnData

Relation to grassmann-ot

GOTDiff builds on grassmann-ot: it reuses cells_to_grassmann to map cells to Grassmann points, then adds a full trajectory-inference layer on top (pseudotime, path-length, branching, AnnData I/O, plotting).


License

MIT

Metadata

Release files for GOTDiff 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for GOTDiff 0.1.0
File Size Uploaded Provenance Actions
gotdiff-0.1.0.tar.gz 22.4 kB Without provenance Details for gotdiff-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for GOTDiff 0.1.0
File Interpreter ABI Platform Actions
gotdiff-0.1.0-py3-none-any.whl Python 3 none any Details for gotdiff-0.1.0-py3-none-any.whl

Total release size: 46.9 kB

Release files / gotdiff-0.1.0.tar.gz

Download URL gotdiff-0.1.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7db545242329cd1d896551e83e9b848f18a6cf9a07f53a82b960b69939a260cc
BLAKE2b-256 checksum
How to use checksums
d15f9349b8706b548a58525489e5f57b2c2972e6f2f7e7f979dde72fe5edf0bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.18

Release files / gotdiff-0.1.0-py3-none-any.whl

Download URL gotdiff-0.1.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09ef8913da3ca6a8951af81fafe9a12ab634d664610cdce730bf2ebb921b00b7
BLAKE2b-256 checksum
How to use checksums
7db7e29969b2a5d239692459b0824aee72aeb2f6fbf83e50db6caf733c7ae6f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.18

Security for GOTDiff 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page