Skip to main content

Accurate and efficient spot detection for microscopy data

Project description

License: BSD-3 PyPI Python Version tests PyPI - Downloads

Logo

Spotiflow - accurate and efficient spot detection with stereographic flow

Spotiflow is a deep learning-based, threshold-agnostic, subpixel-accurate 2D and 3D spot detection method for fluorescence microscopy. It is primarily developed for spatial transcriptomics workflows that require transcript detection in large, multiplexed FISH-images, although it can also be used to detect spot-like structures in general fluorescence microscopy images and volumes. A more detailed description of the method can be found in our paper.

Overview

The documentation of the software can be found here.

Installation (pip, recommended)

Create and activate a fresh conda environment (we currently support Python 3.9 to 3.12):

conda create -n spotiflow python=3.12
conda activate spotiflow

Note (for MacOS users): if using MacOS, there is a known bug causing the installation of PyTorch with conda to sometimes break OpenMP. You can avoid installing PyTorch with conda and let spotiflow install it automatically via pip instead.

For Linux/Windows with a CUDA device, install PyTorch using conda/mamba (one might need to change the cuda version accordingly):

conda install pytorch torchvision pytorch-cuda=12.1 -c pytorch -c nvidia # Might need to change the cuda version accordingly

Note (for Windows users): if using Windows, please install the latest Build Tools for Visual Studio (make sure to select the C++ build tools during installation) before proceeding to install Spotiflow.

Finally, install spotiflow:

pip install spotiflow

Installation (conda)

For Linux/MacOS users, you can also install Spotiflow using conda through the conda-forge channel:

conda install -c conda-forge spotiflow

The conda package is, for now, not CUDA-compatible. We recommend using pip to install Spotiflow if available.

Usage

Training (2D images)

The CLI is the easiest way to train (or fine-tune) a model. To train a model, you can use the following command:

spotiflow-train INPUT_DIR -o OUTPUT_DIR

where INPUT_DIR is the path to the directory containing the data in the format described here and OUTPUT_DIR is the directory where the trained model will be saved. You can also pass other parameters to the training, such as the number of epochs, the learning rate, etc. For more information, including examples, please refer to the training documentation or run the command spotiflow-train --help.

For training with the API, please check the training example notebook. For finetuning an already pretrained model, please refer to the finetuning example notebook.

Training (3D volumes)

3D models can also be trained with the CLI by adding the --is-3d True flag, as shown below:

spotiflow-train INPUT_DIR -o OUTPUT_DIR --3d True

See the example 3D training script for an API example. For more information, please refer to the 3D training example notebook. Fine-tuning a 3D model can be done by following the same workflow as to the 2D case.

Inference (CLI)

You can use the CLI to run inference on an image or folder containing several images. To do that, you can use the following command:

spotiflow-predict PATH

where PATH can be either an image or a folder. By default, the command will use the general pretrained model. You can specify a different model by using the --pretrained-model flag. Moreover, spots are saved to a subfolder spotiflow_results created inside the input folder (this can be changed with the --out-dir flag). For more information, please refer to the help message of the CLI ($ spotiflow-predict -h).

Inference (Docker)

Alternatively to installing Spotiflow as command line tool on your operating system, you can also use it directly from our Docker container (thanks to @migueLib for the contribution!). To do so, you can use the following command:

To pull the Docker container from Dockerhub use:

docker pull weigertlab/spotiflow:main

Then, run spotiflow-predict with:

docker run -it -v [/local/input/folder]:/spotiflow/input weigertlab/spotiflow:main spotiflow-predict input/your_file.tif -o .

Where:
-v: represents the volume flag, which allows you to mount a folder from your local machine to the container.
/path/to/your/data:/spotiflow: is the path to the folder containing the image you want to analyze.

Note:

  • The current implementation of Spotiflow in Docker only supports CPU inference.

Inference (API)

The API allows detecting spots in a new image in a few lines of code! Please check the corresponding example notebook and the documentation for a more in-depth explanation. The same procedure can be followed for 3D volumes.

