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.11):

conda create -n spotiflow python=3.9
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=11.8 -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)

See the example training script or the example notebook for an example of training. For finetuning an already pretrained model, please refer to the finetuning example notebook.

Training (3D volumes)

See the example 3D training script. 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.

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.4.0.tar.gz (10.6 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

spotiflow-0.4.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.4.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 Windows x86-64

spotiflow-0.4.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.4.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.9 Windows x86-64

spotiflow-0.4.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.4.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.4.0.tar.gz.

File metadata

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

File hashes

Hashes for spotiflow-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4f8296094a18902eff6c6423a0c9bef7eb7ff194b5d5add014a18e3ca11e906c
MD5 1dd69116b913fa4285d16202bff6acc0
BLAKE2b-256 fd4b40b3573aad5b7d5ded26caabf254335a162fcadf3897739925f4b143506f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4e81f7bce220799599dfac2c38cb74925ca168b99f9f56cc4a8cb19ce73c491c
MD5 a7f6c18981f1b31b61b51efad67b5f82
BLAKE2b-256 13171738ce54e7853a08707f3b2134e3bb862700321ac612f5f68ce0ae13117e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 759d39fced55a234e540bba58f58c7efda1442db9ba5eee4062b89f02aa2e376
MD5 aec453763ad424c44c3f3d27d2f8d5bc
BLAKE2b-256 68fbab3d0faa5ff8b2c7ac9494b3769170b82184b7731dc81e480578a4524dbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ff9eca3ee03c418377815d4e66ca0ac2834e1b951d8436a39d6afc84858b6e65
MD5 c3dea36036a76d8f6d57d98cceb692e5
BLAKE2b-256 285d9f6b72d7ba180d9c9bee2320a490ff34d1b2df44985804439b3596667e6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b8f9e4b0c12f58993fdb42ce33f4fbbc7ffc4d07a307b99282f4e944a43a5997
MD5 c217f41d0b4c3a1e26adc1ff8e2da6fe
BLAKE2b-256 2e43460bb580f6d97f3904325ab1e68f3de256878990c4ac52b7c349b4123944

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c1a10bbe14ac3783d9f36984b89be142c12cb9f65e9e8f9e3490155cb4969c4
MD5 5a9118cd50a0d4c448bbf5c9398be9d5
BLAKE2b-256 c7bd81802536366a9c8e87c32d662774be2a8eaa5237cc401085ec3e08d9e83d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c869130d08a4533fa77b6462a165a732dc2c4369e63d0a59d97db60909c24821
MD5 1752002b68fde74c7643fccff0f4f6bb
BLAKE2b-256 b2fca78190ccb4835a66597d99d84a5ab21c42e3b2b24b0b8855124570003dff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spotiflow-0.4.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.0 CPython/3.12.5

File hashes

Hashes for spotiflow-0.4.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d1a345707c72efa7cb65a52eb8b5e4a10304e70cdd92c66c8b23dddebdea82d5
MD5 5010bc6639da9c4cf41525ae61bac2aa
BLAKE2b-256 9f176b14498b98ccf4095ff9402f723d1a74106d5a9009758c8afbc33eef7f3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e818f243ba7b420091ed51b5bb6aec6d8ae3f651173d1b343f0e19dd6461fbb2
MD5 9c9495edcd6bb507c0431e6ccedec9d1
BLAKE2b-256 88a0fc0ec84a36e04d7dd87262509c204c5f9236764920be8750ef9d463abe4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97fd74fe8eef75080e8841463d26c9050879c02bd4ad56154088c01fbc832049
MD5 7560b4e539972f27d5920cac3ab8f6f3
BLAKE2b-256 f2c52df760814b3b4b10a851be19e27434e4bdd0d76dca5b317f37f521f1100b

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