File MIES_AnalysisFunctions_PatchSeq.ipf

PSQ Analysis functions for patch sequence

The stimsets with the analysis functions attached are executed in the following order:

  • PSQ_PipetteInBath PB

  • PSQ_SealEvaluation SE

  • PSQ_AccessResistanceSmoke AR

  • PSQ_TrueRestingMembranePotential VM

  • PSQ_DaScale (sub threshold) DA (sub)

  • PSQ_SquarePulse (long pulse) SP

  • PSQ_Rheobase (long pulse) RB

  • PSQ_DaScale (supra threshold) DA (supra)

  • PSQ_SquarePulse (short pulse) SP

  • PSQ_Rheobase (short pulse) RB

  • PSQ_Ramp RA

  • PSQ_Chirp CR

See GetAbbreviationForAnalysisFunction() for a generating the abbreviation of each analysis function.

The Patch Seq analysis functions store various results in the labnotebook.

For orientation the following table shows their relation. All labnotebook keys can and should be created via CreateAnaFuncLBNKey().

Naming constant

Description

Unit

Labnotebook

Analysis function

Per Chunk?

Headstage dependent?

PSQ_FMT_LBN_SPIKE_DETECT

The required number of spikes were detected on the sweep

On/Off

Numerical

SP, RB, RA, DA (Supra)

No

Yes

PSQ_FMT_LBN_SPIKE_POSITIONS

Spike positions

ms

Numerical

RA, VM

No

Yes

PSQ_FMT_LBN_SPIKE_COUNT

Spike count

(none)

Numerical

DA (Supra)

No

Yes

PSQ_FMT_LBN_STEPSIZE

Current DAScale step size

(none)

Numerical

SP, RB

No

No

PSQ_FMT_LBN_STEPSIZE_FUTURE

Future DAScale step size

(none)

Numerical

RB

No

No

PSQ_FMT_LBN_RB_DASCALE_EXC

Range for valid DAScale values is exceeded

On/Off

Numerical

RB

No

Yes

PSQ_FMT_LBN_RB_LIMITED_RES

Failed due to limited DAScale resolution

On/Off

Numerical

RB

No

Yes

PSQ_FMT_LBN_FINAL_SCALE

Final DAScale of the given headstage, only set on success

(none)

Numerical

SP, RB

No

No

PSQ_FMT_LBN_SPIKE_DASCALE_ZERO

Sweep spiked with DAScale of 0

On/Off

Numerical

SP

No

No

PSQ_FMT_LBN_INITIAL_SCALE

Initial DAScale

(none)

Numerical

RB, CR

No

No

PSQ_FMT_LBN_RMS_SHORT_PASS

Short RMS baseline QC result

On/Off

Numerical

DA, RB, RA, CR, SE, VM, AR

Yes

Yes

PSQ_FMT_LBN_RMS_SHORT_THRESHOLD

Short RMS baseline threshold

V

Numerical

DA, RB, RA, CR, SE, VM, AR

No

Yes

PSQ_FMT_LBN_RMS_LONG_PASS

Long RMS baseline QC result

On/Off

Numerical

DA, RB, RA, CR, SE, VM, AR

Yes

Yes

PSQ_FMT_LBN_RMS_LONG_THRESHOLD

Long RMS baseline threshold

V

Numerical

DA, RB, RA, CR, SE, VM, AR

No

Yes

PSQ_FMT_LBN_TARGETV

Target voltage baseline

Volt

Numerical

DA, RB, RA, CR

Yes

Yes

PSQ_FMT_LBN_TARGETV_PASS

Target voltage baseline QC result

On/Off

Numerical

DA, RB, RA, CR

Yes

Yes

PSQ_FMT_LBN_TARGETV_THRESHOLD

Target voltage threshold

V

Numerical

DA, RB, RA, CR

No

Yes

PSQ_FMT_LBN_LEAKCUR

Leak current

Amperes

Numerical

PB, VM, AR

Yes

Yes

PSQ_FMT_LBN_LEAKCUR_PASS

Leak current QC result

On/Off

Numerical

PB, VM, AR

Yes

Yes

PSQ_FMT_LBN_AVERAGEV

Average voltage

Volt

Numerical

VM

Yes

Yes

PSQ_FMT_LBN_CHUNK_PASS

Which chunk passed/failed baseline QC

On/Off

Numerical

DA, RB, RA, CR, PB, SE, VM, AR

Yes

Yes

PSQ_FMT_LBN_BL_QC_PASS

Pass/fail state of the complete baseline

On/Off

Numerical

DA, RB, RA, CR, PB, SE, VM, AR

No

Yes

PSQ_FMT_LBN_SWEEP_PASS

Pass/fail state of the complete sweep

On/Off

Numerical

DA, SP, RA, CR, PB, SE, VM, AR

No

No

PSQ_FMT_LBN_SET_PASS

Pass/fail state of the complete set

On/Off

Numerical

DA, RB, RA, SP, CR, PB, SE, VM, AR

No

No

PSQ_FMT_LBN_SAMPLING_PASS

Pass/fail state of the sampling interval check

On/Off

Numerical

DA, RB, RA, SP, CR, PB, SE, VM, AR

No

No

PSQ_FMT_LBN_PULSE_DUR

Pulse duration as determined experimentally

ms

Numerical

RB, DA, CR

No

Yes

