Accurate and efficient spot detection for microscopy data
Project description
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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file spotiflow-0.4.1.tar.gz
.
File metadata
- Download URL: spotiflow-0.4.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb153964fdb594b8a670b71baa2a9b1e8c7fc6818c75a3aaa608416a58cb0abc |
|
MD5 | 297927e7eff41d170c0e2613fba080a3 |
|
BLAKE2b-256 | bea907c6acbf9783d878961f9f7063ca03ec1f89e31256a0b052dcd9508c0b48 |
File details
Details for the file spotiflow-0.4.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4fe0ff10987520a6317d60870a766ba6200e3b7403cf25e535916c039f466ce |
|
MD5 | cc0c6bd4a8f1b3acb8a0045a03d8581c |
|
BLAKE2b-256 | 451a231a5209b3cf2b7df2e1d3f5ba66e341f245d95fef0e0931ef4b53d3e8ce |
File details
Details for the file spotiflow-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c967fae84499c08a9bfd285f43bb47e2206e231cf33640dbc2e288e5eae5a73e |
|
MD5 | 22ccfb580b05aab7b046a31e650e79bd |
|
BLAKE2b-256 | d6e8555b42cab2279d2229689042e71c08983911e1f23e7674010b74d7a6d174 |
File details
Details for the file spotiflow-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b866625c8f28e5d81719451225bb77c4fa663a3785720403d28f5167575e154 |
|
MD5 | ffce8ee4cdaf369f18319d7600d1168f |
|
BLAKE2b-256 | e06717e1a68a17290d9ad21aed0ac655f2de0931abee69090b2d92bc757f2ea3 |
File details
Details for the file spotiflow-0.4.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a0c0f432138f6745b03a4c10ad313ad575de99d71c00a4bd5699be7676156f5 |
|
MD5 | bf072bbbc85f190720e63b450fd4b990 |
|
BLAKE2b-256 | a0a26c1a2024b3aa2bd00f150acde85b2df2e64a0ef717c2f3c90a915dc41c8c |
File details
Details for the file spotiflow-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac2788b4ec5363216c864520f0a1c179c83a2c3bbd7149933a71ede98b08ee45 |
|
MD5 | 6342cb3a04b25ec364bf9150af2bd583 |
|
BLAKE2b-256 | b94792263ce04211ce99adf02ae0551bfe9da026828a0402322589af8a8f0239 |
File details
Details for the file spotiflow-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bc09a6a6f2d28b5a10bbfc2a721dc2cb28ecc26350fe0b9e2ca5e4a3b9256d6 |
|
MD5 | f05d947fe585dc3d45dcaa206e53f5f1 |
|
BLAKE2b-256 | dd80d648e48a44b06fd71782204385a0448c6308e93a5ae230bbfe1fc29ff91e |
File details
Details for the file spotiflow-0.4.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9adb7bcf9abf16459e282ce03ccbd6ada3bfdce8f1f7d14518526e3bfaab12b6 |
|
MD5 | d261a7f8cd354ff39d2a8d8a11a9cd42 |
|
BLAKE2b-256 | 7e99a77fd14bca5b3df9c9cd02c9345ec10fae1058ec2417af00ef6d49ea66e7 |
File details
Details for the file spotiflow-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a478db6f087ba680a7222568bb2b4a5d7787353df95168ecfbeb146a4124579 |
|
MD5 | 4e39a5393d233ce21a4dd8898c338b9c |
|
BLAKE2b-256 | 087485a3389123fb2d4aa1594ef94852283a9e8068a26e117884f58a07c2a2f2 |
File details
Details for the file spotiflow-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: spotiflow-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00b45725cba8285d635aafa1f550d1865d97af6ba6f40ae64d7f16ce9e41ab23 |
|
MD5 | 19ec92fdb28c9b4fa950bdebb63f8b5a |
|
BLAKE2b-256 | 704af8cb7a856ae64aa0c09a0fa7c24617d5a7817d068f957fed822331306107 |