from spotiflow.model import Spotiflow
from spotiflow.sample_data import test_image_hybiss_2d

# Load sample image
img = test_image_hybiss_2d()
# Or any other image
# img = tifffile.imread("myimage.tif")

# Load a pretrained model
model = Spotiflow.from_pretrained("general")
# Or load your own trained model from folder
# model = Spotiflow.from_folder("./mymodel")

# Predict
points, details = model.predict(img) # points contains the coordinates of the detected spots, the attributes 'heatmap' and 'flow' of `details` contain the predicted full resolution heatmap and the prediction of the stereographic flow respectively (access them by `details.heatmap` or `details.flow`). Retrieved spot intensities are found in `details.intens`.

Napari plugin

Our napari plugin allows detecting spots in 2D and 3D directly with an easy-to-use UI. See napari-spotiflow for more information.

Available pre-trained models

We provide several pre-trained models that may be used out-of-the-box. The available models are: general, hybiss, synth_complex, synth_3d and smfish_3d. For more information on these pre-trained models, please refer to the article and the documentation.

Changing the cache directory

The default cache directory root folder (where pre-trained models and datasets are stored) is, by default, ~/.spotiflow. If you want to change it for your use case, you can either set the environment variable SPOTIFLOW_CACHE_DIR to the path you want or directly pass the desired folder as an argument (cache_dir) to the Spotiflow.from_pretrained() method (note that if the latter is chosen, the path stored in the environment variable will be ignored).

For developers

We are open to contributions, and we indeed very much encourage them! Make sure that existing tests pass before submitting a PR, as well as adding new tests/updating the documentation accordingly for new features.

Testing

First, clone the repository:

git clone git@github.com:weigertlab/spotiflow.git

Then install the testing extras:

cd spotiflow
pip install -e ".[testing]"

then run the tests:

pytest -v --color=yes --cov=spotiflow

Docs

Install the docs extras:

pip install -e ".[docs]"

and then cd into the docs folder of the cloned repository and build them:

cd spotiflow/docs
sphinx-build -M html source build

How to cite

If you use this code in your research, please cite the Spotiflow paper (currently preprint):