PSQ_FMT_LBN_SPIKE_PASS

Pass/fail state of the spike search (No spikes → Pass)

On/Off

Numerical

CR, VM

No

Yes

PSQ_FMT_LBN_DA_fI_SLOPE

Fitted slope in the f-I plot

% Hz/pA

Numerical

DA (Supra)

No

Yes

PSQ_FMT_LBN_DA_fI_SLOPE_REACHED_PASS

Fitted slope in the f-I plot exceeds target value

On/Off

Numerical

DA (Supra)

No

No

PSQ_FMT_LBN_DA_OPMODE

Operation Mode: One of PSQ_DS_SUB/PSQ_DS_SUPRA

(none)

Textual

DA

No

No

PSQ_FMT_LBN_CR_INSIDE_BOUNDS

AD response is inside the given bands

On/Off

Numerical

CR

No

No

PSQ_FMT_LBN_CR_RESISTANCE

Calculated resistance from DAScale sub threshold

Ohm

Numerical

CR

No

No

PSQ_FMT_LBN_CR_BOUNDS_ACTION

Action according to min/max positions

(none)

Numerical

CR

No

No

PSQ_FMT_LBN_CR_BOUNDS_STATE

Upper and Lower bounds state according to min/max pos.

(none)

Textual

CR

No

No

PSQ_FMT_LBN_CR_SPIKE_CHECK

Spike check was enabled/disabled

(none)

Numerical

CR

No

No

PSQ_FMT_LBN_CR_INIT_UOD

Initial user onset delay

ms

Numerical

CR

No

No

PSQ_FMT_LBN_CR_INIT_LPF

Initial MCC low pass filter

Hz

Numerical

CR

No

No

PSQ_FMT_LBN_CR_STIMSET_QC

Stimset valid/invalid QC state

On/Off

Numerical

CR

No

No

FMT_LBN_ANA_FUNC_VERSION

Integer version of the analysis function

(none)

Numerical

All

No

Yes

PSQ_FMT_LBN_PB_RESISTANCE

Pipette Resistance

Ohm

Numerical

PB

No

No

PSQ_FMT_LBN_PB_RESISTANCE_PASS

Pipette Resistance QC

On/Off

Numerical

PB

No

No

PSQ_FMT_LBN_SE_TP_GROUP_SEL

Selected Testpulse groups: One of Both/First/Second

(none)

Textual

SE

No

No

PSQ_FMT_LBN_SE_RESISTANCE_A

Seal Resistance of TPs in group A

Ω

Numerical

SE

No

No

PSQ_FMT_LBN_SE_RESISTANCE_B

Seal Resistance of TPs in group B

Ω

Numerical

SE

No

No

PSQ_FMT_LBN_SE_RESISTANCE_MAX

Maximum Seal Resistance of TPs in both groups

Ω

Numerical

SE

No

No

PSQ_FMT_LBN_SE_RESISTANCE_PASS

Seal Resistance QC

On/Off

Numerical

SE

No

No

PSQ_FMT_LBN_VM_FULL_AVG

Average voltage of all baseline chunks

Volt

Numerical

VM

No

No

PSQ_FMT_LBN_VM_FULL_AVG_ADIFF

Average voltage absolute difference

Volt

Numerical

VM

No

No

PSQ_FMT_LBN_VM_FULL_AVG_ADIFF_PASS

Average voltage absolute difference QC

On/Off

Numerical

VM

No

No

PSQ_FMT_LBN_VM_FULL_AVG_RDIFF

Average voltage relative difference

(none)

Numerical

VM

No

No

PSQ_FMT_LBN_VM_FULL_AVG_RDIFF_PASS

Average voltage relative difference QC

On/Off

Numerical

VM

No

No

PSQ_FMT_LBN_VM_FULL_AVG_PASS

Full average voltage QC result

On/Off

Numerical

VM

No

No

PSQ_FMT_LBN_AR_ACCESS_RESISTANCE

Access resistance of all TPs in the stimset

Ω

Numerical

AR

No

No

PSQ_FMT_LBN_AR_ACCESS_RESISTANCE_PASS

Access resistance QC

On/Off

Numerical

AR

No

No

PSQ_FMT_LBN_AR_STEADY_STATE_RESISTANCE

Steady state resistance of all TPs in the stimset

Ω

Numerical

AR

No

No

PSQ_FMT_LBN_AR_RESISTANCE_RATIO

Ratio of access resistance to steady state

(none)

Numerical

AR

No

No

PSQ_FMT_LBN_AR_RESISTANCE_RATIO_PASS

Ratio of access resistance to steady state QC

On/Off

Numerical

AR

No

No

PSQ_FMT_LBN_ASYNC_PASS

Combined alarm state of all async channels

On/Off

Numerical

All

No

No

LBN_DELTA_I

Delta current in pulse

Amperes

Numerical

RV, AD, DA (Sub)

No

Yes

LBN_DELTA_V

Delta voltage in pulse

Volts

Numerical

RV, AD, DA (Sub)

No

Yes

LBN_RESISTANCE_FIT

Fitted resistance from pulse

Ohm

Numerical

RV, AD, DA (Sub)

No

Yes

LBN_RESISTANCE_FIT_ERR

Error of fitted resistance from pulse

Ohm

Numerical

RV, AD, DA (Sub)

No

Yes

