Skip to content

Commit 21039a8

Browse files
committed
Updated velocity script, better ability to plot peak/charge/times and only voltage correct the proper ones, plotting representative traces, tiny edits for IdAnalysis documentation and initialized mechStim
1 parent 99cab05 commit 21039a8

3 files changed

Lines changed: 237 additions & 102 deletions

File tree

Analysis/SK/AnnotatedScripts/Velocity_VoltageAtt_180913.m

Lines changed: 187 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,69 @@
6060
ExcludeSweeps(ephysData, protList, velocityCells, 'matchType', matchType);
6161

6262
%% Find MRCs
63-
% antAllSteps.xlsx and postAllSteps.xlsx from 180810
63+
% antTraps_allFreq(180913).xls
6464
protList ={'TrapRate'};
6565
matchType = 'first';
6666

6767
sortSweeps = {'velocity','velocity','magnitude','magnitude'};
6868

69-
velocityMRCs = IdAnalysis(ephysData,protList,velocityCells,'num','matchType',matchType, ...
69+
[velocityMRCs velocityStim] = IdAnalysis(ephysData,protList,velocityCells,'num','matchType',matchType, ...
7070
'tauType','thalfmax', 'sortSweepsBy', sortSweeps, 'integrateCurrent',1 , ...
7171
'recParameters', ephysMetaData,'sepByStimDistance',1);
7272

7373
clear protList sortSweeps matchType
7474

75+
%% Quick plot for looking at asymmetry in slow velocities
76+
figure();
77+
for i = 1:8
78+
axh(i) = subtightplot(2,4,i);
79+
plot(velocityMRCs{i,2}([5 4 3 2 1],:)');
80+
cmapline('ax',gca,'colormap','parula');
81+
end
82+
linkaxes(axh,'xy');
83+
plotfixer;
84+
85+
%% Get normalized mean traces (normalized to highest velocity)
86+
% Can then use normVelocityMRCs as input for the final
87+
normVelocitySweeps = cellfun(@(x,y) x./y(end,6),velocityMRCs(:,2),velocityMRCs(:,3),'un',0);
88+
normVelocityMRCs = velocityMRCs;
89+
normVelocityMRCs(:,2) = normVelocitySweeps;
90+
%% Quick plot for selecting representative traces
91+
figure();
92+
for i = 1:8
93+
axh(i) = subtightplot(2,4,i);
94+
plot(velocityMRCs{i,2}');
95+
cmapline('ax',gca,'colormap','parula');
96+
end
97+
linkaxes(axh,'xy');
98+
99+
%% Plot selected representative traces and stimuli
100+
% FAT214 with on ramps for 106, 785, 1560, 7230, 39740 um/s
101+
102+
% Grab stimuli based on velocityStim (second output from IdAnalysis)
103+
% Just example stim from one trace
104+
% Should this be photodiode trace? (if so don't forget to zero it)
105+
stimTrace{1} = ephysData.FAT214.data{3,18}(:,2);
106+
stimTrace{2} = ephysData.FAT214.data{3,11}(:,2);
107+
stimTrace{3} = ephysData.FAT214.data{3,12}(:,3);
108+
stimTrace{4} = ephysData.FAT214.data{3,12}(:,4);
109+
stimTrace{5} = ephysData.FAT214.data{3,11}(:,3);
110+
111+
112+
113+
figure();
114+
axh(1)=subplot(2,1,1);
115+
for i = 1:5
116+
plot(stimTrace{i})
117+
hold on
118+
end
119+
tVec = (1:length(velocityMRCs{1,2}))/10; % time in ms
120+
plot(tVec,velocityMRCs{1,2}([2 5 6 10 12],:)');
121+
cmapline('ax',gca,'colormap','copper');
122+
chH = get(gca,'children');
123+
set(gca,'children',flipud(chH));
124+
plotfixer();
125+
75126
%% Pull out and combine relevant data for plot
76127

77128
% Voltage attenuation data comes from the length constant fitting done in
@@ -107,7 +158,37 @@
107158

108159
end
109160

110-
distVPeak_Ant = distVPeak;
161+
distVPeak_On = distVPeak;
162+
163+
164+
% Off ramps
165+
166+
distVPeak = [];
167+
168+
for iCell = 1:size(whichMRCs,1)
169+
thisCell = whichMRCs{iCell,4};
170+
whichVel = round(thisCell(:,1)) == -stepVel;
171+
if any(whichVel)
172+
thisName = whichMRCs{iCell,1};
173+
hasAtt = strcmp(thisName,thisAtt(:,1));
174+
175+
if any(hasAtt) && thisAtt{hasAtt,2}
176+
try distVPeak(iCell,:) = [thisCell(whichVel,[distCol peakCol]) thisAtt{hasAtt,3}];
177+
catch
178+
distVPeak(iCell,:) = [mean(thisCell(whichVel,[distCol peakCol]),1) thisAtt{hasAtt,3}];
179+
end
180+
else
181+
try distVPeak(iCell,:) = [thisCell(whichVel,[distCol peakCol]) nan];
182+
catch
183+
distVPeak(iCell,:) = [mean(thisCell(whichVel,[distCol peakCol]),1) nan];
184+
end
185+
end
186+
187+
end
188+
189+
end
190+
191+
distVPeak_Off = distVPeak;
111192

112193
clear a iCell thisCell whichMRCs whichStep thisName hasAtt distVPeak
113194

@@ -131,31 +212,57 @@
131212

132213
Vc = -0.06; %in V
133214
Ena = 0.094; % in V
134-
Im = distVPeak_Ant(:,2);
135-
Vatt = distVPeak_Ant(:,3);
215+
Im = distVPeak_On(:,2);
216+
Vatt = distVPeak_On(:,3);
136217

137218
Vm = Vc * Vatt;
138-
distVPeak_Ant(:,4) = (Im * (Vc-Ena)) ./ (Vm-Ena);
219+
distVPeak_On(:,4) = (Im * (Vc-Ena)) ./ (Vm-Ena);
220+
139221

140-
%% Plot anterior and posterior on separate plots
222+
Im = distVPeak_Off(:,2);
223+
Vatt = distVPeak_Off(:,3);
224+
225+
Vm = Vc * Vatt;
226+
distVPeak_Off(:,4) = (Im * (Vc-Ena)) ./ (Vm-Ena);
141227

142-
figure(); axh(1) = subplot(2,1,1);
143-
scatter(distVPeak_Ant(:,1),distVPeak_Ant(:,4));
228+
229+
%% Plot on and off currents vs distance
230+
231+
figure();
232+
scatter(distVPeak_On(:,1),distVPeak_On(:,4),'b');
233+
hold on;
234+
scatter(distVPeak_Off(:,1),distVPeak_Off(:,4),'r');
144235
xlabel('Distance from cell body (um)');
145236
ylabel(sprintf('Current @%dum (pA)',stepVel))
146-
text(100,200,'Anterior');
237+
xlim(gca,[0 200]);
238+
ylim(gca,[0 200]);
239+
legend({'On current','Off current'});
147240

148-
for i = 1:length(axh)
149-
xlim(axh(i),[0 200]);
150-
ylim(axh(i),[0 200]);
151-
end
152241

153242
%% Correct all sizes and export for Igor fitting of Boltzmann to each recording
154243

155244
% Set the filename
156-
fname = 'PatchData/attCorrectedVelCurves(180913).xls';
245+
fname = 'PatchData/attCorrectedVel_times(181002).xls';
246+
noCorr = 0;
247+
248+
for i = 1:2
249+
whichRamp = i; % 1 for on currents, 2 for off currents
250+
normFlag = 0; %normalize to 40mm/s ramp (highest velocity "step")
251+
peakCol = 9; % 6 for peak current, 11 for integrated current/charge
252+
% 8 for tauAct, 9 for tauDecay
253+
switch peakCol
254+
case 6
255+
dType = 'peak';
256+
case 11
257+
dType = 'charge';
258+
case 8
259+
dType = 'act';
260+
case 9
261+
dType = 'decay';
262+
end
263+
distCol = 12;
157264

158-
allVel = vertcat(velocityMRCs{:,3});
265+
allVel = vertcat(velocityMRCs{:,whichRamp+2});
159266
eachVel = uniquetol(allVel(:,1),12,'DataScale',1);
160267
% the value of 12 is empirically chosen as being larger than the largest
161268
% difference between velocities that could be binned (usually 10 after roundVel) and smaller than the
@@ -173,76 +280,98 @@
173280
vel_Out = cell(length(eachVel)+1,size(whichMRCs,1));
174281

175282
for iCell = 1:size(whichMRCs,1)
176-
thisCell = whichMRCs{iCell,3};
283+
thisCell = whichMRCs{iCell,whichRamp+2};
177284
thisDist = mean(thisCell(:,distCol)); % check if cell distance is in range
178285
if thisDist <= distLimits(2) && thisDist >= distLimits(1)
179286
thisName{iCell,1} = whichMRCs{iCell,1}; %name
180287
thisName{iCell,2} = thisDist;
181-
vel_Out{1,iCell} = thisName{iCell,1};
288+
vel_Out{1,iCell} = sprintf('%s_%s_stim%d',thisName{iCell,1},dType,whichRamp);
182289
hasAtt = strcmp(thisName{iCell,1},thisAtt(:,1));
183290
Iact = [];
184291

185292
for iVel = 1:length(eachVel)
186293
stepVel = eachVel(iVel);
187294
whichVel = abs(thisCell(:,1) - stepVel) < 12; %find closest velocity
188295
if any(whichVel)
189-
190296
if any(hasAtt) && thisAtt{hasAtt,2} %if attenuation calc exists and not omitCell
191-
Vm = Vc * thisAtt{hasAtt,3};
192-
Im = thisCell(whichVel,peakCol);
193-
Iact(iVel,1) = (Im * (Vc-Ena)) ./ (Vm-Ena);
297+
if noCorr == 1 || strcmp(dType,'peak') || strcmp(dType,'charge') %attenuation correction for current/charge but not taus
298+
Vm = Vc * thisAtt{hasAtt,3};
299+
Im = thisCell(whichVel,peakCol);
300+
if length(Im) > 1
301+
%multiple profiles containing this velocity, take mean weighted by nReps
302+
Im = sum((thisCell(whichVel,peakCol).*thisCell(whichVel,end)))/sum(thisCell(whichVel,end));
303+
end
304+
305+
Iact(iVel,1) = (Im * (Vc-Ena)) ./ (Vm-Ena);
306+
else
307+
Im = thisCell(whichVel,peakCol);
308+
if length(Im) > 1
309+
%multiple profiles containing this velocity, take mean weighted by nReps
310+
Im = sum((thisCell(whichVel,peakCol).*thisCell(whichVel,end)))/sum(thisCell(whichVel,end));
311+
end
312+
Iact(iVel,1) = Im;
313+
end
194314
else
195315
Iact(iVel,1) = nan;
196316
end
317+
197318

198319
else
199320
Iact(iVel,1) = nan;
200321
end
201322
end
323+
324+
if whichRamp == 2
325+
Iact = flipud(Iact);
326+
end
327+
if normFlag
328+
Iact = Iact./Iact(end);
329+
end
202330
vel_Out(2:length(eachVel)+1,iCell) = num2cell(Iact);
331+
203332
end
204333
end
205-
vel_Name = [{'Anterior', 'Ant_Dist'}; thisName];
334+
335+
if whichRamp == 2
336+
eachVel = flipud(eachVel);
337+
end
338+
339+
thisName(:,1) = cellfun(@(x) sprintf('%s',x),thisName(:,1),'un',0);
340+
vel_Name = [{sprintf('Anterior_stim%d',whichRamp), sprintf('Ant_Dist_stim%d',whichRamp)}; thisName];
206341
vel_Out = vel_Out(:,~cellfun(@isempty, vel_Out(1,:))); % clear out empty waves (where dist didn't match)
207342
vel_Name = vel_Name(~cellfun(@isempty, vel_Name(:,1)),:);
208343

209-
vel_Out = [[{'velocity'};num2cell(eachVel)] vel_Out]; % append stepSize wave
210-
211-
% thisName = cell(0);
212-
% whichMRCs = posteriorMRCs;
213-
% post_Out = cell(length(eachSize)+1,size(whichMRCs,1));
214-
%
215-
% for iCell = 1:size(whichMRCs,1)
216-
% thisCell = whichMRCs{iCell,3};
217-
% thisDist = mean(thisCell(:,distCol)); % check if cell distance is in range
218-
% if thisDist <= distLimits(2) && thisDist >= distLimits(1)
219-
% thisName{iCell,1} = whichMRCs{iCell,1}; %name
220-
% thisName{iCell,2} = thisDist; %distance
221-
% post_Out{1,iCell} = thisName{iCell,1};
222-
% Iact = [];
223-
%
224-
% for iSize = 1:length(eachSize)
225-
% stepVel = eachSize(iSize);
226-
% whichStep = round(thisCell(:,1)*2)/2 == stepVel; %round to nearest 0.5
227-
% if any(whichStep)
228-
% Iact(iSize,1) = thisCell(whichStep,peakCol);
229-
% else
230-
% Iact(iSize,1) = nan;
231-
% end
232-
% end
233-
% post_Out(2:length(eachSize)+1,iCell) = num2cell(Iact);
234-
% end
235-
% end
236-
%
237-
% post_Name = [{'Posterior', 'Post_Dist'}; thisName];
238-
% post_Out = post_Out(:,~cellfun(@isempty, post_Out(1,:)));
239-
% post_Name = post_Name(~cellfun(@isempty, post_Name(:,1)),:);
240-
241-
242-
xlswrite(fname,vel_Out,'vel');
243-
xlswrite(fname,vel_Name,'velStats');
344+
vel_Out = [[{sprintf('vel_stim%d',whichRamp)};num2cell(eachVel)] vel_Out]; % append stepSize wave
345+
346+
347+
xlswrite(fname,vel_Out,sprintf('%s_stim%d',dType,whichRamp));
348+
xlswrite(fname,vel_Name,sprintf('%sStats_stim%d',dType,whichRamp));
244349

245350
clear iCell thisCell Iact whichMRCs whichStep hasAtt thisAtt Vc Ena thisName
351+
end
352+
353+
%% Calculate ratios
354+
% re-save vel_Out as on/offVelChrg and on/offVelPeak for the corresponding
355+
% cases
356+
on = onVelPeak;
357+
off = offVelPeak;
358+
out = on(1,:);
359+
360+
onVel = [on{2:end,1}];
361+
offVel = -[off{2:end,1}];
362+
363+
364+
for i = 1:length(onVel)
365+
whichVel = abs(onVel(i)-offVel)<12;
366+
if any(whichVel)
367+
thisVel = find(whichVel);
368+
out{i+1,1} = offVel(thisVel);
369+
out(i+1,2:end) = cellfun(@(x,y) x./y, off(thisVel+1,2:end), on(i+1,2:end),'un',0);
370+
end
371+
end
372+
373+
out = out(~cellfun(@isempty,out(:,1)),:);
374+
xlswrite(fname,out,sprintf('velPeak_ratio'));
246375

247376

248377
%% Renormalize

Analysis/SK/IdAnalysis.m

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,31 @@
5656
% mechPeaks cell array Nested cell array with a row for each
5757
% recording. CellName, Average Trace,
5858
% then for each stimulus, MRC stats on
59-
% [size/velocity (um or um/s); location
60-
% (datapoint); peak current (pA);
61-
% direction (+/-); threshold used (pA);
62-
% decay tau from exp1 fit (ms);
63-
% number of sweeps averaged].
59+
% [1-sortingParam, 2-size (um), 3-position (um),
60+
% 4-velocity (um/s), 5-pkLoc (datapoint),
61+
% 6-peak (pA), 7-threshold used (pA),
62+
% 8-activation time (ms), 9-decay time (ms) *either t1/2 max or tau
63+
% 10-time to peak (ms), 11-charge (C),
64+
% 12-stim distance (um), 13-number of sweeps averaged.
6465
%
6566
%
6667
% Created by Sammy Katta on 20-May-2015.
6768
% Updated most recently by Sammy Katta on 7-Aug-2017.
6869
% Documentation not updated yet, but fxn now allows output to be used for
6970
% many more types of analyses. Will soon rename.
7071

71-
% TODO: Add flag for using stim com signal vs. PD signal (chan 2 vs chan 3)
72-
% Done, but still uses stim com to group step sizes, and includes PD
73-
% trace and calculated sizes (based on calibration if available) in
74-
% output
72+
% TODO: Allow output of mean PD or stimcom signal as traces in mechStim
73+
% (either include as output from newStepFind, or just section it with
74+
% profileIndex and use series/sweep numbers from stimMetaData to pull it
75+
% out for each group).
76+
%
7577
% NEXT: test with stimInterval, break down into intermediate fxns if still
7678
% necessary.
7779
% LATER: add in PD step analysis (will need findMRCs modified), output
7880
% sorted stim command and PD traces with sortedLeakSub
7981
% LATER: add GUI for selecting sortSweepsBy for each stim segment
8082

81-
function [mechPeaks, mechStim, mechTraces] = IdAnalysis(ephysData, protList, varargin)
83+
function [mechPeaks, mechStim] = IdAnalysis(ephysData, protList, varargin)
8284

8385
p = inputParser;
8486
p.addRequired('ephysData', @(x) isstruct(x));
@@ -134,6 +136,8 @@
134136
end
135137

136138
mechPeaks = cell(length(allCells),1);
139+
mechStim = cell(length(allCells),1);
140+
137141
% protList = {'WC_Probe','NoPrePulse','DispRate'};
138142
% protList = {'PrePulse'};
139143

@@ -545,6 +549,7 @@
545549
end
546550
else
547551
mechPeaks{iCell,1} = cellName;
552+
548553
mechPeaks{iCell,2} = meansByStimProfile;
549554

550555
for iStim = 1:nStim
@@ -597,10 +602,9 @@
597602
%means and use those timepoints for peak finding so you'd also have a
598603
%less noisy stim/PD trace.
599604

600-
mechStim (iCell,2:length(sortedStim)+1) = sortedStim;
601-
605+
mechStim(iCell,2:length(sortedStim)+1) = sortedStim;
602606
end
603-
607+
mechStim = mechStim(~cellfun(@isempty, mechPeaks(:,1)),:);
604608
mechPeaks = mechPeaks(~cellfun(@isempty, mechPeaks(:,1)),:);
605609

606610
end

0 commit comments

Comments
 (0)