Skip to content

Commit 6c5c216

Browse files
authored
Merge pull request #1894 from AllenInstitute/feature/1894-dascale-adaptive-supra-threshold
PSQ_DAScale: Add adaptive suprathreshold
2 parents 18d1f07 + b5300a3 commit 6c5c216

12 files changed

+3828
-441
lines changed

Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ static Function/S AD_GetResultMessage(variable anaFuncType, variable passed, WAV
116116

117117
// PSQ_DA
118118
// - baseline QC
119-
// - needs at least $NUM_DA_SCALES passing sweeps
120-
// and for supra mode if the FinalSlopePercent parameter is present this has to be reached as well
119+
// - SUB/SUPRA: needs at least $NUM_DA_SCALES passing sweeps
120+
// - SUPRA: if the FinalSlopePercent parameter is present this has to be reached as well
121+
// - ADAPT: - fewer than $NumInvalidSlopeSweepsAllowed invalid f-I slopes
122+
// - fISlopeReached QC or initial f-I slope QC was invalid
123+
// - measured all future DAScale values
124+
// - enough points for Fit QC
121125

122126
// PSQ_PB
123127
// - baseline QC
@@ -477,8 +481,9 @@ static Function/S AD_GetDAScaleFailMsg(numericalValues, textualValues, sweepNo,
477481
DFREF sweepDFR
478482
variable headstage
479483

480-
string msg, key, fISlopeStr
481-
variable numPasses, numRequiredPasses, finalSlopePercent
484+
string msg, key, fISlopeStr, opMode
485+
variable numPasses, numRequiredPasses, finalSlopePercent, slopePercentage, measuredAllFutureDAScales
486+
variable numInvalidSlopeSweepsAllowed, numFailedSweeps
482487

483488
numPasses = PSQ_NumPassesInSet(numericalValues, PSQ_DA_SCALE, sweepNo, headstage)
484489

@@ -489,11 +494,50 @@ static Function/S AD_GetDAScaleFailMsg(numericalValues, textualValues, sweepNo,
489494
WAVE/T params = GetLastSettingTextSCI(numericalValues, textualValues, sweepNo, "Function params", headstage, DATA_ACQUISITION_MODE)
490495
endif
491496

492-
WAVE/Z DAScales = AFH_GetAnalysisParamWave("DAScales", params[headstage])
493-
ASSERT(WaveExists(DASCales), "analysis function parameters don't have a DAScales entry")
494-
numRequiredPasses = DimSize(DAScales, ROWS)
497+
opMode = AFH_GetAnalysisParamTextual("OperationMode", params[headstage])
498+
499+
strswitch(opMode)
500+
case PSQ_DS_SUB:
501+
case PSQ_DS_SUPRA:
502+
503+
WAVE/Z DAScales = AFH_GetAnalysisParamWave("DAScales", params[headstage])
504+
ASSERT(WaveExists(DASCales), "analysis function parameters don't have a DAScales entry")
505+
numRequiredPasses = DimSize(DAScales, ROWS)
506+
507+
msg = AD_GetPerSweepFailMessage(PSQ_DA_SCALE, numericalValues, textualValues, sweepNo, sweepDFR, headstage, numRequiredPasses = numRequiredPasses)
508+
break
509+
case PSQ_DS_ADAPT:
510+
msg = AD_GetPerSweepFailMessage(PSQ_DA_SCALE, numericalValues, textualValues, sweepNo, sweepDFR, headstage)
511+
512+
if(!IsEmpty(msg))
513+
return msg
514+
endif
515+
516+
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES_PASS, query = 1)
517+
measuredAllFutureDAScales = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)
518+
519+
if(!measuredAllFutureDAScales)
520+
sprintf msg, "Could not acquire all requested future DAScale values"
521+
endif
522+
523+
if(!IsEmpty(msg))
524+
return msg
525+
endif
526+
527+
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_VALID_SLOPE_PASS, query = 1)
528+
WAVE slopePasses = GetLastSettingEachSCI(numericalValues, sweepNo, key, headstage, UNKNOWN_MODE)
529+
numFailedSweeps = DimSize(slopePasses, ROWS) - Sum(slopePasses)
530+
531+
numInvalidSlopeSweepsAllowed = AFH_GetAnalysisParamNumerical("NumInvalidSlopeSweepsAllowed", params[headstage])
532+
533+
if(numFailedSweeps >= numInvalidSlopeSweepsAllowed)
534+
sprintf msg, "Encountered %g sweeps with invalid slopes, but only %g are allowed.", numFailedSweeps, numInvalidSlopeSweepsAllowed
535+
endif
536+
break
537+
default:
538+
ASSERT(0, "Invalid opMode")
539+
endswitch
495540