LBN_AUTOBIAS_TARGET_DIAG

Autobias target voltage from dialog

mV

Numerical

RV

No

Yes

Query the standard STIMSET_SCALE_FACTOR_KEY entry from labnotebook for getting the DAScale.

The following table lists the user epochs which are added during data acquisition:

Tags

Short Name

Analysis function

Description

Level

Name=Baseline Chunk;Index=x

U_BLCx

DA, RB, RA, CR, SE, VM, AR

Baseline QC evaluation chunks

-1

Name=Baseline Chunk QC Selection;Index=x

U_BLSx

SE, VM, AR

Selects the chunk for Baseline QC evaluation

-1

Name=DA Suppression

U_RA_DA

RA

DA was suppressed in this time interval

-1

Name=Unacquired DA data

U_RA_UD

RA

Interval of unacquired data

-1

Type=Testpulse Like;Index=x

U_TPx

PB, SE, AR

Testpulse like region in stimset

-1

Type=Testpulse Like;SubType=Baseline;Index=x

U_TPx_B0

PB, SE, AR

Pre pulse baseline of testpulse

-1

Type=Testpulse Like;SubType=Pulse;Amplitude=y;Index=x

U_TPx_P

PB, SE, AR

Pulse of testpulse

-1

Type=Testpulse Like;SubType=Baseline;Index=x

U_TPx_B1

PB, SE, AR

Post pulse baseline of testpulse

-1

Type=Chirp Cycle Evaluation

U_CR_CE

CR

Evaluation chunk for bounds state

-1

Type=Chirp Spike Evaluation

U_CR_SE

CR

Evaluation chunk for spike check

-1

The tag entry Index=x is a zero-based index, which tracks how often the specific type of user epoch appears. So for different epoch types duplicated index entries are to be expected.

See also Time specialities.

Textual results entries stored by the sweep formula store operation with the names Sweep Formula store [XXX]:

Name

Analysis function

Steady state resistance

PB

Steady state resistance (group A)

PB

Steady state resistance (group B)

PB

Average U_BLS0

VM

Average U_BLS1

VM

Steady state resistance

AR

Peak resistance

AR

Functions

static variable PSQ_GetPulseSettingsForType(variable type, PSQ_PulseSettings *s)

Fills s according to the analysis function type.

static wave PSQ_GetPulseDurations(string device, variable type, variable sweepNo, variable totalOnsetDelay, variable forceRecalculation = defaultValue)

Return the pulse durations from the labnotebook or calculate them before if required in ms. For convenience unused headstages will have 0 instead of NaN in the returned wave.

We recalculate the durations on every sweep again as we can not assume that it is constant for the whole stimulus set.

static wave PSQ_DeterminePulseDuration(string device, variable sweepNo, variable type, variable totalOnsetDelay)

Determine the pulse duration on each headstage.

Returns the labnotebook wave as well.

static std::tuple<variable, variable, variable> PSQ_GetBaselineThresholds(string params)

Return the baseline RMS short/long and target V thresholds in mV.

static variable PSQ_StoreThresholdsInLabnotebook(string device, variable type, variable sweepNo, variable headstage, variable rmsShortThreshold, variable rmsLongThreshold, variable targetVThreshold)
static variable PSQ_EvaluateBaselinePassed(string device, variable type, variable sweepNo, variable headstage, variable chunk, variable ret)
static std::tuple<variable, variable> PSQ_EvaluateBaselineChunks(string device, variable type, AnalysisFunction_V3 *s)
static variable PSQ_EvaluateBaselineProperties(string device, AnalysisFunction_V3 *s, variable type, variable chunk, variable fifoInStimsetTime, variable totalOnsetDelay)

Evaluate one chunk of the baseline.

Parameters:
  • device – device

  • sAnalysisFunction_V3 struct

  • type – analysis function type, one of PatchSeqAnalysisFunctionTypes

  • chunk – chunk number, chunk == 0 -> Pre pulse baseline chunk, chunk >= 1 -> Post pulse baseline for traditional baseline evaluation if PSQ_PulseSettings::usesBaselineChunkEpochs is false.

  • fifoInStimsetTime – Fifo position in ms relative to the start of the stimset (therefore ignoring the totalOnsetDelay)

  • totalOnsetDelay – total onset delay in ms

Returns:

pre pulse baseline: 0 if the chunk passes, one of the possible AnalysisFuncReturnTypesConstants values otherwise post pulse baseline: 0 if the chunk passes, PSQ_BL_FAILED if it does not pass generic baseline: 0 if the chunk passes, PSQ_BL_FAILED if it does not pass

static variable PSQ_GetNumberOfChunks(string device, variable sweepNo, variable headstage, variable type, variable sampleIntervalAD)

Return the number of chunks.

A chunk is PSQ_BL_EVAL_RANGE [ms] of baseline.

For calculating the number of chunks we ignore the one chunk after the pulse which we don’t evaluate!

static variable PSQ_Calculate(wave wv, variable column, variable startTime, variable rangeTime, variable method)
static variable PSQ_NumAcquiredSweepsInSet(string device, variable sweepNo, variable headstage)

Return the number of already acquired sweeps from the given stimset cycle.

variable PSQ_NumPassesInSet(wave numericalValues, variable type, variable sweepNo, variable headstage)

Return the number of passed sweeps in all sweeps from the given stimset cycle.

