Skip to main content

3D fluorescent puncta detection for microscopy z-stacks.

Project description

SNAPpy

SNAPpy detects fluorescent puncta in 3D microscopy z-stacks. It uses a two-stage workflow:

  1. Stage 1 finds candidate puncta with LoG or h-max local-maximum detection.
  2. 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:
  xy_spacing_nm: 128.866  # replace if your xy pixel spacing differs
  z_spacing_nm: 300.0     # replace if your z-step spacing differs

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 a 3D TIFF. Each same-stem CSV must contain x, y, and z columns in voxel coordinates.

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 by mrsnappy 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:

  1. Read the 3D TIFF stack.
  2. Optionally subtract background.
  3. Normalize the image, usually by robust z-score.
  4. Optionally smooth the image for Stage 1 detection.
  5. Find candidate puncta with LoG or h-max local maxima.
  6. Fit local Gaussian-style models around candidates.
  7. Measure intensity, sigma, fit-quality, contrast, morphology, and distortion features.
  8. Use the optimized SVM and threshold to keep likely true puncta.
  9. 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

mrsnappy-0.3.0.tar.gz (91.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrsnappy-0.3.0-py3-none-any.whl (67.2 kB view details)

Uploaded Python 3

File details

Details for the file mrsnappy-0.3.0.tar.gz.

File metadata

  • Download URL: mrsnappy-0.3.0.tar.gz
  • Upload date:
  • Size: 91.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mrsnappy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 943c0ae20578ace966cde2330de27bdfb0b4a34229e795df74eb27aba2fb1b98
MD5 72e7159409f3deed3893a255f46f1795
BLAKE2b-256 a6b663d8c3f98b9091835b91382cf34360fdb86e4acb09aaf0404cd57cad12e0

See more details on using hashes here.

File details

Details for the file mrsnappy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mrsnappy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 67.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mrsnappy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6bd7642b0427c210d0b21ecb1a9a4224521e048d76b8b6559961f7ee3b31bee
MD5 d145d607fe38be6f8106f2125d645f66
BLAKE2b-256 1ac2a5e192cdab3219e7be43157846a2432d6fd93f72893f6a4f2a6fe9430dfd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page