Spyne is a Python package designed for advanced analysis and visualization of neuronal morphologies and dendritic spines calcium imaging data. 🧠🔬
spyne parses, processes, visualizes and analyzes calcium event data. It is tailored for working with comprehensive datasets from 2-photon microscopy collected using
Vidrio ScanImage software.
Choose the installation method based on your hardware setup:
# Clone and set up conda environment with GPU-enabled PyTorch/TensorFlow
git clone https://github.com/dcupolillo/spyne.git
cd spyne
conda env create -f environment.yml
conda activate spyne-env
# Install spyne
pip install -e .Prerequisites: You must have an NVIDIA GPU and appropriate CUDA drivers installed. See the NVIDIA CUDA Installation Guide for setup instructions. Ensure your CUDA version is compatible with the deep learning library versions specified in environment.yml.
# Clone and set up conda environment with CPU-only PyTorch/TensorFlow
git clone https://github.com/dcupolillo/spyne.git
cd spyne
conda env create -f environment_CPU.yml
conda activate spyne-env-cpu
# Install spyne
pip install -e .If you only need plotting and data loading features (not spine segmentation or event classification):
pip install git+https://github.com/dcupolillo/spyne.git- Plotting and data loading only: Minimal install is sufficient (CPU environment).
- Spine segmentation and calcium event classification: GPU environment strongly recommended for reasonable performance.
spyne is composed of 3 main elements:
- ImagingDataset : manages the actual imaging data and metadata;
- SpineDataset : performs spine segmentation and calcium imaging analysis.
- EphyDataset: manages and analyzes patch-clamp data.
The ImagingDataset class is the primary handler for calcium imaging data. It integrates data from 2-photon microscopy experiments, organizing data hierarchically as follows:
Dataset
└── ROIs
└── Sweeps
└── Channels
└── Framesspine dataset
ephy dataset
spyne depends and relies on structural data generated using ROIpy (find repository here).
Example Usage:
import spyne
from pathlib import Path
data_folder = Path("data") # where your data is stored
date = "250101" # YYMMDD format
cell_n = "cell0001" #cell000n format
imaging_folder = data_folder / date / cell_n / "neuron"
# Initialize the dataseta
dataset = spyne.ImagingDataset(imaging_folder)
spine_dataset = spyne.SpineDataset(dataset)
ephy_dataset = spyne.EphyDataset(dataset)-
Calcium Imaging Data Processing:
- Handle dF/F traces and z-scores.
- Detect and binarize calcium events with customizable thresholds.
- Segment calcium traces into spines and neurites.
-
Region of Interest (ROI) Analysis:
- Automatically generate and optimize rectangular ROIs for scanning.
- Assign ROIs to specific neuronal branches and compute branch attributes.
- Handle transformation matrices for pixel-to-reference coordinate mapping.
-
Visualization:
- Plot neuronal structures with color-coded branches.
- Visualize calcium traces for individual spines and neurites.
- Generate ROI layouts for scan fields.