static variable PSQ_GetDAStimsetLength(string device, variable headstage)

Return the DA stimset length in ms of the given headstage.

Returns:

stimset length or -1 on error

wave PSQ_CreateOverrideResults(string device, variable headstage, variable type, string opMode = defaultValue)

Create the overrides results wave for CI testing.

PSQ_SQUARE_PULSE:

Rows:

  • Only one

Cols:

  • sweeps/steps

Layers:

  • 0: x position in ms where the spike is in each sweep/step For convenience the values 0 always means no spike and 1 spike detected (at the appropriate position).

  • 1: async channel QC

PSQ_RHEOBASE/PSQ_RAMP:

Rows:

  • chunk indizes

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: x position in ms where the spike is in each sweep/step For convenience the values 0 always means no spike and 1 spike detected (at the appropriate position).

  • 2: async channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

PSQ_DA_SCALE:

Rows:

  • chunk indizes

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: x position in ms where the spike is in each sweep/step For convenience the values 0 always means no spike and 1 spike detected (at the appropriate position).

  • 2: Number of spikes

  • 3: Async channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

PSQ_CHIRP:

Rows:

  • chunk indizes

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: maximum of AD data in chirp region [first row only, others are ignored], use NaN to use the real values

  • 2: minimum of AD data in chirp region [first row only, others are ignored], use NaN to use the real values

  • 3: passing spike check in chirp region or not [first row only, others are ignored]

  • 4: async channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

PSQ_PIPETTE_BATH:

Rows:

  • chunk indizes

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: averaged steady state resistance [MΩ]

  • 2: async channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

PSQ_SEAL_EVALUATION:

Rows:

  • chunk indizes (only selected chunks via user epoch, sorted by ascending chunk start time)

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: Resistance A [MΩ]

  • 2: Resistance B [MΩ]

  • 3: Async Channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

PSQ_TRUE_REST_VM:

Rows:

  • chunk indizes (only selected chunks via user epoch, sorted by ascending chunk start time)

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: number of spikes (QC passes with 0)

  • 2: average voltage [mV]

  • 3: async channel QC

Chunks (only for row/layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC (unused)

  • 3: leak current baseline QC (unused)

PSQ_ACC_RES_SMOKE:

Rows:

  • chunk indizes (only selected chunks via user epoch, sorted by ascending chunk start time)

Cols:

  • sweeps/steps

Layers:

  • 0: 1 if the chunk has passing baseline QC or not

  • 1: Access Resistance [MΩ]

  • 2: Steady State Resistance [MΩ]

  • 3: Async Channel QC

Chunks (only for layer 0):

  • 0: RMS short baseline QC

  • 1: RMS long baseline QC

  • 2: target voltage baseline QC

  • 3: leak current baseline QC

static variable PSQ_StoreStepSizeInLBN(string device, variable type, variable sweepNo, variable stepsize, variable future = defaultValue)

Store the step size in the labnotebook.

static wave PSQ_SearchForSpikes(string device, variable type, wave sweepWave, variable headstage, variable offset, variable level, variable searchEnd = defaultValue, variable numberOfSpikesReq = defaultValue, wave spikePositions = defaultValue, variable *numberOfSpikesFound = defaultValue)

Search the AD channel of the given headstage for spikes from the pulse onset until the end of the sweep or searchEnd if given.

Parameters:
  • device[in] device

  • type[in] One of PatchSeqAnalysisFunctionTypes

  • sweepWave[in] sweep wave with acquired data

  • headstage[in] headstage in the range [0, NUM_HEADSTAGES[

  • offset[in] offset in ms where the spike search should start, commonly the totalOnsetDelay

  • level[in] set the level for the spike search

  • searchEnd[in] [optional, defaults to inf] total length in ms of the spike search, relative to sweepWave start

  • numberOfSpikesReq[in] [optional, defaults to one] number of spikes to look for Positive finite value: Return value is 1 iff at least numberOfSpikes were found Inf: Return value is 1 if at least 1 spike was found

  • spikePositions[out] [optional] returns the position of the first numberOfSpikes found on success in ms

  • numberOfSpikesFound[out] [optional] returns the number of spikes found

Returns:

labnotebook value wave suitable for ED_AddEntryToLabnotebook()

static variable PSQ_GetLastPassingLongRHSweep(string device, variable headstage, variable duration)

Return a sweep number of an existing sweep matching the following conditions.

  • Acquired with Rheobase analysis function

  • Set QC passed for this SCI

  • Pulse duration was longer than duration

  • Spiked

And as usual we want the last matching sweep.

Returns:

existing sweep number or -1 in case no such sweep could be found

static variable PSQ_DS_IsValidMode(string str)
static variable PSQ_GetLastPassingDAScale(string device, variable headstage, string opMode)

Return the sweep number of the last sweep using the PSQ_DaScale() analysis function, where the set passes and was in the given mode.

static variable PSQ_GetLastPassingTrueRMP(string device, variable headstage)

Return the sweep number of the last sweep using the PSQ_TrueRestingMembranePotential() analysis function.

variable PSQ_DS_GetDAScaleOffset(string device, variable headstage, string opMode)

Return the DAScale offset for PSQ_DaScale()

Returns:

DAScale value in pA or NaN on error

variable PSQ_FoundAtLeastOneSpike(string device, variable sweepNo)

Check if the given sweep has at least one “spike detected” entry in the labnotebook.

Returns:

1 if found at least one, zero if none and NaN if no such entry could be found

static variable PSQ_GetDefaultSamplingFrequency(string device, variable type)
variable PSQ_GetDefaultSamplingFrequencyForSingleHeadstage(string device)

Returns the sampling frequency in kHz of our supported NI and ITC hardware for one active headstage and no TTL channels.

static variable PSQ_CheckADSamplingFrequencyAndStoreInLabnotebook(string device, variable type, AnalysisFunction_V3 *s)

Return the QC state of the sampling interval/frequency check and store it also in the labnotebook.

static string PSQ_GetHelpCommon(variable type, string name)

Help strings for common parameters.

Not every analysis function uses every parameter though.

static string PSQ_CheckParamCommon(string name, CheckParametersStruct *s, variable maxThreshold = defaultValue)
string PSQ_DAScale_GetParams()

Require parameters from stimset.

string PSQ_DAScale_GetHelp(string name)
string PSQ_DAScale_CheckParam(string name, CheckParametersStruct *s)
variable PSQ_DAScale(string device, AnalysisFunction_V3 *s)

Patch Seq Analysis function to find a suitable DAScale.

Prerequisites:

  • Does only work for one headstage

  • Assumes that the stimset has 500ms of pre pulse baseline, a non-zero pulse and at least 1000ms post pulse baseline.

  • Each 500ms (PSQ_BL_EVAL_RANGE) of the baseline is a chunk

Testing: For testing the spike detection logic, the results can be defined in the override wave,

Reading the results from the labnotebook:

WAVE numericalValues = GetLBNumericalValues(device)

// set properties

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_SET_PASS, query = 1)
setPassed = GetLastSettingIndepSCI(numericalValues, sweepNo, key, headstage, UNKNOWN_MODE)

if(setPassed)
  // set passed
else
  // set did not pass
endif

// single sweep properties
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_SWEEP_PASS, query = 1)
sweepPassed = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)

