Skip to content

Commit 8ba7104

Browse files
committed
fixed Freq and NonStat Analysis for updated findMRCs, Igor outputs for preindent and attenuation scripts, fixed findMRCs output columns, simplified roundVel
1 parent ae64335 commit 8ba7104

9 files changed

Lines changed: 230 additions & 39 deletions

File tree

Analysis/SK/AnnotatedScripts/AntVsPost_VoltageAttenuation_180803.m

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@
5656
% sweeps where the recording was lost partway through or some unexpected
5757
% source of noise was clearly at play.
5858

59-
protList ={'WC_Probe';'NoPre'};
60-
matchType = 'first';
59+
protList ={'WC_Probe';'WC_ProbeSmall';'WC_ProbeLarge';'NoPrePulse'};
60+
matchType = 'full';
6161

6262
ExcludeSweeps(ephysData, protList, anteriorDistCells, 'matchType', matchType);
6363
ExcludeSweeps(ephysData, protList, posteriorDistCells, 'matchType', matchType);
6464

65-
%% Find MRCs
65+
%% Find MRCs
66+
% antAllSteps.xlsx and postAllSteps.xlsx
67+
protList ={'WC_Probe';'NoPre'};
68+
matchType = 'first';
69+
6670
sortSweeps = {'magnitude','magnitude','magnitude','magnitude'};
6771

