Metadata-Version: 2.4
Name: tysserand
Version: 1.0.0
Summary: Fast and accurate spatial networks reconstruction.
Author-email: Alexis Coullomb <alexis.coullomb.pro@gmail.com>
License: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/VeraPancaldiLab/tysserand
Project-URL: Documentation, https://tysserand.readthedocs.io
Project-URL: Changelog, https://github.com/VeraPancaldiLab/tysserand/blob/main/CHANGELOG.md
Project-URL: Paper, https://doi.org/10.1093/bioinformatics/btab490
Keywords: spatial networks,bioimage,spatial omics,sociology,econometrics
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: joblib
Requires-Dist: scikit-learn
Requires-Dist: pynndescent
Requires-Dist: scikit-image
Requires-Dist: opencv-python-headless
Requires-Dist: matplotlib
Requires-Dist: seaborn
Provides-Extra: napari
Requires-Dist: napari[all]; extra == "napari"
Provides-Extra: interop
Requires-Dist: networkx; extra == "interop"
Requires-Dist: igraph; extra == "interop"
Requires-Dist: anndata; extra == "interop"
Provides-Extra: notebooks
Requires-Dist: ipykernel; extra == "notebooks"
Requires-Dist: scanpy; extra == "notebooks"
Requires-Dist: cairocffi; extra == "notebooks"
Requires-Dist: libpysal; extra == "notebooks"
Requires-Dist: geopandas; extra == "notebooks"
Requires-Dist: pyarrow; extra == "notebooks"
Provides-Extra: all
Requires-Dist: tysserand[interop,napari,notebooks]; extra == "all"
Dynamic: license-file

# tysserand

Fast and accurate spatial networks reconstruction.

![](./images/tysserand_main_figure.png)

*tysserand* is a Python library to reconstruct spatial networks from spatially resolved omics experiments. It is intended as a common tool where the bioinformatics community can add new methods to reconstruct networks, choose appropriate parameters, clean resulting networks and pipe data to other libraries.  
You can find the article and supplementary information on [Bioinformatics](https://doi.org/10.1093/bioinformatics/btab490), and the freely available preprint (same text!) is on [BioRxiv](https://www.biorxiv.org/content/10.1101/2020.11.16.385377v2).  
A tutorial is available [here](./examples/02-tutorial.ipynb).  
📖 **Documentation:** [tysserand.readthedocs.io](https://tysserand.readthedocs.io) · 📝 [Changelog](https://github.com/VeraPancaldiLab/tysserand/blob/main/CHANGELOG.md)

*tysserand* is fast: it is 50 to more than 120 times faster than PySAL.  
*tysserand* is accurate: it implements the best performing methods, tested on simulated and real bioimages.
*tysserand* is user friendly and interactive: it integrates tools to choose appropriate parameters and facilitates the use of napari-based interactive image visualization and network annotation.
*tysserand* is modular and opened to contributions: if you have an idea on how to improve reconstruction methods, create a particular one for a specific case, or make them even faster, join us!

## Installation

Simply do
```bash
pip install tysserand
```
If you want the latest features not published on PyPI run
```bash
pip install git+https://github.com/VeraPancaldiLab/tysserand.git
```

Optional dependencies are grouped in extras: `napari` (interactive visualization and annotation), `interop` (NetworkX, iGraph and AnnData bridges), `notebooks` (Jupyter tutorials and publication figures, including PySAL), or `all`:
```bash
pip install "tysserand[all]"
```

For development, the environment is managed with [uv](https://docs.astral.sh/uv/):
```bash
git clone https://github.com/VeraPancaldiLab/tysserand.git
cd tysserand
uv sync --extra all   # creates .venv with tysserand installed in editable mode
uv run pytest -q tests
# add the environment to jupyterlab
uv run python -m ipykernel install --user --name=spatial-networks
```


## Implemented methods

![Set of nodes](./images/publication_figures/mIF-nodes_positions.png)

### Delaunay triangulation

This method builds virtual cells centered arround each node and contacting each other to fully tile the space occupyied by the nodes. Edges are drawn between the nodes of contacting tiles. The `node_adaptive_trimming` option can infer a better distance threshold to discard edges for each individual node.

![Edge lengths with *Delaunay* reconstruction](./images/publication_figures/mIF-Delaunay_distances.png)  
![Trimmed network](./images/publication_figures/mIF-Delaunay_network.png)  
![Network overlay on original tissue image](./images/publication_figures/mIF-Delaunay_superimposed.png)  

### k-nearest neighbors

Each node is linked with its k nearest neighbors. It is the most common method used in single cell publications, althought it produces artifacts well visible on simple 2D networks.

![Edge lengths with *k-nearest neighbors* reconstruction](./images/publication_figures/mIF-knn_distances.png)

### radial distance neighbors

Each node is linked to nodes closer than a threshold distance D, that is to say each node is linked to all nodes in a circle of radius D.

![Edge lengths with *radial distance neighbors* reconstruction](./images/publication_figures/mIF-rdn_distances.png)

### Area contact

Nodes are the center of detected objects (like after cell segmentation) and they are linked if their respective areas are in contact or closer than a given distance threshold.  
A parallelized version is implemented with joblib.

![*Contacting areas* reconstruction](./images/publication_figures/simulated_segmentation_image_size-600_hole_proba-0.1_noise_sigma-10.0_objects_network.png)

### Area contact *and* k-nearest neighbors

Areas are linked if they are in contact or closer than a given distance. Then, the remaining non connected areas are connected with their nearest neighbors.