// chunk (500ms portions of the baseline) properties
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_CHUNK_PASS, chunk = chunk, query = 1)
chunkPassed = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)

// single test properties
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_RMS_SHORT_PASS, chunk = chunk, query = 1)
rmsShortPassed = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_RMS_LONG_PASS, chunk = chunk, query = 1)
rmsLongPassed  = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_TARGETV_PASS, chunk = chunk, query = 1)
targetVPassed  = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)

// get fitted resistance from last passing sweep
// resistance for the first headstage can be found in resistanceFitted[0]
WAVE/Z resistanceFitted = GetLastSettingSCI(numericalValues, sweepNo, LABNOTEBOOK_USER_PREFIX + LBN_RESISTANCE_FIT, headstage, UNKNOWN_MODE)

Decision logic flowchart:

///
/// Sketch of a stimset with inserted TP, pre pulse baseline (-), pulse (*), and post pulse baseline (-).
///
///  |-|                 ***********************************
///  | |                 |                                 |
///  | |                 |                      \WWW/      |
///  | |                 |                      /   \      |
///  | |                 |                     /wwwww\     |
///  | |                 |                   _|  o_o  |_   |
///  | |                 |      \WWWWWWW/   (_   / \   _)  |
///  | |                 |    _/`  o_o  `\_   |  \_/  |    |
///  | |                 |   (_    (_)    _)  : ~~~~~ :    |
///  | |                 |     \ '-...-' /     \_____/     |
///  | |                 |     (`'-----'`)     [     ]     |
///  | |                 |      `"""""""`      `"""""`     |
///  | |                 |                                 |
/// -| |-----------------|                                 |--------------------------------------------
///
/// ascii art image from: http://ascii.co.uk/art/erniebert
///
///
string PSQ_SquarePulse_GetParams()

Return a list of required parameters.

string PSQ_SquarePulse_GetHelp(string name)
string PSQ_SquarePulse_CheckParam(string name, CheckParametersStruct *s)
variable PSQ_SquarePulse(string device, AnalysisFunction_V3 *s)

Analysis function to find the smallest DAScale where the cell spikes.

Prerequisites:

  • Does only work for one headstage

  • Assumes that the stimset has a pulse

Testing: For testing the spike detection logic, the results can be defined in the override wave,

Decision logic flowchart:

///
/// Sketch of a stimset with pre pulse baseline (-), pulse (*), and post pulse baseline (-).
///
///    *******
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
/// ---|     |--------------------------------------------
///
///
string PSQ_Rheobase_GetParams()

Return a list of required parameters.

string PSQ_Rheobase_GetHelp(string name)
string PSQ_Rheobase_CheckParam(string name, CheckParametersStruct *s)
variable PSQ_Rheobase(string device, AnalysisFunction_V3 *s)

Analysis function for finding the exact DAScale value between spiking and non-spiking.

Prerequisites:

  • Does only work for one headstage

  • Assumes that the stimset has a pulse of non-zero and arbitrary length

  • Pre pulse baseline length is PSQ_BL_EVAL_RANGE

  • Post pulse baseline length a multiple of PSQ_BL_EVAL_RANGE

Testing: For testing the spike detection logic, the results can be defined in the override wave,

Decision logic flowchart:

