Skip to content

Commit

Permalink
fix: correctly define unit type when isolation distances are computed
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie-Fabre committed Sep 8, 2023
1 parent c5d7907 commit 583564a
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 688 deletions.
122 changes: 122 additions & 0 deletions qualityMetrics/bc_getQualityUnitType.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
function unitType = bc_getQualityUnitType(param, qMetric)
% JF, Classify units into good/mua/noise/non-somatic
% ------
% Inputs
% ------
%
% ------
% Outputs
% ------
if param.computeDistanceMetrics && ~isnan(param.isoDmin) && param.computeDrift && param.extractRaw
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDistanceMetrics && ~isnan(param.isoDmin) && param.computeDrift
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDrift && param.extractRaw

unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.rawAmplitude > param.minAmplitude & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDistanceMetrics && ~isnan(param.isoDmin) && param.extractRaw
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & isnan(unitType)& ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDrift
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDistanceMetrics && ~isnan(param.isoDmin)
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);

unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & ...
qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.extractRaw
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

else
unitType = nan(length(qMetric.percentageSpikesMissing_gaussian), 1);
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.presenceRatio >= param.minPresenceRatio & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

end
64 changes: 32 additions & 32 deletions qualityMetrics/bc_getQualityUnitType.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & isnan(unitType)& ...
qMetric.rawAmplitude' > param.minAmplitude & qMetric.isoD' >= param.isoDmin &...
qMetric.Lratio' <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDistanceMetrics && ~isnan(param.isoDmin) && param.computeDrift
Expand All @@ -28,13 +28,13 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & isnan(unitType)& ...
qMetric.isoD' >= param.isoDmin &...
qMetric.Lratio' <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDrift && param.extractRaw
Expand All @@ -44,12 +44,12 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & isnan(unitType)& ...
qMetric.rawAmplitude' > param.minAmplitude & isnan(unitType)) = 1; % SINGLE SEXY UNIT
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
qMetric.rawAmplitude > param.minAmplitude & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDistanceMetrics && ~isnan(param.isoDmin) && param.extractRaw
Expand All @@ -58,13 +58,13 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & qMetric.signalToNoiseRatio >= param.minSNR &...
qMetric.presenceRatio >= param.minPresenceRatio & isnan(unitType)& ...
qMetric.rawAmplitude' > param.minAmplitude & qMetric.isoD' >= param.isoDmin &...
qMetric.Lratio' <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
qMetric.rawAmplitude > param.minAmplitude & qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.computeDrift
Expand All @@ -73,11 +73,11 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & isnan(unitType)& ...
qMetric.presenceRatio >= param.minPresenceRatio & qMetric.maxDriftEstimate <= param.maxDrift & ...
isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

Expand All @@ -87,13 +87,13 @@
unitType(qMetric.nPeaks > param.maxNPeaks | qMetric.nTroughs > param.maxNTroughs | ...
qMetric.spatialDecaySlope >= param.minSpatialDecaySlope | qMetric.waveformDuration_peakTrough < param.minWvDuration |...
qMetric.waveformDuration_peakTrough > param.maxWvDuration | qMetric.waveformBaselineFlatness >= param.maxWvBaselineFraction) = 0; % NOISE
unitType(qMetric.isSomatic' ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian' <= param.maxPercSpikesMissing & qMetric.nSpikes' > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR' <= param.maxRPVviolations & ...
unitType(qMetric.isSomatic ~= param.somatic & isnan(unitType)) = 3; % NON-SOMATIC
unitType(qMetric.percentageSpikesMissing_gaussian <= param.maxPercSpikesMissing & qMetric.nSpikes > param.minNumSpikes & ...
qMetric.fractionRPVs_estimatedTauR <= param.maxRPVviolations & ...
qMetric.rawAmplitude > param.minAmplitude & ...
qMetric.presenceRatio >= param.minPresenceRatio & isnan(unitType)& ...
qMetric.isoD' >= param.isoDmin &...
qMetric.Lratio' <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
qMetric.presenceRatio >= param.minPresenceRatio & ...
qMetric.isoD >= param.isoDmin &...
qMetric.Lratio <= param.lratioMax & isnan(unitType)) = 1; % SINGLE SEXY UNIT
unitType(isnan(unitType)) = 2; % MULTI UNIT

elseif param.extractRaw
Expand Down
2 changes: 1 addition & 1 deletion qualityMetrics/bc_runAllQualityMetrics.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@
end

unitType = bc_getQualityUnitType(param, qMetric);
%bc_plotGlobalQualityMetric(qMetric, param, unitType, uniqueTemplates, forGUI.tempWv);
bc_plotGlobalQualityMetric(qMetric, param, unitType, uniqueTemplates, forGUI.tempWv);
end
Loading

0 comments on commit 583564a

Please sign in to comment.