Metadata-Version: 2.4
Name: scomv
Version: 0.1.6
Summary: Spatial omics analysis tools for cell/gene clustering from a standard region
Author-email: Ryosuke Nomura <nomubare123@g.ecc.u-tokyo.ac.jp>
Maintainer-email: Ryosuke Nomura <nomubare123@g.ecc.u-tokyo.ac.jp>
License: MIT
Project-URL: bugs, https://github.com/RyosukeNomural/scomv/issues
Project-URL: changelog, https://github.com/RyosukeNomural/scomv/blob/master/changelog.md
Project-URL: homepage, https://github.com/RyosukeNomural/scomv
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: adjustText
Requires-Dist: anndata==0.10.5.post1
Requires-Dist: dask==2024.8.0
Requires-Dist: dask-expr==1.1.10
Requires-Dist: fsspec==2023.6.0
Requires-Dist: geopandas==1.0.1
Requires-Dist: hdbscan
Requires-Dist: llvmlite<0.44,>=0.41.1
Requires-Dist: matplotlib
Requires-Dist: numba<0.61,>=0.58.1
Requires-Dist: numcodecs==0.12.1
Requires-Dist: numpy==1.26.4
Requires-Dist: ome-zarr==0.10.2
Requires-Dist: opencv-python==4.11.0.86
Requires-Dist: pandas==2.3.0
Requires-Dist: plotly
Requires-Dist: pyogrio==0.11.0
Requires-Dist: scanpy==1.11.3
Requires-Dist: scikit-bio==0.7.0
Requires-Dist: scikit-learn==1.7.2
Requires-Dist: scipy<1.16,>=1.11.4
Requires-Dist: seaborn
Requires-Dist: shapely<2.3,>=2.0.7
Requires-Dist: spatialdata==0.2.5.post0
Requires-Dist: squidpy==1.6.1
Requires-Dist: stlearn==1.2.2
Requires-Dist: tblib==3.1.0
Requires-Dist: tensorflow==2.16.2; python_version >= "3.11" and platform_system == "Darwin" and platform_machine == "x86_64"
Requires-Dist: tensorboard==2.16.2; python_version >= "3.11" and platform_system == "Darwin" and platform_machine == "x86_64"
Requires-Dist: tensorflow==2.17.1; python_version >= "3.11" and (platform_system != "Darwin" or platform_machine != "x86_64")
Requires-Dist: tensorboard==2.17.1; python_version >= "3.11" and (platform_system != "Darwin" or platform_machine != "x86_64")
Requires-Dist: tensorboard-data-server==0.7.2
Requires-Dist: tensorflow-io-gcs-filesystem==0.37.1
Requires-Dist: streamlit>=1.35
Requires-Dist: streamlit-authenticator>=0.4
Requires-Dist: pyyaml
Requires-Dist: tqdm
Requires-Dist: typer
Requires-Dist: xarray==2024.7.0
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: ruff; extra == "test"
Requires-Dist: ty; extra == "test"
Requires-Dist: ipdb; extra == "test"
Dynamic: license-file

# SpatialCompassV <img src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/logo.png" width="240" align="middle" alt="SCOMV logo"/>

