ionique.parsers

Parser module for event and state segmentation in current recordings. This module provides a framework for parsing current trace data. It includes an abstract base Parser class and multiple concrete parser implementations for detecting spikes, noise, square pulses, and other event structures in ionic current signals.

Some of the parsers and the parser base class were adapted from the PyPore Package by Jacob Schreiber and Kevin Karplus (https://github.com/jmschrei/PyPore)

class ionique.parsers.AutoSquareParser(threshold_baseline=0.7, expected_conductance=1.9, conductance_tolerance=1.2, wrap_padding: int = 50, rules=[])

Bases: Parser

Class for building a straightforward pipeline of data analysis to make it reusable with customized parameters

__init__(threshold_baseline=0.7, expected_conductance=1.9, conductance_tolerance=1.2, wrap_padding: int = 50, rules=[])

Initialize a Parser instance

parse(current, eff_sampling_freq, voltage)

Takes in a current segment, and returns a list of segment objects

Parameters:

kwargs (dict) – Keyword arguments containing the data, such as current

Returns:

A list of tuples representing the start and end indices of the segment and an empty dictionary.

Return type:

list[tuple]

required_parent_attributes: list[str] = ['current', 'eff_sampling_freq', 'voltage']
class ionique.parsers.FilterDerivativeSegmenter(low_threshold=1, high_threshold=2, cutoff_freq=1000.0, sampling_freq=100000.0)

Bases: Parser

This parser will segment an event using a filter-derivative method. It will first apply a bessel filter at a certain cutoff to the current, then it will take the derivative of that, and segment when the derivative passes a threshold.

__init__(low_threshold=1, high_threshold=2, cutoff_freq=1000.0, sampling_freq=100000.0)

Initialize a Parser instance

parse(current)

Apply the filter-derivative method to filter the ionic current.

set_params()
Returns:

class ionique.parsers.IVCurveAnalyzer(current, parent_segment, sampling_frequency, method='simple')

Bases: Parser

THIS CLASS IS NOT IMPLEMENTED YET. DO NOT USE. Check for at Least Two Voltage Steps: confirm that the segment has at least two voltage steps.

Divide into Voltage Segments: separate data into voltage segments.

Call IVAnalyzer on Parent Segment: compute the mean and std of the current in each voltage segment.

Return an Array of (voltage: (imean, istd)) pair:

Also mean and std should be calulated in two ways

__init__(current, parent_segment, sampling_frequency, method='simple')

Initialize a Parser instance

analyze()

Analyze each voltage step in a parent segment

class ionique.parsers.IVCurveParser(voltage)

Bases: object

THIS CLASS IS NOT IMPLEMENTED YET! DO NOT USE. The class handles:

  1. Identifies a file where an IV curve is recorded based on the pattern.

Here, the goal is to feed the voltage information to a module and have it search and do pattern matching to find one of these possibilities. .This can be a parser that accepts voltage array or compressed voltage as one of the inputs.

__init__(voltage)
parse()

Searches for a pattern in the voltage data to identify IV. If none exists, the given datafile does not contain IV curves. If one or multiple IV curves are found, it returns start and end regions of each of them. Returns: list of indices: start and end for each deteced IV curve

class ionique.parsers.MemoryParse(starts, ends)

Bases: object

A parser based on being fed previous split points, and splitting a raw file based those splits. Used predominately when loading previous split points from the database cache, to reconstruct a parsed file from “memory.

__init__(starts, ends)
Parameters:
  • starts (list[int]) – A list of start indices for each segment.

  • ends (list[int]) – A list of end indices corresponding to each start index.

parse(current)
class ionique.parsers.NoiseFilterParser(noise_threshold=60, detect_noise=True)

Bases: Parser

This unit is a parser subclass. when invoked on a segment (whole file or subsegment), it identifies the areas where bad things happened, and areas where the data is clean. Examples of bad things include high noise (60Hz noise from opening the cage), membrane rupture, and membrane formation attempts. it produces children from the good regions of the data and ignore the bad regions.

__init__(noise_threshold=60, detect_noise=True)

Initialize a Parser instance

parse(data, segment_start=0, segment_end=None)

Takes in a current segment, and returns a list of segment objects

Parameters:

kwargs (dict) – Keyword arguments containing the data, such as current

Returns:

A list of tuples representing the start and end indices of the segment and an empty dictionary.

Return type:

list[tuple]

class ionique.parsers.Parser

Bases: ABC

This class defines the interface and shared utility methods for parser implementations. Parsers are used to segment ionic current data into structured regions of interest (events).

Subclasses should implement the parse method and define any additional logic required to detect features in the data.

abstract __init__()

Initialize a Parser instance

classmethod from_json(_json)

Critical: Not implemented yet, figure out how to make this work in pythion

classmethod get_init_params()

Get the initialization parameters of the parser class.

Returns:

A dictionary of initialization parameters, default None.

Return type:

dict or None

classmethod get_name()

Get the name of the parser class :return: The name of the class. :rtype: str

classmethod get_process_inputs()
classmethod get_process_outputs()

Get the outputs generated by processing

Returns:

A list of outputs generated by parse method

Return type:

list or None

get_required_parent_attributes()

Get the list of required attributes from the parent segment

Returns:

A list of required parent attributes

Return type:

list[str]

parse(**kwargs)

Takes in a current segment, and returns a list of segment objects

Parameters:

kwargs (dict) – Keyword arguments containing the data, such as current

Returns:

A list of tuples representing the start and end indices of the segment and an empty dictionary.

Return type:

list[tuple]

required_parent_attributes: list[str] = ['current']
set_params(param_dict)

Updates each paramater presented in the GUI to the value input in the lineEdit corresponding to that value. :param param_dict: A dictionary :type param_dict: dict

to_dict()

Convert the parser’s attributes to a dictionary.

Returns:

A dictionary representation of the parser’s attributes.

Return type:

dict

to_json(filename=False)

Convert the parser’s attributes to a JSON string.

Parameters:

filename (str, default bool) – If filename, it writes the JSON string to the specified file.

Returns:

A dictionary representation of the parser’s attributes.

Return type:

str

class ionique.parsers.SpeedyStatSplit(sampling_freq, min_width=100, max_width=1000000, window_width=10000, min_gain_per_sample=None, false_positive_rate=None, prior_segments_per_second=None, cutoff_freq=None)

Bases: Parser

A parser wrapper for the Cython-accelerated FastStatSplit algorithm.

See cparsers.pyx FastStatSplit for full documentation. This is just a wrapper for the cyton implementation to add a GUI.

__init__(sampling_freq, min_width=100, max_width=1000000, window_width=10000, min_gain_per_sample=None, false_positive_rate=None, prior_segments_per_second=None, cutoff_freq=None)

Initialize the SpeedyStatSplit instance

Parameters:
  • sampling_freq (int) – The sampling frequency of the data

  • min_width (int, optional) – Minimum width of a segment, default=100

  • max_width (int, optional) – Maximum width of a segment, default=1000000.

  • window_width (int, optional) – Width of the window, defaults to 10000.

  • min_gain_per_sample (float or None, optional) – Minimum gain per sample, default=None

  • false_positive_rate (float or None, optional) – Expected false positive rate , default=None

  • prior_segments_per_second (float or None, optional) – Prior number of segments per second, default=None.

  • cutoff_freq (float or None, optional) – Cutoff frequency for filtering, default=None

best_single_split(current)

Determine the best single split point in the current data

Parameters:

current (numpy.ndarray) – The current data to be analyzed.

Returns:

The best split point

Return type:

int or None

parse(current)

Parse the current data to detect segments using the FastStatSplit

Parameters:

current (numpy.ndarray) – The current data to be parsed

Returns:

A list of detected segments

Return type:

parse_meta(current)

Parse the current data and extract meta information

Parameters:

current (numpy.ndarray) – The current data to be parsed.

set_params()

Set the parameters

uiTemplate = [('sampling_freq', 'spin', {'bounds': [0, None], 'dec': True, 'siPrefix': True, 'step': 1, 'suffix': 'Hz', 'value': 200000}), ('min_width', 'spin', {'dec': True, 'int': True, 'min': 2, 'step': 1, 'value': 100}), ('max_width', 'spin', {'dec': True, 'int': True, 'step': 1, 'value': 1000000}), ('window_width', 'spin', {'dec': True, 'int': True, 'step': 1, 'value': 10000}), ('cutoff_freq', 'spin', {'hidden': True})]
class ionique.parsers.SpikeParser(height=None, threshold=None, distance=None, prominence=None, prominence_snr=None, width=None, wlen=None, rel_height: float = 0.5, plateu_size=None, fractional: bool = True)

Bases: Parser

A parser for detecting spike-like events in ionic current data.

This parser wraps scipy.signal.find_peaks, supporting thresholds for features like peak height, prominence, and width. It computes event characteristics such as dwell time, relative prominence, and peak positions.

__init__(height=None, threshold=None, distance=None, prominence=None, prominence_snr=None, width=None, wlen=None, rel_height: float = 0.5, plateu_size=None, fractional: bool = True) None

Initialize the SpikeParser.

Parameters:
  • height (float or tuple or None) – Minimum spike height.

  • threshold (float or tuple or None) – Minimum vertical threshold.

  • distance (float or tuple or None) – Minimum horizontal distance between peaks.

  • prominence (float or tuple or None) – Minimum peak prominence.

  • prominence_snr (tuple or None) – Alternative to prominence, specified as a tuple of signal-to-noise (SNR) ratios.

  • width (float or tuple or None) – Full width at half maximum of the peak.

  • wlen (float or None) – Width of the window used to calculate prominence.

  • rel_height (float) – Relative height used in width calculation (range 0 to 1).

  • plateu_size (float or None) – Minimum length of a flat-topped peak.

  • fractional (bool) – Whether to interpret height, prominence, etc., as a fraction of the signal mean.

parse(current, sampling_freq, mean, std, start)

Takes in a current segment, and returns a list of segment objects

Parameters:

kwargs (dict) – Keyword arguments containing the data, such as current

Returns:

A list of tuples representing the start and end indices of the segment and an empty dictionary.

Return type:

list[tuple]

required_parent_attributes: list[str] = ['current', 'sampling_freq', 'mean', 'start', 'std']
class ionique.parsers.lambda_event_parser(threshold=90, rules=None)

Bases: Parser

A simple rule-based parser which defines events as a sequential series of points which are below a certain threshold, then filtered based on other critereon such as total time or minimum current. Rules can be passed in at initiation, or set later, but must be a lambda function takes in a PreEvent object and performs some boolean operation.

__init__(threshold=90, rules=None)
Parameters:
  • threshold (float) – The threshold for detecting events (e.g., current < threshold).

  • rules (list[callable] or None) – A list of lambda functions that accept an event and return a bool.

parse(current)

Perform a large capture of events by creating a boolean mask for when the current is below a threshold, then detecting the edges in those masks, and using the edges to partitition the sample. The events are then filtered before being returned.

set_params()

Read in the data from the GUI and use it to customize the rules or threshold of the parser.

ionique.parsers.pairwise(iterable)

s -> (s0,s1), (s1,s2), (s2, s3), …

Parameters:

iterable

Returns:

class ionique.parsers.snakebase_parser(threshold=1.5)

Bases: Parser

A simple parser based on dividing when the peak-to-peak amplitude of a wave exceeds a certain threshold.

__init__(threshold=1.5)

Initialize a Parser instance

parse(current)

Takes in a current segment, and returns a list of segment objects

Parameters:

kwargs (dict) – Keyword arguments containing the data, such as current

Returns:

A list of tuples representing the start and end indices of the segment and an empty dictionary.

Return type:

list[tuple]

set_params()

Updates each paramater presented in the GUI to the value input in the lineEdit corresponding to that value. :param param_dict: A dictionary :type param_dict: dict