Metadata-Version: 2.5
Name: sigma-omics
Version: 0.3.2
Summary: Interface-aware spectral graph learning of pathological metabolic transitions
Project-URL: Homepage, https://github.com/Elsa-bingxue/SIGMA
Project-URL: Repository, https://github.com/Elsa-bingxue/SIGMA
Project-URL: Issues, https://github.com/Elsa-bingxue/SIGMA/issues
Author-email: Bingxue Du <dubingxue73@gmail.com>
License: MIT
License-File: LICENSE
Keywords: mass spectrometry imaging,pathological interface,spatial metabolomics,spatial omics,spectral graph learning
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Requires-Dist: anndata>=0.10
Requires-Dist: matplotlib>=3.8
Requires-Dist: numpy<2,>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: scanpy>=1.10
Requires-Dist: scikit-learn>=1.3
Requires-Dist: scipy>=1.10
Requires-Dist: statsmodels>=0.14
Requires-Dist: torch-geometric<2.6,>=2.5
Requires-Dist: torch>=2.1
Requires-Dist: zarr<3,>=2.18
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: twine>=5; extra == 'dev'
Provides-Extra: plot
Requires-Dist: matplotlib>=3.8; extra == 'plot'
Description-Content-Type: text/markdown

# SIGMA · Spatial interface metabolic programmes

[![PyPI](https://img.shields.io/pypi/v/sigma-omics)](https://pypi.org/project/sigma-omics/)

SIGMA identifies metabolic programmes around tissue interfaces. It combines spatial
mass spectra, tissue coordinates and pathological or weak anchors to describe where
signals change, how far they extend and how they vary along an interface. Matched
spatial RNA can provide an auxiliary representation and cellular context.

## Installation

Use Python 3.10 or later in a separate environment. Python 3.11 is recommended for
this release. The distribution is `sigma-omics`; the import name is `sigma_spatial`.

```bash
python3.11 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install --prefer-binary "sigma-omics==0.3.2"
python -c "import sigma_spatial; print(sigma_spatial.__version__)"
```

On Windows, activate with `.venv\Scripts\activate`. To update an existing installation:

```bash
python -m pip install --upgrade --prefer-binary "sigma-omics==0.3.2"
python -m pip check
```

Restart the Python or notebook session after upgrading. PyTorch and PyTorch Geometric
are installed as dependencies; CPU execution is sufficient. For CUDA, install the
PyTorch build appropriate for your system before installing SIGMA.

## What changed in 0.3.2

- Continuous distance to an interpolated interface is available through
  `distance_mode="continuous"`.
- Zero-distance positions retain their explicitly recorded tissue side.
- Upgrading a saved coordinate also updates existing `d_signed` and `d_abs` aliases
  while preserving the old columns.
- Tied near/far thresholds no longer test overlapping groups. Unavailable programme
  comparisons return `NaN` and record `n_overlap`.

The original SIGMA model is unchanged. `distance_mode="legacy"` remains the default
for historical reproducibility. Select continuous distance explicitly for new analyses.

## Quick start

Prepare an `AnnData` object with MSI intensities in `X`, spatial coordinates in
`obsm["spatial"]`, and anchors in `obs["sigma_anchor"]` (1: inside/tumour,
0: outside/non-tumour, NaN: unknown). The paired workflow also requires an aligned
RNA representation in `obsm["X_harmony"]`, in the same spot order.

```python
import scanpy as sc
from sigma_spatial import run_sigma

adata = sc.read_h5ad("sample.h5ad")
result = run_sigma(
    adata,
    anchor_key="sigma_anchor",
    representation_key="X_harmony",
    distance_mode="continuous",
    random_state=0,
)
result.write_h5ad("sample_sigma.h5ad")
```

For explicitly anchored MSI-only data, use `run_sigma_weak_anchor`, which omits the
RNA loss. It accepts the same `distance_mode` option. Continuous distance requires
the unmodified probability-threshold mask (`boundary_mode="legacy"`); it is not
compatible with morphological mask cleanup.

## Upgrade an existing coordinate

An existing fitted probability field can be re-expressed without retraining:

```python
from sigma_spatial import update_interface_coordinate

updated = update_interface_coordinate(result, copy=True)
updated.write_h5ad("sample_sigma_continuous.h5ad")
```

This uses `obs["sigma_region_probability"]` and preserves previous coordinate
columns under the `_before_continuous` suffix. It does **not** recalculate existing
ion rankings or programme memberships. Recompute downstream analyses before
interpreting results under the new coordinate.

## Side-specific near/far comparisons

```python
from sigma_spatial import side_near_far_statistics

# program_scores maps programme names to arrays in the same spot order as updated.
statistics = side_near_far_statistics(
    program_scores,
    updated.obs["sigma_d_signed"].to_numpy(),
    inside_mask=updated.obs["sigma_inside"].to_numpy(),
    side_names={"negative": "Tumour", "positive": "Stroma"},
)
```

Negative distance denotes the inside, positive distance the outside. An exact zero
is a location, not a side label. If `inside_mask` is omitted, zero-distance positions
are excluded with a warning. Distances use the units of the supplied coordinates;
they are not automatically micrometres or spot spacings.

## Outputs and interpretation

SIGMA stores the fitted tissue field, interface coordinate, ranked ions and
programme summaries in `AnnData` and downstream tables. The continuous contour is
stored in `uns["sigma_coordinate"]["segments"]`; `sigma_boundary` remains the
neighbour-based display mask. Raw data and manuscript fitting caches are not bundled.

Use independent measurements or specimens to validate biological interpretations.
RNA used in fitting provides context rather than independent validation of the same
model. A static signal's spatial extent is not a physical diffusion length or an
invasion distance.

## Documentation and source

- [Input format](https://github.com/Elsa-bingxue/SIGMA/blob/main/docs/input_format.md)
- [Workflows and reproducibility](https://github.com/Elsa-bingxue/SIGMA/blob/main/docs/workflows_and_reproducibility.md)
- [Source repository](https://github.com/Elsa-bingxue/SIGMA)
- [Issue tracker](https://github.com/Elsa-bingxue/SIGMA/issues)

The source distribution includes `docs/installation.md`, `docs/continuous_distance.md`,
`docs/output_schema.md`, examples, regression tests and `CHANGELOG.md` for this release.
