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)

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.

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

spotiflow-0.4.5-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.4.5-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.9 Windows x86-64

spotiflow-0.4.5-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.5-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.5.tar.gz.

File metadata

  • Download URL: spotiflow-0.4.5.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.4.5.tar.gz
Algorithm Hash digest
SHA256 839a1344dfcfa78f1465498205a891bccd81cfbfa289392f261d73d7754f3f0e
MD5 02a633cdc61bd8f6dfe9999a765a8508
BLAKE2b-256 41fe5a0f49a9fa1eb78940a9f19cb51793c9a2f8e6bd8f54586328d6737708cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9c41bfabf1efd6473a05429c7e62ebe1861628c7bd4616a88002c2bcd97edcd3
MD5 fe4ef03035bb579d2f5f05d8f379a8ae
BLAKE2b-256 84fed38a31674ede342c516c3d2ec5f294ee8c91aa96fd9e1613b776a3ddd990

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9fcfd5dc11a722fda293ab0498d2cd41d196639a1932317d21c20fd0b0ca362
MD5 2776eebdd54d4d48c26ab059a1089a6f
BLAKE2b-256 e44d58a18e231fcb41a2293e5d36a612a821bad8dccd01a4619187f831e45a04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b137a64bb0144f319716ac60507225984ed9a9204bf55c5c7f494113ff0e0571
MD5 cdd2ebfa702c3cb8cacc805e27dc04b0
BLAKE2b-256 f912344462c5d79d28e21ce00cd0d41ffe4712aa05d32d5078806e6a03b2e1e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 32f0a8427b74954ffa12d4414a3ef21791347cf308e4cdda45c77b9bbfe34052
MD5 7f47d65514e1e980b33822768aad51f1
BLAKE2b-256 387168874a25dd2bbfe9a1b4831af0cb759ce0e53f9496c3cec4be43bdb1e98c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea5796c4cc2f3b239d07e5eae8eeab452fc37c3ca173094856f0b0c876c0fb6e
MD5 3c18063c84d86ae028dedc502378d17c
BLAKE2b-256 2d1c3e58f84d592a3fffc1c367d6dd280c1e70faf956cb13284e99588a4df812

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d315d8c92269064208582bcc3928632b2ce2a8231d6207ec2abe5a5bc79b640
MD5 329409cb5e2051181ea3d13e123c7e5b
BLAKE2b-256 e5071295f01729f7f27f985373f28b6167118af7fb1f99ab586b9b6cbe13b70d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3ec81c9e6fd9d6cfeb40cf4eaaf2bc50ceb7f8d68271b9fa2ffd2676ddce50aa
MD5 361f40831e0b61fd166a75b9ba598042
BLAKE2b-256 b2dce91a805614407907457c1c2e3fdd4cf395b389fcfbaae74f6cde0f1eefed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f559df5bb609f99b97ff2a461e9d822c3bd4bac846579a69e2ba5037f59db34
MD5 b8ddfc25d7208baeb8e6244d53424ab2
BLAKE2b-256 6001dd713ba5baceca262a419d88e46627a23516ad78992632e518b3e71bdc8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4bd98f044d81018d6e4212a03f171ae3448415905338c2c2348a7b523628783a
MD5 8c6a478ed72f232b1bf8ed1732c88104
BLAKE2b-256 b0de8bb171021cacd2050eb07f4d118644328b3a3bcc2c8be5992771b6de445b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spotiflow-0.4.5-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.4.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 327f101d63dac1be1b8be3dc761135ec7e018e2b99010799c27ced780e91d5a9
MD5 9defac2b4dc9a920c753e2b0214ca05d
BLAKE2b-256 12a8cecb11e1aed0d7f56a0c7011dcc0a6ffeb4579cd856fbb85d028c6b7fb5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac1e88ebe00732fe77ed30b876f2f99ed7fdd05a9dd20ed65ec8890cf665a976
MD5 392fb3b81dc0a2cdb52c4c7c8b3d1b1c
BLAKE2b-256 fe41e36cb2392d022dec2ce9644929bf60f06b91f78a755306d2fa7735fc3b28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spotiflow-0.4.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe659f1237040afb425026722724b09997d53f4db90a3e3aee68b960f310f9e2
MD5 023741fa571c412938990e0ffa5f0667
BLAKE2b-256 c7d46fde3dcab1a116f7520a2a1ad857337fde0d6193e6e5d41a3f8907e447af

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