Skip to content

Commit e4688d8

Browse files
committed
updated FreqAnalysis to allow for alternate channel inputs (e.g., to have PD signal in same output format),fixed FreqAnalysis allLeakSub losing alignment with allSweeps bc no vertcat meant empties remained
1 parent 6a2b527 commit e4688d8

2 files changed

Lines changed: 51 additions & 16 deletions

File tree

Analysis/SK/Scripts-in-progress/FrequencyAnalysis.m

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
p.addParameter('tauType','thalfmax', @(x) ischar(x) && ismember(x,{'fit' 'thalfmax'}));
2121
p.addParameter('integrateCurrent',1);
2222
p.addParameter('normToOn1',0);
23-
p.addParameter('matchPhase',0');
23+
p.addParameter('matchPhase',0);
24+
p.addParameter('channel',1, @(x) isnumeric(x) && ismember(x,1:6));
2425

2526
p.parse(ephysData, ephysMetaData, protList, varargin{:});
2627

@@ -30,6 +31,7 @@
3031
integrateFlag = p.Results.integrateCurrent;
3132
normalizeFlag = p.Results.normToOn1;
3233
phaseFlag = p.Results.matchPhase;
34+
channel = p.Results.channel;
3335

3436
% Load and format Excel file with lists (col1 = cell name, col2 = series number,
3537
% col 3 = comma separated list of good traces for analysis)
@@ -52,6 +54,7 @@
5254
sortStimBy = 'time';
5355
sortSweepsBy = {'frequency'};
5456
stimSortOrder = [1 2];
57+
sqWindow = 5;
5558

5659
% pull cell distances and filter freqs
5760
allCellInd = cellfun(@(x) find(strcmp(ephysMetaData(:,1),x)),allCells,'un',0)';
@@ -83,7 +86,7 @@
8386
end
8487

8588
% Initialize for allSeries
86-
allLeakSub = cell(0);
89+
allLeakSub = cell(nSeries,1);
8790
allSweeps = cell(nSeries,2);
8891
allSine = cell(0);
8992
stimSquareSum = [];
@@ -102,8 +105,9 @@
102105
catch
103106
end
104107

108+
probeI = ephysData.(cellName).data{channel,thisSeries}(:,pickedTraces);
109+
105110

106-
probeI = ephysData.(cellName).data{1,thisSeries}(:,pickedTraces);
107111
stimComI = ephysData.(cellName).data{2,thisSeries}(:,pickedTraces); %in V, not um
108112
% sampling frequency in kHz
109113
sf = ephysData.(cellName).samplingFreq{thisSeries} ./ 1000;
@@ -151,9 +155,14 @@
151155

152156
sineTrace = leakSubtract(sineParams(1):sineParams(2));
153157

154-
% Take the average current of the last steadyTime ms of the
155-
% sine trace, regardless of sine frequency.
156-
steadyStateI = -mean(sineTrace(end-steadyTime*sf:end))*1e12;
158+
if channel == 1 % to units of pA
159+
% Take the average current of the last steadyTime ms of the
160+
% sine trace, regardless of sine frequency.
161+
steadyStateI = -mean(sineTrace(end-steadyTime*sf:end))*1e12;
162+
163+
else % original units
164+
steadyStateI = mean(sineTrace(end-steadyTime*sf:end));
165+
end
157166

158167
theseSines = [sineParams steadyStateI thisSeries];
159168
% Implement later: use fit to calculate time constant of decay from peak
@@ -171,14 +180,30 @@
171180

172181

173182
% Find MRC peaks at the on and off of square stimuli.
174-
theseSquares = [];
175-
for iStim = 1:size(squareParams,1)
176-
theseSquares(iStim,:) = findMRCs(squareParams(iStim,:), leakSubtract, sf, dataType, ...
177-
'tauType', tauType, 'integrateCurrent',integrateFlag);
183+
theseSquares = nan(4,13); %adjust this if you change findMRCs output
184+
185+
if channel == 1
186+
for iStim = 1:size(squareParams,1)
187+
theseSquares(iStim,:) = findMRCs(squareParams(iStim,:), leakSubtract, sf, dataType, ...
188+
'tauType', tauType, 'integrateCurrent',integrateFlag);
189+
end
190+
191+
else % just find the actual voltage at the start and end of each step
192+
theseSquareAmps = nan(4,1);
193+
for iStim = 1:size(squareParams,1)
194+
if squareParams(iStim, 3) >= 0
195+
theseSquareAmps(iStim) = mean(leakSubtract(squareParams(iStim,1)+sf:squareParams(iStim,1)+sqWindow*sf*2));
196+
else
197+
theseSquareAmps(iStim) = mean(leakSubtract(squareParams(iStim,1)-sqWindow*sf:squareParams(iStim,1)));
198+
end
199+
end
200+
theseSquares(:,1:4) = squareParams(:,3:6);
201+
theseSquares(:,5:6) = [squareParams(:,1) theseSquareAmps];
202+
theseSquares(:,13:14) = squareParams(:,7:8);
178203
end
204+
179205
theseSquares = [theseSquares repmat(sineParams(4),iStim,1) repmat(thisSeries,iStim,1)];
180206

181-
182207
%TODO: add to Sine output: peak at start, beginning average, tau of
183208
% fit of smoothed trace
184209
%TODO: add to SquareSum output: interval between squares, and
@@ -214,6 +239,7 @@
214239

215240
allSineSum = vertcat(allSweeps{:,1});
216241
allSquareSum = vertcat(allSweeps{:,2});
242+
allLeakSub = allLeakSub(~cellfun(@isempty,allLeakSub));
217243
for iStim = 1:max(allSquareSum(:,13))
218244
stimSquareSum(:,:,iStim) = allSquareSum(allSquareSum(:,13)==iStim,:);
219245
end
@@ -272,7 +298,7 @@
272298
% stimSortOrder. Use unique to find unique sets of rows/stimulus
273299
% profiles and separate them into groups.
274300
[sweepsByParams, sortIdx] = sortrows(sweepsByParams, stimSortOrder(1:size(sweepsByParams,2)));
275-
sortedLeakSub = allLeakSub(sortIdx,:);
301+
sortedLeakSub = allLeakSub(sortIdx);
276302
sortedSquares = stimSquareSum(sortIdx,:,:);
277303

278304
for iStim = 1:nStim
@@ -345,7 +371,11 @@
345371

346372
if normalizeFlag
347373
steadyMeans = steadyMeans./squareMeans(:,1);
348-
normMeans = num2cell(squareMeans(:,1)*1e-12);
374+
if channel == 1
375+
normMeans = num2cell(squareMeans(:,1)*1e-12);
376+
else
377+
normMeans = num2cell(squareMeans(:,1));
378+
end
349379
theseSweeps = cellfun(@(x,y) x/y, theseSweeps,normMeans','un',0);
350380
end
351381

Analysis/SK/Scripts-in-progress/SinePowerSpec.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
sinePeaksNorm = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 1);
7272

7373
sinePeaks = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 0);
74+
75+
sinePeaksPD = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 0, 'channel',3);
76+
7477
% okay we're just going to plot the power spectrum in the morning and
7578
% ignore the bode plot because I don't know what a "system" object really
7679
% is in matlab or if my data can be one, or what a linear time-invariant
@@ -81,13 +84,15 @@
8184
allPSD = [];
8285
allF = [];
8386
allSize = [];
87+
88+
whichPeaks = sinePeaks;
8489
% ally = []; %for plotting fft magnitude and phase
8590
% allf_fft = [];
8691

8792

88-
for iRec = 1:size(sinePeaksNorm,1)
89-
theseRecs = sinePeaksNorm{iRec,2};
90-
theseSizes = sinePeaksNorm{iRec,3}(:,1:3);
93+
for iRec = 1:size(whichPeaks,1)
94+
theseRecs = whichPeaks{iRec,2};
95+
theseSizes = whichPeaks{iRec,3}(:,1:3);
9196

9297
for iFreq = 1:length(theseRecs)
9398
try thisRec = theseRecs{iFreq}(theseSizes(iFreq,1):theseSizes(iFreq,2),:);

0 commit comments

Comments
 (0)