@article {dominguezmantes24,
	author = {Dominguez Mantes, Albert and Herrera, Antonio and Khven, Irina and Schlaeppi, Anjalie and Kyriacou, Eftychia and Tsissios, Georgios and Skoufa, Evangelia and Santangeli, Luca and Buglakova, Elena and Durmus, Emine Berna and Manley, Suliana and Kreshuk, Anna and Arendt, Detlev and Aztekin, Can and Lingner, Joachim and La Manno, Gioele and Weigert, Martin},
	title = {Spotiflow: accurate and efficient spot detection for fluorescence microscopy with deep stereographic flow regression},
	elocation-id = {2024.02.01.578426},
	year = {2024},
	doi = {10.1101/2024.02.01.578426},
	publisher = {Cold Spring Harbor Laboratory},
	URL = {https://www.biorxiv.org/content/early/2024/02/05/2024.02.01.578426},
	eprint = {https://www.biorxiv.org/content/early/2024/02/05/2024.02.01.578426.full.pdf},
	journal = {bioRxiv}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotiflow-0.5.0.tar.gz (10.6 MB view details)

Uploaded Source

Built Distributions

spotiflow-0.5.0-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12 Windows x86-64

spotiflow-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

spotiflow-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

spotiflow-0.5.0-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

spotiflow-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

spotiflow-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

spotiflow-0.5.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

spotiflow-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

spotiflow-0.5.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

spotiflow-0.5.0-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

spotiflow-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

spotiflow-0.5.0-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

File details

Details for the file spotiflow-0.5.0.tar.gz.

File metadata

  • Download URL: spotiflow-0.5.0.tar.gz
  • Upload date:
  • Size: 10.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for spotiflow-0.5.0.tar.gz
Algorithm Hash digest
SHA256 53d24eb49ba16525688a3a144f157bdab4fc8fe37cff236de4795db50894f984
MD5 902f4bb7c1309f852a4dee24609e3b84
BLAKE2b-256 e89989245617c2ceb780d8fd50d4b3845c60daa8786daaf0baf51be5ed81ac32

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ee25821c5c5c3d10e1fb7ccccdee15ed5ea3119c6dc053092120d27d98874f08
MD5 52e44a91a031c83808fd1379a64817f6
BLAKE2b-256 b850bab4c519bc50ff2abe151560c797c8d2b009da02040916f2864b30038cdd

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b3b8ff05029592418451c89f0b96460cd5cbfd81b8434d4db5c2c7cac4c40cf
MD5 6832a64447d22935462c48ad7d6ee850
BLAKE2b-256 eb0ef8acaec9eb88a00586aca341b66ed67b4ce61edaa163434d2aaf02a10773

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dc02d76cb911623f55cacad529736ef05964c8fb9f4039beeaf1d03afce8809f
MD5 a65f161cf484c29bc358138cd1248899
BLAKE2b-256 bd72a011cbffe8de2807aad4a0de9a39b88ac10a66e1ae6e01c2fdfceb29f551

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bf81d9a6c0af7bd37c61995fa42a2934e446545b1f9e97ef1a6e9cf90f9aa856
MD5 96a082a3ec3087abdba6579e45a84e60
BLAKE2b-256 ea6cc0cc0d8a95050fe3073a593b6167909b5d3d76a761616969e71242a2672a

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d256741f716b955b441617bb90472f49bfe35bce7cb28e6b5f47386aa27c3d6
MD5 8ea09d18c5e07f26ad0cf0ce3c71742b
BLAKE2b-256 d453f6063e63d2dba79c51d3a800e49dda8d920bb74cdc67461a604a421ccecd

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5dc05f324a14fa58a0e54cd4ac7913cd9bfcee6767dcbcb0ec4e6e3c2e55129
MD5 347d4627a507ed0b20f475a5bb5a45d4
BLAKE2b-256 e0296ca533f567773e0a70a74d57586e2d82f63ca4d9bf3bc6a884871f29f5ec

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2e22dce337fe437e9e67abb9e7fd181e7a66849fcd8a0b028b90b0a094df2497
MD5 d0e4275ce028a80c6179dff64ce7958e
BLAKE2b-256 6eb90af97d150e3bd412b0b1558ba4cbb94f7e04381edf70541fa1849b33e949

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f04cb84ebd2dc1391be4f0ad541821b6318f147ef57be414eba3e557b6aa303
MD5 380c11f7e8d0d423169e3b88150bd280
BLAKE2b-256 cfdcce379f4fba0ac0d9dfa9f64cc4868a6a846f3de3160bc5036ed1acb61923

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b89ea0090249f932cacbbb7cbf83e1ba1f0e146ddf7623e6c34226bf14fa0232
MD5 dd5f6b8100b1dbae0459e2d139b40610
BLAKE2b-256 2a8bec0f9bf9c56f9ab835f94b6b49f3299623bed6dc75505b36904598aa7a5c

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: spotiflow-0.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for spotiflow-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 954861734a588c3d4d6effa1f716486ff2c55d8efa38d186d5d29fcd3a5d01f2
MD5 d69db4090f53204fa87486a643471068
BLAKE2b-256 991e2157a78ce1b905c3b346fb32362d3b9584f83191bcc5fca2963d4b2b11ee

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32c5c280bf9bfe1a7aa59d17ed70984d7f967d334240bd74dfc3c524e38e3361
MD5 61a871cacab763dcd2c723357ff66b3f
BLAKE2b-256 8b8fdf8069d4b612280d9fcd06b936fade186cf8db10be124ef38b6eab614ea3

See more details on using hashes here.

File details

Details for the file spotiflow-0.5.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for spotiflow-0.5.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 02425b12052b5052f28ba5de4a4f32067492c7790b7cd13baba8d3cf1dee2ebb
MD5 a2cbc37cd3e311f076e4da0f6a194f42
BLAKE2b-256 19b33385533bffbe1bca30038a2fa756e881b005fb1235fd9082ff47c25d724c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page