HEKA PatchMaster

Support is provided for reading data and protocols from HEKA PatchMaster files in the 2x90.2 format.

PatchMaster files can contain several experiments, ordered into “groups” and “series”. The Series class implements Myokit’s shared myokit.formats.SweepSource interface.

Importer

Protocols can be imported via the PatchMasterFile class, or using the PatchMasterImporter.

myokit.formats.heka.importers()

Returns a dict of all importers available in this module.

class myokit.formats.heka.PatchMasterImporter

This Importer can import (step) protocols from “series” inside HEKA PatchMaster files.

protocol(filename, group=None, series=None)

Attempts to load the protocol from the file at filename.

Because PatchMaster files can contain several experiments, a further selection can be made with the arguments:

filename

The file to read

group

The group to read from (as a string).

series

The integer index of the desired series in the specified group.

supports_protocol()

Returns a bool indicating if protocol import is supported.

PatchMasterFile

class myokit.formats.heka.PatchMasterFile(filepath)

Provides read-only access to data stored in HEKA PatchMaster (“bundle”) files (.dat), stored at filepath.

Data loading is “lazy”, meaning that data is only read when requested. This means the file stays open, and so close() must be called after using a PatchMasterFile. To ensure this happens, use with:

with PatchMasterFile('my-file.dat') as f:
    for group in f:
        print(group.label)

Each file contains a hierarchy of Group, Series, Sweep and Trace objects. For example, each “group” might represent a single cell, and each “series” will be a protocol (called a “stimulus”) run on that cell. Groups are named by the user. Series are named after the “stimulus” they run. Sweeps are usually unnamed (although they do have a label property), and channels are named by the user.

To access groups, index them by integer, or use the group() method to find the first group with a given label:

with PatchMasterFile('my-file.dat') as f:
    group_0 = f[0]
    group_x = f.group('Experiment X')

Series, sweeps, and traces are accessed with integers:

with PatchMasterFile('my-file.dat') as f:
    group = f.group('Experiment X')
    series = group[0]
    sweep = series[0]
    trace = sweep[0]

Each object in the hierarchy can be iterated over:

with PatchMasterFile('my-file.dat') as f:
    for group in f:
        for series in group:
            for sweep in series:
                for trace in sweep:
                    ...

To see only completed series (where all sweeps were run to finish), use:

with PatchMasterFile('my-file.dat') as f:
    for group in f:
        for series in group.complete_series():
            ...

The Series class implements the myokit.formats.SweepSource interface:

with PatchMasterFile('my-file.dat') as f:
    for group in f:
        for series in group.complete_series():
            log = series.log()
amplifier_tree()

Returns this file’s amplifier tree (an AmplifierFile object), or None.

close()

Closes this file: no new data can be read once this has been called.

filename()

Returns this file’s filename.

group(label)

Returns the first :class`Group` matching the given label.

path()

Returns the path to this PatchMaster file.

stimulus_tree()

Returns this file’s stimulus tree (a StimulusFile object).

version()

Returns this file’s version number (as a string).

Internals

PatchMaster files are structured as several trees. These are read using the TreeNode class, which makes use of the EndianAwareReader class.

class myokit.formats.heka.TreeNode(parent)

Base class for objects within a PatchMaster file that form a tree.

This class may be useful when extending the patchmaster file reading, or to read other HEKA formats. To read a patchmaster file, use the PatchMasterFile class.

For subclasses:

When reading a file, TreeNode objects will be created by (1) calling the constructor with a parent but no children. (2) Calling the method _read_properties() which should read record properties from the open file handle and update the TreeNode accordingly. (3) Calling the method _read_finalize(), which can handl any actions that require children to have been added.

parent()

Returns this tree TreeNode’s parent.

static read(pfile, handle, levels)

Reads a full HEKA “Tree” structure.

Arguments:

pfile

A PatchMasterFile.

handle

An file handle, open at the tree root.

levels

The classes to use for each tree level.

Returns a TreeNode representing the tree’s root.

class myokit.formats.heka.EndianAwareReader(handle, is_little_endian)

Used by PatchmasterFile and its supporting classes when reading from an open file handle that may be either big or little endian.

This class may be useful when extending the patchmaster file reading, or to read other HEKA formats. To read a patchmaster file, use the PatchMasterFile class.

read(form)

Read and unpack using the struct format form.

read1(form)

Returns the first item from a call to read(form).

This is useful for the many cases where a single number is read.

str(size)

Read and unpack a string of at most length size.

time()

Reads a time in HEKA’s seconds-since-1990 format, converts it, and returns a datetime object.