///
/// Sketch of a stimset with pre pulse baseline (-), pulse (*), and post pulse baseline (-).
///
///    *******
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
///    |     |
/// ---|     |--------------------------------------------
///
///
variable PSQ_GetFinalDAScaleFake()
string PSQ_Ramp_GetParams()

Return a list of required parameters.

string PSQ_Ramp_GetHelp(string name)
string PSQ_Ramp_CheckParam(string name, CheckParametersStruct *s)
variable PSQ_Ramp(string device, AnalysisFunction_V3 *s)

Analysis function for applying a ramp stim set and finding the position were it spikes.

Prerequisites:

  • Does only work for one headstage

  • Assumes that the stimset has a ramp of non-zero and arbitrary length

  • Pre pulse baseline length is PSQ_BL_EVAL_RANGE

  • Post pulse baseline length is at least two times PSQ_BL_EVAL_RANGE

Testing: For testing the spike detection logic, the results can be defined in the override wave,

Decision logic flowchart:

///
/// Sketch of a stimset with pre pulse baseline (-), ramp (/|), and post pulse baseline (-).
///
///                 /|
///                / |
///               /  |
///              /   |
///             /    |
///            /     |
///           /      |
///          /       |
///         /        |
///        /         |
///       /          |
///      /           |
///     /            |
/// ---/             |--------------------------------------------
///
///
static variable PSQ_Ramp_AddEpoch(string device, variable headstage, wave wv, string tags, string shortName, variable first, variable last)
std::tuple<variable, variable> PSQ_CR_SetHasPassed(wave numericalValues, variable sweepNo, variable headstage)

Determine if we have three passing sweeps with the same DAScale value.

Returns:

result set passing state (0/1)

Returns:

maxOccurences maximum number of passing sets with the same DASCale value

static std::tuple<ChirpBoundsInfo> PSQ_CR_DetermineBoundsState(variable baseline, variable minimum, variable maximum, variable value)

Returns the two letter states “AA”, “BB” and “BA” for the value and the scaling factors to reach min/center/max.

We need the real baseline value (measured), whereas the center between minimum/maximum would be targetV, which the user entered together with an allowed ± range.

string PSQ_CR_BoundsActionToString(variable boundsAction)
static variable PSQ_CR_DetermineBoundsActionHelper(wave wv, string state, variable action)
static variable PSQ_CR_DetermineBoundsActionFromState(string upperState, string lowerState)

Returns an action depending on the upper and lower states, see ChirpBoundsAction.

static variable PSQ_CR_DetermineScalingFactor(ChirpBoundsInfo *lowerInfo, ChirpBoundsInfo *upperInfo, variable boundsEvaluationMode)

Determine the scaling factor for DAScale which is required for being inside the bounds.

static std::tuple<variable, variable> PSQ_CR_DetermineBoundsAction(string device, wave scaledDACWave, variable headstage, variable sweepNo, variable chirpStart, variable cycleEnd, variable innerRelativeBound, variable outerRelativeBound, variable boundsEvaluationMode)

Determine the bounds action given the requested chirp slice.

Parameters:
  • device – device

  • scaledDACWave – DAQ data wave with correct units and scaling

  • headstage – headstage

  • sweepNo – sweep number

  • chirpStart – x-position relative to stimset start where the chirp starts

  • cycleEnd – x-position relative to stimset start where the requested number of cycles finish

  • innerRelativeBound – analysis parameter

  • outerRelativeBound – analysis parameter

  • boundsEvaluationMode – bounds evaluation mode, one of PSQChirpBoundsEvaluationMode

Returns:

boundsAction, one of ChirpBoundsAction

Returns:

scalingFactorDAScale, scaling factor to be inside the bounds for actions PSQ_CR_INCREASE/PSQ_CR_DECREASE

static string PSQ_CR_BoundsEvaluationModeToString(variable val)
static variable PSQ_CR_ParseBoundsEvaluationModeString(string str)
static variable PSQ_SetAutobiasTargetVIfPresent(string device, variable headstage, string params, string name)
static variable PSQ_SetAutobiasTargetV(string device, variable headstage, variable value)
static variable PSQ_CR_SetAutobiasTargetVFromTrueRMP(string device, variable headstage, string params)

Set autobias target V from the average voltage of a passing PSQ_TrueRestingMembranePotential() sweep.

Returns:

0 on success, 1 otherwise

string PSQ_Chirp_GetHelp(string name)
string PSQ_Chirp_CheckParam(string name, CheckParametersStruct *s)
string PSQ_Chirp_GetParams()

Return a list of required analysis functions for PSQ_Chirp()

variable PSQ_Chirp(string device, AnalysisFunction_V3 *s)

Analysis function for determining the impedance of the cell using a sine chirp stim set.

Prerequisites:

  • Does only work for one headstage

  • Assumes that the stimset has a chirp of non-zero and arbitrary length

  • Pre pulse baseline length is PSQ_BL_EVAL_RANGE

  • Post pulse baseline length is at least two times PSQ_BL_EVAL_RANGE

Testing: For testing the range detection logic, the results can be defined in the wave root:overrideResults.

Decision logic flowchart:

The bounds action for Symmetric (Upper and Lower) is derived from the state according to the following sketch:

Depolarized (Upper only):

State

Action

BA

Pass

AA

Decrease

BB

Increase

Hyperpolarized (Lower only):

State

Action

BA

Pass

AA

Increase