496-
msg = AD_GetPerSweepFailMessage(PSQ_DA_SCALE, numericalValues, textualValues, sweepNo, sweepDFR, headstage, numRequiredPasses = numRequiredPasses)
497541
if(!IsEmpty(msg))
498542
return msg
499543
endif
@@ -509,7 +553,25 @@ static Function/S AD_GetDAScaleFailMsg(numericalValues, textualValues, sweepNo,
509553

510554
finalSlopePercent = AFH_GetAnalysisParamNumerical("FinalSlopePercent", params[headstage])
511555

512-
sprintf msg, "Failure as we did not reach the required fI slope (target: %g%% reached: %s%%)", finalSlopePercent, fISlopeStr
556+
if(IsFinite(finalSlopePercent))
557+
// Supra
558+
sprintf msg, "Failure as we did not reach the required fI slope (target: %g%% reached: %s%%)", finalSlopePercent, fISlopeStr
559+
else
560+
// Adaptive Suprathreshold
561+
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_INIT_VALID_SLOPE_PASS, query = 1)
562+
WAVE initialFISlopeValid = GetLastSettingSCI(numericalValues, sweepNo, key, headstage, UNKNOWN_MODE)
563+
564+
if(initialFISlopeValid[headstage])
565+
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_MAX_SLOPE, query = 1)
566+
WAVE maxSlopeLBN = GetLastSetting(numericalValues, sweepNo, key, UNKNOWN_MODE)
567+
568+
slopePercentage = AFH_GetAnalysisParamNumerical("SlopePercentage", params[headstage])
569+
fISlope[p] = maxSlopeLBN[headstage] * (1 - (slopePercentage * PERCENT_TO_ONE))
570+
fISlopeStr = RemoveEnding(NumericWaveToList(fISlope, "%, ", format = "%.15g"), "%, ")
571+
sprintf msg, "The fit slope was not small enough for the given slope percentage (target: %g%% reached: %s%%)", slopePercentage, fISlopeStr
572+
endif
573+
endif
574+
513575
return msg
514576
endif
515577

@@ -726,7 +788,7 @@ static Function/S AD_GetPerSweepFailMessage(variable anaFuncType, WAVE numerical
726788
string key, msg, str
727789
string text = ""
728790
variable numPasses, i, numSweeps, sweepNo, boundsAction, spikeCheck, resistancePass, accessRestPass, resistanceRatio
729-
variable avgCheckPass, stopReason, stimsetQC, baselineQC
791+
variable avgCheckPass, stopReason, stimsetQC, baselineQC, enoughFIPointsQC
730792
string perSweepFailedMessage = ""
731793

732794
if(!ParamIsDefault(numRequiredPasses))
@@ -854,6 +916,23 @@ static Function/S AD_GetPerSweepFailMessage(variable anaFuncType, WAVE numerical
854916
sprintf text, "Sweep %d failed: Limited resolution", sweepNo
855917
break
856918
endif
919+
920+
key = CreateAnaFuncLBNKey(anaFuncType, PSQ_FMT_LBN_DA_AT_ENOUGH_FI_POINTS_PASS, query = 1)
921+
enoughFIPointsQC = GetLastSettingIndep(numericalValues, sweepNo, key, UNKNOWN_MODE)
922+
923+
if(IsFinite(enoughFIPointsQC) && !enoughFIPointsQC)
924+
sprintf text, "Sweep %d failed: Not enough points for fit", sweepNo
925+
break
926+
endif
927+
928+
key = CreateAnaFuncLBNKey(anaFuncType, PSQ_FMT_LBN_DA_AT_VALID_SLOPE_PASS, query = 1)
929+
WAVE/Z validFitSlope = GetLastSetting(numericalValues, sweepNo, key, UNKNOWN_MODE)
930+
931+
if(WaveExists(validFitSlope) && !validFitSlope[headstage])
932+
sprintf text, "Sweep %d failed: Invalid fit slope", sweepNo
933+
break
934+
endif
935+
857936
break
858937
case PSQ_PIPETTE_BATH:
859938
[baselineQC, msg] = AD_GetBaselineFailMsg(anaFuncType, numericalValues, sweepNo, headstage)

0 commit comments

Comments
 (0)