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, and subpixel-accurate 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. A more detailed description of the method can be found in our paper.

Overview

The documentation of the software can be found here.

Installation

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

Usage

Training

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.

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.

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 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 = {Albert Dominguez Mantes and Antonio Herrera and Irina Khven and Anjalie Schlaeppi and Eftychia Kyriacou and Georgios Tsissios and Can Aztekin and Joachim Ligner and Gioele La Manno and Martin Weigert},
	title = {Spotiflow: accurate and efficient spot detection for imaging-based spatial transcriptomics with 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.3.3.tar.gz (10.4 MB view details)

Uploaded Source

Built Distributions

spotiflow-0.3.3-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

spotiflow-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

spotiflow-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

spotiflow-0.3.3-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

spotiflow-0.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

spotiflow-0.3.3-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

spotiflow-0.3.3-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

spotiflow-0.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

spotiflow-0.3.3-cp39-cp39-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spotiflow-0.3.3.tar.gz
Algorithm Hash digest
SHA256 d3faf71ab15f3eef65404489983ce48a4bc094212896ea97274bf970dafc2eb8
MD5 0b88395b03ce2ff6eb775d7422921fe2
BLAKE2b-256 541bcee1ff1bab31b7f76d3db4f388d75922c6b5dfd60b0d052bb0f7f733518c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 84415200397eb4107e5030ec01e8a7673a24eaf72721d033407a7edabf1f7058
MD5 72481eba729b443be1b7d99f5ef2ecd4
BLAKE2b-256 8d9beb837d7f1316c2df36ff21422586fc40b040314c29b8e0db6c3173e73e5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 904329cffabfb35c69dfc456045817c252fa13642eafbb3094075508e056ccba
MD5 a941d48bef8876c758a3e14b730bdd9f
BLAKE2b-256 95edd8c02b48a11441a51bbd86eae35d05afa1b06cb6205d33f4d0ba55b57b56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c1e581174074067343cd2fc714a604e27dbcb6153140f0ad9eea8942257cc3d
MD5 33481e3142477f2167b075fa9c4bfa42
BLAKE2b-256 e4a2790c21cb9d724149ac4d67cc6e78a0694fa0efdc9dcb34c79f49588972af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 14eb867366aabc5be59aa370bb3ad9ac515e70e6c0bfffb5f118dfbd86c0c26e
MD5 7eb57e9bad8615a05c56c323460c8e9c
BLAKE2b-256 18b306418f2ebd3052a3e47487508c3caf994fe5a41d7be09cece3d2d989300b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d55a0fe3ef5da1c51a43d8c7c7f7686ab71f1e18dd805f4744d92bcdfe575a3e
MD5 f557d38def65ba0e0840297d1b3a8ee6
BLAKE2b-256 16d900c52b8f0815e5cd0983742c445ee734caabc9e3a0352bae03e66ec7ab9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d6a8eebe148d7d869dfc43607f9591124b0f8c2508a88e312fd6c060ddb1bab
MD5 59fc89b37876c7e25b1b3f83feac4714
BLAKE2b-256 32759ed4d6194a5bea403667372d1010f9b058f5a79d389185da4fc21388617c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spotiflow-0.3.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for spotiflow-0.3.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 696c2fa531d8fe4f1e74050732de5915928b6bfaf79e50ea0004ca2bc32e7bed
MD5 800828b0cd7470d41ad27d4a0a3467b0
BLAKE2b-256 0fc52b3de79044d40adf3bd47ec9e72499420f1e446535b18521a0bf76de9e1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6eca55e0b71597df295c9354496495cf0f012d0514fc88a855779af367b976db
MD5 1b0c598177d410018c61933842e65482
BLAKE2b-256 8ab16f3dffa825250c5cb66c7efc47f99c9276669af106a1de45bf0a706a8a80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.3.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 46b5a9ddc97ebd3f75d74b3e858994895ae019514f1e58746739ade4e4cc4a44
MD5 24b3c82f6975e340be721c94ebf4392d
BLAKE2b-256 56a0b429969534bb463329d7b6ce4fe045c85a9629d30c069203b2022c803690

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