Fluorescent puncta detection for 2D microscopy images and 3D z-stacks.
Project description
SNAPpy
SNAPpy detects fluorescent puncta in 3D microscopy z-stacks and native 2D microscopy images. It uses a two-stage workflow:
- Stage 1 finds candidate puncta with LoG or h-max local-maximum detection.
- Stage 2 fits each candidate, measures interpretable local features, and uses an SVM to remove false candidates.
SNAPpy does not ship with trained model files. First optimize a model from labeled images, then use that model.joblib file to detect puncta in new images.
Names
| Name | Meaning |
|---|---|
SNAPpy |
Project and repository name |
mrsnappy |
PyPI package, Python import, and terminal command |
The PyPI name snappy is already used by an unrelated project, so this package uses mrsnappy.
Install
Install the current GitHub version:
python -m pip install "git+https://github.com/marcorojas-cessa/SNAPpy.git"
Or install the latest PyPI release:
python -m pip install mrsnappy
Check the command:
mrsnappy --help
For development:
git clone https://github.com/marcorojas-cessa/SNAPpy.git
cd SNAPpy
python -m pip install -e ".[dev]"
pytest
SNAPpy is CPU-based and does not require a GPU.
Quick Start
Create an editable config:
mrsnappy init-config --output config.yaml
The default config is the benchmark-tested starting point used for the SNAPpy publication work: h-max candidate detection, physical-unit smoothing/background sweeps, a 300 nm candidate-to-label matching radius, and interpretable SVM feature packs. Before using it on other microscope data, confirm or replace the physical spacing values:
pipeline_defaults:
image_dimensionality: 3
xy_spacing_nm: 128.866 # replace if your xy pixel spacing differs
z_spacing_nm: 300.0 # replace if your z-step spacing differs
For native 2D images, set image_dimensionality: 2, set xy_spacing_nm,
and use fit_method: 2D Gaussian. In 2D mode z_spacing_nm is not required
and z-only Stage 2 features are omitted rather than filled with fake values.
Optimize a model from labeled training and validation images:
mrsnappy optimize \
--dataset-root /path/to/labeled_dataset \
--out-dir /path/to/model \
--config config.yaml
Detect puncta in one new image:
mrsnappy detect \
--model /path/to/model/model.joblib \
--input /path/to/image.tif \
--output /path/to/detections.csv
Detect puncta in a folder:
mrsnappy detect \
--model /path/to/model/model.joblib \
--input /path/to/images \
--output /path/to/detections
For folder input, SNAPpy writes one CSV per image using the image stem. For example, cell_A_003.tif becomes cell_A_003.csv.
Labeled Dataset Layout
mrsnappy optimize currently uses fixed-split optimization. The dataset root must contain train/ and val/ folders:
labeled_dataset/
train/
image_001.tif
image_001.csv
image_002.tif
image_002.csv
val/
image_101.tif
image_101.csv
Each image must be either a 3D TIFF or, with pipeline_defaults.image_dimensionality: 2, a native 2D TIFF. For 3D images, each same-stem CSV must contain x, y, and z columns in voxel coordinates. For 2D images, CSV labels may contain x,y, y,x, or axis-0,axis-1 style columns; internally SNAPpy stores 2D coordinates in image-axis order (y,x).
Detection CSVs are dimensionality-aware: 3D output uses x,y,z,score, while 2D output uses x,y,score.
SNAPpy uses train/ to fit the Stage 2 SVM. It uses val/ to choose Stage 1 settings, Stage 2 feature/SVM settings, and the final SVM decision threshold. Held-out test scoring should be done outside SNAPpy by running mrsnappy detect and comparing detections to test labels.
Optimize Outputs
Optimization writes:
model/
model.joblib
model_config.json
model_summary.md
optimization_splits.csv
model.joblib: trained model used bymrsnappy detect.model_config.json: machine-readable record of the exact config, selected model, selected features, validation metrics, Stage 1 shortlist, and near-tie Stage 2 finalists.model_summary.md: human-readable summary of the optimized model.optimization_splits.csv: exact train/validation image and label paths used during optimization.
Official SNAPpy intentionally keeps outputs compact. Benchmark-specific files such as per-image test metrics, resource metrics, localization offsets, or candidate-level audit tables should be produced by benchmark wrapper code, not by the core SNAPpy optimizer.
Detect Output
Detection CSV files contain:
detection_id,x,y,z,score
1,42.3,88.1,12.0,1.74
2,51.9,91.5,13.2,0.62
Coordinates are voxel coordinates. z is the stack axis.
How SNAPpy Works
The short version:
- Read the 3D TIFF stack.
- Optionally subtract background.
- Normalize the image, usually by robust z-score.
- Optionally smooth the image for Stage 1 detection.
- Find candidate puncta with LoG or h-max local maxima.
- Fit local Gaussian-style models around candidates.
- Measure intensity, sigma, fit-quality, contrast, morphology, and distortion features.
- Use the optimized SVM and threshold to keep likely true puncta.
- Write final detections.
See docs/workflow.md for the full method explanation and docs/cli_api.md for the complete command and config reference.
Documentation
Repository Scope
This repository contains the installable SNAPpy package, documentation, examples, and tests. Raw microscopy data, trained models, benchmark result trees, cluster logs, and manuscript files are intentionally excluded.
Citation
If you use SNAPpy in a publication, cite the associated manuscript once available.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mrsnappy-0.4.0.tar.gz.
File metadata
- Download URL: mrsnappy-0.4.0.tar.gz
- Upload date:
- Size: 100.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3ebc5d9e499dd4326e262dcf2f985a713ad0644818d91b78c7f9b3928709f30
|
|
| MD5 |
6157ebc2135bc5697e8cef0dbd49db12
|
|
| BLAKE2b-256 |
8658ffeab41c32c7f6ab770dd2ee82b3575459213d3395aac3b93b7e0a91cd47
|
File details
Details for the file mrsnappy-0.4.0-py3-none-any.whl.
File metadata
- Download URL: mrsnappy-0.4.0-py3-none-any.whl
- Upload date:
- Size: 71.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
557396581c8952d2723d689208c3d844631116d61f22d333e009f9075262ce5d
|
|
| MD5 |
d489fea21b30246e78fe420579bfa40f
|
|
| BLAKE2b-256 |
890f06036ff7ba997f97791b13c7c968f15d680873247a777b05ea1712e9686b
|