![PyPI version](https://img.shields.io/pypi/v/scomv.svg?dummy=99)
[![Documentation Status](https://readthedocs.org/projects/spatialcompassv/badge/?version=latest)](https://spatialcompassv.readthedocs.io/en/latest/?badge=latest)


Spatial omics analysis tools for cell/gene clustering from a astandard region

* PyPI package: https://pypi.org/project/scomv/
* Free software: MIT License
* Documentation: https://spatialcompassv.readthedocs.io


## Overview of the SpatialCompassV (SCOMV) Workflow

The overall workflow of **SpatialCompassV (SCOMV)** is summarized as follows:

- **Extraction of a reference region**  
  A reference region (e.g., a tumor region) is identified using the **[SpatialKnifeY (SKNY)](https://github.com/shusakai/skny)** algorithm.

### Vector construction from spatial grids

<table border="0" style="border-collapse: collapse; border: none;">
  <tr>
    <td style="vertical-align: top; padding-right: 14px; border: none;">
      The AnnData object is discretized into spatial grids, and for each grid,
      the shortest-distance vector to the reference region is computed.
    </td>
    <td style="vertical-align: top; width: 200px; border: none;">
      <img width="200" alt="vector"
           src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/vector.png" />
    </td>
  </tr>
</table>

<table border="0" style="border-collapse: collapse; border: none;">
  <tr>
    <td style="vertical-align: top; padding-right: 14px; border: none;">
      This vector information is stored for each cell/gene and projected onto a
      <b>polar coordinate map</b>.
      The horizontal axis represents distance, and the vertical axis also represents distance. 
      Distances are defined as negative for locations inside the reference region.
    </td>
    <td style="vertical-align: top; border: none;">
        <img
          alt="polar_map"
          src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/polar.png"
          style="width:800px; height:auto; display:block;"
        />
    </td>
  </tr>
</table>

<table border="0" style="border-collapse: collapse; border: none;">
  <tr>
    <td style="vertical-align: top; padding-right: 14px; border: none;">
      A <b>uniformity</b> score is also computed for each distance bin, measuring how
      evenly a cell type or gene surrounds the reference region across all angular
      directions. High uniformity indicates a symmetric, ring-like distribution, while
      low uniformity means the signal is concentrated on one side.
    </td>
    <td style="vertical-align: top; border: none;">
      <img
        alt="uniformity"
        src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/uniformity.png"
        style="width:1000px; height:auto; display:block;"
        />
    </td>
  </tr>
</table>


<table border="0" style="border-collapse: collapse; border: none;">
  <tr>
    <td style="vertical-align: top; padding-right: 14px; border: none;">
      A <b>similarity matrix</b> is then constructed, followed by <b>PCoA and clustering</b>,
      to classify spatial distribution patterns.
    </td>
    <td style="vertical-align: top; border: none;">
      <img
        alt="PCoA"
        src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/pcoa.png"
        style="width:800px; height:auto; display:block;"
        />
    </td>
  </tr>
</table>



### Additional functionality
- Gene distributions can also be visualized as **3D density maps**, allowing direct comparison of the spatial distributions of two genes.
<p>
  <img src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/images/overview.png"
       alt="overview"
       width="700"/>
</p>





## Installation

### Stable release

To install SpatialCompassV, run this command in your terminal:

```sh
pip install scomv
```

### From source

The source files for SpatialCompassV can be downloaded from the [Github repo](https://github.com/RyosukeNomural/SpatialCompassV).

You can either clone the public repository:

```sh
git clone git://github.com/RyosukeNomural/SpatialCompassV
```

Once you have a copy of the source, you can install it with:

```sh
cd SpatialCompassV
pip install .
```


## Test Dataset & Quick Start

This repository includes a small example dataset — a 10x Genomics Xenium
human breast cancer FFPE section, from the
[10x Genomics Xenium Human Breast Cancer preview dataset](https://www.10xgenomics.com/jp/products/xenium-in-situ/preview-dataset-human-breast) —
under [`docs/tutorials/tutorial_data/`](https://github.com/RyosukeNomural/SpatialCompassV/tree/main/docs/tutorials/tutorial_data),
so SCOMV can be run end-to-end without downloading anything separately.

Open any of the tutorial notebooks below in Jupyter; each one loads the test
dataset above and runs a full SCOMV pipeline on it:

```bash
git clone https://github.com/RyosukeNomural/SpatialCompassV.git
cd SpatialCompassV
jupyter notebook docs/tutorials/gene_analysis/index.ipynb   # or cell_analysis / tumor_solid_analysis
```

For full step-by-step instructions, parameters, and expected intermediate
results, see the tutorials: https://spatialcompassv.readthedocs.io/en/latest/tutorials.html

**[Tumor Clustering based on Uniformity](https://github.com/RyosukeNomural/SpatialCompassV/blob/main/docs/tutorials/tumor_solid_analysis/index.ipynb)**
— input: `tutorial_data/xenium_data/` + `cell.xlsx` → output: tumor "solid" region clusters by immune-cell uniformity

<img src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/docs/_static/images/tumor_solid_analysis.png" width="320" alt="tumor_solid_analysis example output"/>

**[Cell Distribution Clustering](https://github.com/RyosukeNomural/SpatialCompassV/blob/main/docs/tutorials/cell_analysis/index.ipynb)**
— input: `tutorial_data/xenium_data/` + `Cell_Barcode_Type_Matrices.xlsx` → output: cell-type groupings by distance-to-tumor pattern

<img src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/docs/_static/images/cell_analysis.png" width="320" alt="cell_analysis example output"/>

**[Gene Distribution Clustering](https://github.com/RyosukeNomural/SpatialCompassV/blob/main/docs/tutorials/gene_analysis/index.ipynb)**
— input: `tutorial_data/xenium_data/` → output: gene clusters by spatial distribution pattern

<img src="https://raw.githubusercontent.com/RyosukeNomural/SpatialCompassV/main/docs/_static/images/gene_analysis.png" width="320" alt="gene_analysis example output"/>


## Supplementary Analysis

Supplementary analysis notebooks supporting the paper are kept in
[`supplementary/`](https://github.com/RyosukeNomural/SpatialCompassV/tree/main/supplementary),
separate from the package tutorials above. This currently includes
[`lung_cancer_panel.ipynb`](https://github.com/RyosukeNomural/SpatialCompassV/blob/main/supplementary/lung_cancer_panel.ipynb),
which reproduces the paper's two-stage gene clustering (PCoA + density ratio, then PCoA +
uniformity) on a lung cancer Xenium panel. Note that the underlying dataset for this
notebook is unpublished and not included in this repository.

[`breast_cancer_morans_i.ipynb`](https://github.com/RyosukeNomural/SpatialCompassV/blob/main/supplementary/breast_cancer_morans_i.ipynb)
computes Moran's I and Geary's C spatial autocorrelation for genes within a given field of
view of the breast cancer test dataset and plots the top genes for each statistic.


## Credits

This package was created with [Cookiecutter](https://github.com/audreyfeldroy/cookiecutter) and the [audreyfeldroy/cookiecutter-pypackage](https://github.com/audreyfeldroy/cookiecutter-pypackage) project template.
