Skip to main content

A Python library for idealizing single-channel current recordings

Project description

PyIoneer

A Python library and CLI for idealizing single-channel current recordings from electrophysiology experiments.

Features

  • Multiple Idealization Methods:

    • Hidden Markov Models (HMM)
    • Threshold-crossing detection
    • Change-point detection
  • Block Detection: Detect blocking events in single-channel recordings (adapted from synapse-abf)

  • Batch Processing: Analyze multiple ABF files automatically

  • Direct ABF Support: Works directly with Axon Binary Format files via pyABF

  • No GUI Required: Perfect for automation and pipelines

  • Cross-platform: Works on Windows, macOS, and Linux

Installation

pip install pyioneer

For all features including HMM and change-point detection:

pip install pyioneer[all]

Or install from source:

git clone https://github.com/Adorey92-git/pyioneer
cd pyioneer
pip install -e .

Quick Start

Python API

from pyioneer import load_abf, segment_threshold, detect_blocks

# Load ABF file
reader = load_abf("recording.abf")
time, current = reader.get_sweep(sweep=0, channel=0)

# Segment using threshold method
result = segment_threshold(time, current, threshold=0.5)

# Get event list with dwell times
for event in result.events:
    print(f"State {event.state}: {event.dwell_time:.4f}s at {event.amplitude:.2f} pA")

# Detect blocks
blocks = detect_blocks(time, current)
print(f"Found {len(blocks)} blocks")

Command Line

# Segment a file
pyioneer idealize recording.abf --method threshold --threshold 0.5

# Detect blocks
pyioneer blocks recording.abf --sweep 0

# Batch process directory
pyioneer batch /path/to/abf/files --method threshold --threshold 0.5 --output results.json

Idealization Methods

Threshold-Crossing

Simple and fast method that detects state transitions when the current crosses a threshold.

result = segment_threshold(
    time, current,
    threshold=0.5,  # Threshold in pA
    min_dwell=0.001,  # Minimum dwell time in seconds
    baseline=None  # Auto-detect baseline
)

Hidden Markov Models (HMM)

Model-based approach, ideal for noisy data.

result = segment_hmm(
    time, current,
    n_states=2,  # Number of states (e.g., open/closed)
    method="gaussian",
    max_iter=100
)

Change-Point Detection

Detects abrupt changes in signal statistics.

result = segment_change_point(
    time, current,
    n_states=2,
    method="binseg",  # or "window", "dynp"
    min_size=2
)

Block Detection

Detect blocking events in single-channel recordings where current moves toward zero from baseline.

from pyioneer import detect_blocks, BlockDetector

# Simple detection
blocks = detect_blocks(
    time, current,
    baseline=None,  # Auto-detect
    block_threshold_factor=2.0,
    min_block_duration=0.001
)

# Advanced detection with custom parameters
detector = BlockDetector(
    baseline_threshold=-0.25,  # Known baseline
    block_threshold_factor=2.0,
    min_block_duration=0.001
)
blocks = detector.detect(time, current, sweep_number=0)

Batch Processing

Process multiple files automatically:

from pyioneer import batch_analyze, idealize_threshold
from pathlib import Path

results = batch_analyze(
    Path("/path/to/abf/files"),
    idealize_threshold,
    idealization_kwargs={"threshold": 0.5},
    detect_blocks=True,
    output_path=Path("results.json")
)

Output Format

Idealization results include:

  • Events: List of detected events with:

    • start_time: Event start time (seconds)
    • end_time: Event end time (seconds)
    • dwell_time: Duration of event (seconds)
    • amplitude: Mean current during event (pA)
    • state: State index (0=closed, 1=open, etc.)
  • Idealized trace: Array of idealized current values

  • States: Array of state assignments for each sample

Convert to pandas DataFrame:

df = result.to_dataframe()
df.to_csv("events.csv")

Comparison with pClamp

PyIoneer provides similar functionality to pClamp's idealization features but:

  • No GUI required - perfect for automation
  • Cross-platform - works on all operating systems
  • Modern Python API - easy to integrate into pipelines
  • Open source - fully customizable
  • Tailored for single-channel - optimized for patch-clamp recordings

Requirements

  • Python 3.8+
  • pyABF 2.3.8+
  • NumPy 1.24.0+
  • SciPy 1.10.0+
  • Click 8.0.0+

Optional dependencies:

  • hmmlearn for HMM idealization
  • ruptures for change-point detection
  • pandas for DataFrame export

Documentation

See examples/ for more detailed usage examples.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Built with pyABF for ABF file support
  • Block detection adapted from synapse-abf
  • Inspired by QuB and pClamp idealization tools

Citation

If you use PyIoneer in your research, please cite:

@software{pyioneer2025,
  title={PyIoneer: A Python library for idealizing single-channel current recordings},
  author={Your Name},
  year={2025},
  url={https://github.com/Adorey92-git/pyioneer}
}

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

pyioneer-0.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

pyioneer-0.1.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file pyioneer-0.1.0.tar.gz.

File metadata

  • Download URL: pyioneer-0.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pyioneer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 78bfc7faee84877543ed03b3dc1af89b8d21d3fd462c820d6fb5d1aec6e14140
MD5 48f6172333c3f530fa6f7845d1f72bef
BLAKE2b-256 56285117e877d7a95a1a0a5ad62e7710e0b9101bb359d355bf8e5aca9afd5301

See more details on using hashes here.

File details

Details for the file pyioneer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyioneer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pyioneer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba1d806be7b9e9be57165dd52075becbbc902e74028f4ba90b728dd1c9f11c5e
MD5 a691dcfc235b663dd2f6de011529b68e
BLAKE2b-256 7deb25090bd3c19cafd183f8833a488a5f64bdd612f6250eb367c138abe6cb6b

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