6872
anteriorMRCs = IdAnalysis(ephysData,protList,anteriorDistCells,'num','matchType',matchType, ...
@@ -87,7 +91,7 @@
8791
% the recording name against the voltage attenuation table to find the
8892
% attenuation factor for that recording.
8993
whichMRCs = anteriorMRCs;
90-
thisAtt = attenuationData(:,[2 10]);
94+
thisAtt = attenuationData(:,[2 8 10]);
9195
distVPeak = [];
9296
stepSize = 10;
9397

@@ -98,8 +102,8 @@
98102
thisName = whichMRCs{iCell,1};
99103
hasAtt = strcmp(thisName,thisAtt(:,1));
100104

101-
if any(hasAtt)
102-
distVPeak(iCell,:) = [thisCell(whichStep,[11 6]) thisAtt{hasAtt,2}];
105+
if any(hasAtt) && thisAtt{hasAtt,2}
106+
distVPeak(iCell,:) = [thisCell(whichStep,[11 6]) thisAtt{hasAtt,3}];
103107
else
104108
distVPeak(iCell,:) = [thisCell(whichStep,[11 6]) nan];
105109
end
@@ -166,12 +170,101 @@
166170
figure(); axh(1) = subplot(2,1,1);
167171
scatter(distVPeak_Ant(:,1),distVPeak_Ant(:,4));
168172
xlabel('Distance from cell body (um)');
169-
ylabel('Current @10um (pA)')
173+
ylabel(sprintf('Current @%dum (pA)',stepSize))
170174
text(100,200,'Anterior');
171175
axh(2) = subplot(2,1,2);
172176
scatter(distVPeak_Post(:,1),distVPeak_Post(:,2));
173177
xlabel('Distance from cell body (um)');
174-
ylabel('Current @10um (pA)')
178+
ylabel(sprintf('Current @%dum (pA)',stepSize))
175179
text(100,200,'Posterior');
176180

177-
xlim(axh,[0 200]); ylim(axh,[0 200]);
181+
for i = 1:length(axh)
182+
xlim(axh(i),[0 200]);
183+
ylim(axh(i),[0 200]);
184+
end
185+
186+
%% Plot on one plot
187+
188+
figure();
189+
scatter(distVPeak_Ant(:,1),distVPeak_Ant(:,4));
190+
hold on;
191+
scatter(-distVPeak_Post(:,1),distVPeak_Post(:,2));
192+
xlabel('Distance from cell body (um)');
193+
ylabel(sprintf('Current @%dum (pA)',stepSize))
194+
xlim([-100 200]);ylim([0 200]);
195+
vline(0,'k:');
196+
197+
%% Correct all sizes and export for Igor fitting of Boltzmann to each recording
198+
199+
Vc = -0.06; %in V
200+
Ena = 0.094; % in V
201+
202+
whichMRCs = anteriorMRCs;
203+
thisAtt = attenuationData(:,[2 8 10]);
204+
thisName = cell(0);
205+
ant_Out = cell(length(eachSize)+1,size(whichMRCs,1));
206+
207+
for iCell = 1:size(whichMRCs,1)
208+
thisCell = whichMRCs{iCell,3};
209+
thisName{iCell,1} = whichMRCs{iCell,1}; %name
210+
thisName{iCell,2} = mean(thisCell(:,11)); %distance
211+
ant_Out{1,iCell} = thisName{iCell,1};
212+
hasAtt = strcmp(thisName{iCell,1},thisAtt(:,1));
213+
Iact = [];
214+
215+
for iSize = 1:length(eachSize)
216+
stepSize = eachSize(iSize);
217+
whichStep = round(thisCell(:,1)*2)/2 == stepSize; %round to nearest 0.5
218+
if any(whichStep)
219+
220+
if any(hasAtt) && thisAtt{hasAtt,2} %if attenuation calc exists and not omitCell
221+
Vm = Vc * thisAtt{hasAtt,3};
222+
Im = thisCell(whichStep,6);
223+
Iact(iSize,1) = (Im * (Vc-Ena)) ./ (Vm-Ena);
224+
else
225+
Iact(iSize,1) = nan;
226+
end
227+
228+
else
229+
Iact(iSize,1) = nan;
230+
end
231+
end
232+
ant_Out(2:length(eachSize)+1,iCell) = num2cell(Iact);
233+
234+
end
235+
ant_Name = [{'Anterior', 'Ant_Dist'}; thisName];
236+
237+
thisName = cell(0);
238+
whichMRCs = posteriorMRCs;
239+
post_Out = cell(length(eachSize)+1,size(whichMRCs,1));
240+
241+
for iCell = 1:size(whichMRCs,1)
242+
thisCell = whichMRCs{iCell,3};
243+
thisName{iCell,1} = whichMRCs{iCell,1}; %name
244+
thisName{iCell,2} = mean(thisCell(:,11)); %distance
245+
post_Out{1,iCell} = thisName{iCell,1};
246+
Iact = [];
247+
248+
for iSize = 1:length(eachSize)
249+
stepSize = eachSize(iSize);
250+
whichStep = round(thisCell(:,1)*2)/2 == stepSize; %round to nearest 0.5
251+
if any(whichStep)
252+
Iact(iSize,1) = thisCell(whichStep,6);
253+
else
254+
Iact(iSize,1) = nan;
255+
end
256+
end
257+
post_Out(2:length(eachSize)+1,iCell) = num2cell(Iact);
258+
259+
end
260+
261+
ant_Out = [[{'stepSize'};num2cell(eachSize)] ant_Out];
262+
post_Name = [{'Posterior', 'Post_Dist'}; thisName];
263+
264+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',ant_Out,'ant');
265+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',post_Out,'post');
266+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',ant_Name,'antStats');
267+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',post_Name,'postStats');
268+
269+
270+
clear iCell thisCell Iact whichMRCs whichStep hasAtt thisAtt Vc Ena thisName

Analysis/SK/ExcludeSweeps.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@
210210
end
211211
end
212212

213+
keepRows = cellfun(@(x) ~isempty(x), selectedSweeps(:,3));
214+
selectedSweeps = selectedSweeps(keepRows,:);
213215

214216
% Ask where to save and write out the .xls file)
215217
[filename, pathname] = uiputfile(...
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
% The point of this function is to grab the data from Igor or from an Excel
2+
% sheet after fitting individual I-d curves to get max/delta/xhalf from the
3+
% Boltzmann fit, then normalize each I-d curve to its predicted max, and
4+
% export back into an Igor-readable format for plotting.
5+
%% Import fits from Igor table
6+
7+
fitStats = ImportMetaData(); %AttCorrectedI-D_fitstats.xlsx
8+
fitHeaders = fitStats(1,:);
9+
fitStats = fitStats(2:end,:);
10+
11+
%% Get names and match up stats
12+
antStats = fitStats(:,cell2mat(cellfun(@(x) ~isempty(regexp(x,'Ant')), fitHeaders,'un',0)));
13+
postStats = fitStats(:,cell2mat(cellfun(@(x) ~isempty(regexp(x,'Post')), fitHeaders,'un',0)));
14+
antStats = antStats(cellfun(@(x) ~isnumeric(x), antStats(:,1)),:);
15+
postStats = postStats(cellfun(@(x) ~isnumeric(x), postStats(:,1)),:);
16+
17+
% this gives five columns: name, delta, distance, max, xhalf
18+
%MAKE SURE these columns are the same ones in the same order
19+
20+
% straight up taking the fits and recoloring them here won't work because
21+
% Igor fits are all 200 points long but the X wave
22+
% is calculated, and is different length for each (i.e., some curves have
23+
% X values from 0.5 to 11, some from 3 to 10, etc., and those ranges
24+
% determine what the x values are for each fit separately).
25+
26+
% instead, I'm just going to do the normalization here and send the waves
27+
% back to Igor, where I can average them like the other I-dCellFits
28+
29+
%%
30+
eachSize = fitStats(:,cell2mat(cellfun(@(x) ~isempty(regexp(x,'stepSize')), fitHeaders,'un',0)));
31+
eachSize = eachSize(cellfun(@(x) isnumeric(x) && ~isnan(x),eachSize));
32+
33+
whichSide = antStats;
34+
thisCell = whichSide(:,1);
35+
thisDataNorm = cell(0);
36+
37+
for i = 1:size(whichSide,1)
38+
thisMax = whichSide{i,4};
39+
whichData = cell2mat(cellfun(@(x) ~isempty(regexp(x,sprintf('^(?!fit).*%s',thisCell{i}))),fitHeaders,'un',0));
40+
thisData = fitStats(1:length(eachSize),whichData);
41+
thisData(cellfun(@isempty,thisData))={nan};
42+
thisDataNorm(:,i) = cellfun(@(x) x./thisMax, thisData,'un',0);
43+
end
44+
45+
antNorm = thisDataNorm;
46+
antHeaders = cellfun(@(x) sprintf('%s_Norm',x),thisCell,'un',0)';
47+
48+
49+
% POSTERIOR
50+
whichSide = postStats;
51+
thisCell = whichSide(:,1);
52+
thisDataNorm = cell(0);
53+
54+
for i = 1:size(whichSide,1)
55+
thisMax = whichSide{i,4};
56+
whichData = cell2mat(cellfun(@(x) ~isempty(regexp(x,sprintf('^(?!fit).*%s',thisCell{i}))),fitHeaders,'un',0));
57+
thisData = fitStats(1:length(eachSize),whichData);
58+
thisData(cellfun(@isempty,thisData))={nan};
59+
thisDataNorm(:,i) = cellfun(@(x) x./thisMax, thisData,'un',0);
60+
end
61+
62+
postNorm = thisDataNorm;
63+
postHeaders = cellfun(@(x) sprintf('%s_Norm',x),thisCell,'un',0)';
64+
65+
%%
66+
67+
68+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',antHeaders,'antNorm');
69+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',postHeaders,'postNorm');
70+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',antNorm,'antNorm','A2');
71+
xlswrite('PatchData/attCorrectedIdCurves(180819).xls',postNorm,'postNorm','A2');

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
p.addParameter('tauType','thalfmax', @(x) ischar(x) && ismember(x,{'fit' 'thalfmax'}));
1818
p.addParameter('integrateCurrent',1);
1919
p.addParameter('normToOn1',0);
20+
p.addParameter('matchPhase',0');
2021

2122
p.parse(ephysData, ephysMetaData, protList, varargin{:});
2223

@@ -25,6 +26,7 @@
2526
tauType = p.Results.tauType;
2627
integrateFlag = p.Results.integrateCurrent;
2728
normalizeFlag = p.Results.normToOn1;
29+
phaseFlag = p.Results.matchPhase;
2830

2931
% Load and format Excel file with lists (col1 = cell name, col2 = series number,
3032
% col 3 = comma separated list of good traces for analysis)
@@ -180,7 +182,7 @@
180182
% between sweeps
181183

182184
% Concatenate data for all series in this recording
183-
allLeakSub{iSeries,1} = leakSubtractCell;
185+
allLeakSub(iSeries,1) = leakSubtractCell;
184186
allSweeps{iSeries,1} = theseSines;
185187
allSweeps{iSeries,2} = theseSquares;
186188
end
@@ -209,8 +211,8 @@
209211

210212
allSineSum = vertcat(allSweeps{:,1});
211213
allSquareSum = vertcat(allSweeps{:,2});
212-
for iStim = 1:max(allSquareSum(:,7))
213-
stimSquareSum(:,:,iStim) = allSquareSum(allSquareSum(:,7)==iStim,:);
214+
for iStim = 1:max(allSquareSum(:,12))
215+
stimSquareSum(:,:,iStim) = allSquareSum(allSquareSum(:,12)==iStim,:);
214216
end
215217

216218
% Find how many unique timepoints/durations there are, within a given
@@ -290,12 +292,14 @@
290292

291293
% meansByStimProfile = NaN(nStimProfiles, length(sortedLeakSub));
292294
steadyMeans = [];
295+
squareMeans = [];
293296
groupIdx = cell(0);
297+
theseSweeps = cell(0);
294298

295299
for iProfile = 1:nStimProfiles
296300
groupIdx{iProfile} = profileStartIdx(iProfile):profileEndIdx(iProfile);
297301

298-
% theseSweeps = sortedLeakSub(groupIdx{iProfile},:);
302+
theseSweeps{iProfile} = sortedLeakSub(groupIdx{iProfile},:);
299303

300304
% if length(groupIdx{iProfile})>1
301305
% meansByStimProfile(iProfile,:) = nanmean(theseSweeps,1);
@@ -322,7 +326,7 @@
322326
nSqStim = size(sortedSquares,3);
323327

324328
for iSqStim = 1:nSqStim
325-
squareMeans(iProfile,iSqStim) = mean(sortedSquares(groupIdx{iProfile},3,iSqStim));
329+
squareMeans(iProfile,iSqStim) = mean(sortedSquares(groupIdx{iProfile},6,iSqStim));
326330
end
327331

328332
onRatio = sortedSquares(:,:,3)./sortedSquares(:,:,1);
@@ -337,7 +341,7 @@
337341
end
338342

339343
sinePeaks{iCell,1} = cellName;
340-
sinePeaks{iCell,2} = sortedLeakSub;
344+
sinePeaks{iCell,2} = theseSweeps';
341345
sinePeaks{iCell,3} = [stimMetaData steadyMeans squareMeans];
342346

343347
end

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185
for iStim = 1:nStims
186186

187187
stimLoc = uniquetol(allStim{iStim}(:,1:2),lengthTol,'ByRows',true);
188+
stimSize = round(mean(allStim{iStim}(:,3)));
189+
stimPos = round(mean(allStim{iStim}(:,4)));
190+
stimVel = roundVel(mean(allStim{iStim}(:,5)));
188191
responseTime = [stimLoc(1)-preTime*sf:stimLoc(2)+postTime*sf];
189192
%NEXT: use seriesStimuli location/sweep number to set time
190193
%boundaries for where to look at the response
@@ -225,6 +228,9 @@
225228
% Save everything to output struct
226229
nonStatOutput.(cellName)(whichRow).protocol = protName;
227230
nonStatOutput.(cellName)(whichRow).stimNum = iStim;
231+
nonStatOutput.(cellName)(whichRow).size = stimSize;
232+
nonStatOutput.(cellName)(whichRow).position = stimPos;
233+
nonStatOutput.(cellName)(whichRow).velocity = stimVel;
228234
nonStatOutput.(cellName)(whichRow).slidingMean = windowMeans;
229235
nonStatOutput.(cellName)(whichRow).slidingVar = windowVars;
230236
nonStatOutput.(cellName)(whichRow).sweepsPerWindow = averagingWindow;

0 commit comments

Comments
 (0)