BB

Decrease

///
/// Sketch of a stimset with pre pulse baseline (-), sine chirp (~), and post pulse baseline (-).
///
///
///
///                     ~               ~
///                   ~  ~             ~ ~
///                  ~    ~           ~   ~
///                 ~      ~         ~     ~
/// ---------------~        ~       ~       ~--------------------------------
///                          ~     ~
///                           ~   ~
///                             ~
///
///
static variable PSQ_CR_FindDependentAnalysisParameter(string device, string name, string params)
static std::tuple<variable, variable> PSQ_CR_GetSpikeEvaluationRange(string device, variable sweepNo, variable headstage)

Return the begin/start [ms] of the spike bounds evaluation range.

Zero is the DA/AD wave zero.

static std::tuple<variable, variable> PSQ_CR_GetChirpEvaluationRange(string device, variable sweepNo, variable headstage, variable requestedCycles)

Return the begin/start [ms] of the chirp bounds evaluation range.

Zero is the DA/AD wave zero.

static variable PSQ_ForceSetEvent(string device, variable headstage)

Manually force the pre/post set events.

Required to do before skipping sweeps.

Todo:

this hack must go away.

static string PSQ_ExecuteSweepFormula(string device, string code)

Execute code in the SweepFormula notebook.

static variable PSQ_SetSamplingIntervalMultiplier(string device, variable multiplier)
static variable PSQ_SetStimulusSets(string device, variable headstage, string params)
string PSQ_PipetteInBath_CheckParam(string name, CheckParametersStruct *s)
string PSQ_PipetteInBath_GetHelp(string name)
string PSQ_PipetteInBath_GetParams()
variable PSQ_PipetteInBath(string device, AnalysisFunction_V3 *s)

Analysis function for determining the pipette resistance while that is located in the bath.

Prerequisites:

  • Does only work for one headstage

  • We expect three epochs per test pulse in the stimset, plus one epoch before all TPs, and at the very end

  • Assumes that the stimset has NumberOfTestpulses test pulses

  • Pre pulse baseline length is PSQ_BL_EVAL_RANGE

  • Post pulse baseline is not evaluated

Testing: For testing the range detection logic, the results can be defined in the wave root:overrideResults.

Decision logic flowchart:

///
/// Sketch of a stimset with three test pulse like epochs
///
///                    +-----+       +-----+       +-----+
///                    |     |       |     |       |     |
///                    |     |       |     |       |     |
///                    |     |       |     |       |     |
/// -------------------+     +-------+     +-------+     +------------------------
///
/// Epoch borders
/// -------------
///
///       0        | 1 |  2  | 3 | 4 |  5  | 6 | 7 |  8  | 9 |     10
///
///
static wave PSQ_GetSweepFormulaResultWave(WaveText textualResultsValues, string key, variable sweepNo)
static variable PSQ_GetSweepFormulaResult(WaveText textualResultsValues, string key, variable sweepNo)
static variable PSQ_PB_GetPrePulseBaselineDuration(string device, variable headstage)
static variable PSQ_CreateTestpulseEpochs(string device, variable headstage, variable numTestPulses)

Create user epochs for the testpulse like shapes in the stimset.

Assumes that all sweeps in the stimset are the same.

Returns:

0 on success, 1 on failure

static variable PSQ_CreateTestpulseLikeEpoch(string device, variable DAC, string setName, variable DAScale, variable start, variable epochIndex, variable tpIndex)
string PSQ_SealEvaluation_CheckParam(string name, CheckParametersStruct *s)
string PSQ_SealEvaluation_GetHelp(string name)
string PSQ_SealEvaluation_GetParams()
variable PSQ_SealEvaluation(string device, AnalysisFunction_V3 *s)

Analysis function for checking the seal resistance.

Prerequisites:

  • Does only work for one headstage

  • See below for the stimset layout

  • The dedicated baseline epochs before each testpulse group (epoch 0 and 11) and must be at least as large as the given BaselineChunkLength analysis parameter

Testing: For testing the range detection logic, the results can be defined in the wave root:overrideResults.

Decision logic flowchart:

///
/// Sketch of the stimset
///
///                    +-----+       +-----+       +-----+                                    +-----+       +-----+       +-----+
///                    |     |       |     |       |     |                                    |     |       |     |       |     |
///                    |     |       |     |       |     |                                    |     |       |     |       |     |
///                    |     |       |     |       |     |                                    |     |       |     |       |     |
/// -------------------+     +-------+     +-------+     +------------------------------------+     +-------+     +-------+     +------------
///
/// Epoch borders
/// -------------
///
///       0        | 1 |  2  | 3 | 4 |  5  | 6 | 7 |  8  | 9 |             10    |     11 | 12| 13  | 14| 15| 16  | 17|18 | 19  | 20 |  21  |
///
/// We always expect PSQ_SE_REQUIRED_EPOCHS (22) epochs even if the user only chose `First` or `Second` on testpulse selection.
///
///    BEGIN group A
/// 0: baselineQC chunk with length `BaselineChunkLength` or longer before group A
/// 1-3: 1. TP
/// 4-6: 2. TP
/// 7-9: 3. TP
///    END group A
/// 10: empty space, can be zero points long, but is always present
///    BEGIN group B
/// 11: baselineQC chunk with length `BaselineChunkLength` or longer before group B
/// 12-14: 1. TP
/// 15-17: 2. TP
/// 18-20: 3. TP
///    END group B
/// 21: trailing empty space
///
///
static variable PSQ_SE_CreateEpochs(string device, variable headstage, string params)

Create user epochs.

Assumes that all sweeps in the stimset are the same.

Returns:

0 on success, 1 on failure

static variable PSQ_SE_GetTestpulseGroupSelection(string params)
static variable PSQ_SE_ParseTestpulseGroupSelection(string str)
string PSQ_TrueRestingMembranePotential_CheckParam(string name, CheckParametersStruct *s)
string PSQ_TrueRestingMembranePotential_GetHelp(string name)
string PSQ_TrueRestingMembranePotential_GetParams()
variable PSQ_TrueRestingMembranePotential(string device, AnalysisFunction_V3 *s)

Analysis function for determining the mean potential of a stimset.

Prerequisites:

  • Does only work for one headstage

  • See below for the stimset layout

Testing: For testing the range detection logic, the results can be defined in the wave root:overrideResults.

Decision logic flowchart:

///
/// Sketch of the stimset
///
/// --------------------------------------------
///
/// Epoch borders
/// -------------
///
/// |         0          | 1 |        2        |
///
/// We always expect PSQ_VM_REQUIRED_EPOCHS (3) epochs.
///
/// 0: baselineQC chunk with length `BaselineChunkLength` or larger
/// 1: empty space, can be zero points long, but is always present
/// 2: baselineQC chunk with length `BaselineChunkLength` or larger
///
///
static std::tuple<string, string> PSQ_CreateBaselineChunkSelectionStrings(variable index)
static variable PSQ_CreateBaselineChunkSelectionEpochs(string device, variable headstage, string params, wave epochIndizes, variable numRequiredEpochs = defaultValue)

Create baseline selection epochs.

Assumes that all sweeps in the stimset are the same.

Parameters:
  • device – device

  • headstage – headstage

  • params – analysis function parameters

  • epochIndizes – indizes of stimset epochs for which we should create BLS epochs

  • numRequiredEpochs – number of required epochs in the stimset, use

Returns:

0 on success, 1 on failure

static variable PSQ_DetermineSweepQCResults(string device, variable type, variable sweepNo, variable headstage, variable requiredPassesInSet, variable numSweepsFailedAllowed)

Check if we need to act on the now available sweep QC state.

Parameters:
  • device – device

  • type – analysis function type

  • sweepNo – sweep number

  • headstage – headstage

  • requiredPassesInSet – number of passes in set which makes the set pass

  • numSweepsFailedAllowed – number of failures in set which makes the set fail

Returns:

One of DetermineSweepQCReturns

static variable PSQ_VM_EvaluateAverageVoltage(string device, variable sweepNo, variable headstage, string params, variable baselineQCPassed)
static std::tuple<variable, WAVE> PSQ_VM_CheckForSpikes(string device, variable sweepNo, variable headstage, wave scaledDACWave, variable level)
static variable PSQ_VM_HandleFailingSpikeQC(string device, AnalysisFunction_V3 *s, wave spikePositions)
static variable PSQ_CheckThatAlarmIsEnabled(string device, wave asyncChannels)
static variable PSQ_CheckAsyncAlarmStateAndStoreInLabnotebook(string device, variable type, variable sweepNo, wave asyncChannels)
string PSQ_AccessResistanceSmoke_CheckParam(string name, CheckParametersStruct *s)
string PSQ_AccessResistanceSmoke_GetHelp(string name)
string PSQ_AccessResistanceSmoke_GetParams()
variable PSQ_AccessResistanceSmoke(string device, AnalysisFunction_V3 *s)

Analysis function for determining the TP resistances and their ratio.

Prerequisites:

  • Does only work for one headstage

  • We expect three epochs per test pulse in the stimset, plus one epoch before all TPs, and at the very end

  • Assumes that the stimset has NumberOfTestpulses test pulses

  • Pre pulse baseline length is given by BaselineChunkLength

  • Post pulse baseline is not evaluated

Testing: For testing the range detection logic, the results can be defined in the wave root:overrideResults.

Decision logic flowchart:

///
/// Sketch of a stimset with three test pulse like epochs
///
///                    +-----+       +-----+       +-----+
///                    |     |       |     |       |     |
///                    |     |       |     |       |     |
///                    |     |       |     |       |     |
/// -------------------+     +-------+     +-------+     +------------------------
///
/// Epoch borders
/// -------------
///
///        0       | 1 |  2  | 3 | 4 |  5  | 6 | 7 |  8  | 9 |      10
///
/// So for this stimset we have two epochs at the very beginning and end, plus
/// three epochs per test pulse and three test pulses, which gives eleven in
/// total.
///
///

Variables

static const double PSQ_BL_PRE_PULSE = 0x0
static const double PSQ_BL_POST_PULSE = 0x1
static const double PSQ_BL_GENERIC = 0x2
static const double PSQ_RMS_SHORT_TEST = 0x0
static const double PSQ_RMS_LONG_TEST = 0x1
static const double PSQ_TARGETV_TEST = 0x2
static const double PSQ_LEAKCUR_TEST = 0x3
static const double PSQ_DEFAULT_SAMPLING_MULTIPLIER = 4
static const double PSQ_RHEOBASE_DURATION = 500