Skip to content

Commit 948e907

Browse files
committed
Code Version for PreIndentation Analysis. (sortRowsTol fixed to work for negative sorting values).
1 parent f750a41 commit 948e907

2 files changed

Lines changed: 144 additions & 33 deletions

File tree

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

Lines changed: 142 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
% PreIndentIgorExport.m
22

33
%% Load data
4-
% load prepulseFatData(180108).mat
4+
% Load prepulseWT_Recreated(181108).mat
5+
%(recreated with filtering/selection code at the current date).
6+
7+
% or run this section to re-load the data if ephysData and
8+
% ephysMetaData are loaded (through FAT158).
59

6-
% or run this section to re-load the data given ephysData and
7-
% ephysMetaData.
810
strainList = {'TU2769'};
911
internalList = {'IC2'};
1012
resistCutoff = '<210'; % Rs < 210 MOhm
@@ -14,27 +16,33 @@
1416

1517
clear strainList internalList resistCutoff ans;
1618

17-
18-
19-
protList ={'NoPrePulse'};
19+
% Find MRCs for prepulse sweeps.
20+
% Use TracePicks_Preto158_WT_IC2.xls
21+
protList ={'PrePulse'};
2022
sortSweeps = {'position','position','position','position'};
2123
matchType = 'full';
22-
wtNoPreMRCs = IdAnalysis(ephysData,protList,wtCells,'num','matchType',matchType, ...
24+
wtPreMRCs = IdAnalysis(ephysData,protList,wtCells,'num','matchType',matchType, ...
2325
'tauType','thalfmax', 'sortSweepsBy', sortSweeps, 'integrateCurrent',1,...
2426
'sortStimBy','time','recParameters',ephysMetaData);
2527

2628
clear protList sortSweeps matchType
2729

28-
protList ={'PrePulse'};
30+
% Find MRCs for no-prepulse sweeps.
31+
% Use TracePicks_NoPreto158_WT_IC2.xls
32+
protList ={'NoPrePulse'};
2933
sortSweeps = {'position','position','position','position'};
3034
matchType = 'full';
31-
wtPreMRCs = IdAnalysis(ephysData,protList,wtCells,'num','matchType',matchType, ...
35+
wtNoPreMRCs = IdAnalysis(ephysData,protList,wtCells,'num','matchType',matchType, ...
3236
'tauType','thalfmax', 'sortSweepsBy', sortSweeps, 'integrateCurrent',1,...
3337
'sortStimBy','time','recParameters',ephysMetaData);
3438

3539
clear protList sortSweeps matchType
3640

37-
%% Export to Igor
41+
% Exclude FAT116 because the pre-indentation step was 3um, rather than 5um
42+
% like the rest of the data.
43+
wtPreMRCs = wtPreMRCs(2:12,:);
44+
45+
%% Collate data for export
3846

3947
% Get traces and associated recording names
4048
noPreTraces = vertcat(wtNoPreMRCs{:,2})';
@@ -48,26 +56,129 @@
4856

4957

5058
% Get sizes of on2 step (or just step for noPre), sort by size
51-
preSteps = vertcat(wtPreMRCs{:,4});
52-
[preStepsSort, preI] = sortrows(preSteps,1);
53-
54-
preRelSizes = round(preStepsSort(:,1)) - 5;
55-
preAbsSizes = round(preStepsSort(:,1));
56-
preN = preStepsSort(:,7);
57-
preCellsSort = preCells(preI);
58-
preTracesSort = preTraces(:,preI);
59-
60-
61-
62-
noPreSteps = vertcat(wtNoPreMRCs{:,3});
63-
[noPreStepsSort, noPreI] = sortrows(noPreSteps,1);
64-
65-
noPreSizes = round(noPreStepsSort(:,1));
66-
noPreN = noPreStepsSort(:,7);
67-
noPreCellsSort = noPreCells(noPreI);
68-
noPreTracesSort = noPreTraces(:,noPreI);
69-
70-
59+
for i = 0:1
60+
preSteps = vertcat(wtPreMRCs{:,4+i});
61+
[preStepsSort, preI] = sortrows(preSteps,1+i);
62+
63+
preRelSizes = round(preStepsSort(:,2));
64+
preAbsSizes = round(preStepsSort(:,1));
65+
preN = preStepsSort(:,7);
66+
preCellsSort = preCells(preI);
67+
preTracesSort = preTraces(:,preI);
68+
69+
if i == 0
70+
on_PreSteps = preStepsSort(:,[1 2 6 13]);
71+
on_PreTraces = preTracesSort;
72+
else
73+
off_PreSteps = preStepsSort(:,[1 2 6 13]);
74+
off_PreTraces = preTracesSort;
75+
end
76+
77+
78+
% Column 4 for off
79+
noPreSteps = vertcat(wtNoPreMRCs{:,3+i});
80+
[noPreStepsSort, noPreI] = sortrows(noPreSteps,1+i);
81+
82+
noPreSizes = round(noPreStepsSort(:,1));
83+
noPreN = noPreStepsSort(:,7);
84+
noPreCellsSort = noPreCells(noPreI);
85+
noPreTracesSort = noPreTraces(:,noPreI);
86+
87+
if i == 0
88+
on_NoPreSteps = noPreStepsSort(:,[1 2 6 13]);
89+
on_NoPreTraces = noPreTracesSort;
90+
else
91+
off_NoPreSteps = noPreStepsSort(:,[1 2 6 13]);
92+
off_NoPreTraces = noPreTracesSort;
93+
end
94+
end
95+
96+
% on/off_(no)PreSteps variable now contains:
97+
% absolute position, relative position (to 5um pre-step), current, nReps
98+
99+
%% Calculate summary statistics for each step size
100+
101+
% Relative displacement pre-step
102+
whichSteps = on_PreSteps(:,[2,3]);
103+
104+
[~, sortIdx, eachDisp, dispStartIdx, dispEndIdx] = ...
105+
sortRowsTol(whichSteps, 0, 1);
106+
thisMean = arrayfun(@(x,y) mean(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
107+
thisSD = arrayfun(@(x,y) std(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
108+
thisSEM = thisSD./sqrt(dispEndIdx-dispStartIdx+1);
109+
thisDisp = eachDisp(:,1);
110+
111+
relPreSummary = [thisDisp thisMean thisSD thisSEM];
112+
113+
% Absolute displacement pre-step
114+
whichSteps = on_PreSteps(:,[1,3]);
115+
116+
[~, sortIdx, eachDisp, dispStartIdx, dispEndIdx] = ...
117+
sortRowsTol(whichSteps, 0, 1);
118+
thisMean = arrayfun(@(x,y) mean(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
119+
thisSD = arrayfun(@(x,y) std(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
120+
thisSEM = thisSD./sqrt(dispEndIdx-dispStartIdx+1);
121+
thisDisp = eachDisp(:,1);
122+
123+
absPreSummary = [thisDisp thisMean thisSD thisSEM];
124+
125+
% No pre-step
126+
whichSteps = off_PreSteps(:,[2,3]);
127+
whichSteps(:,1) = -whichSteps(:,1);
128+
129+
[~, sortIdx, eachDisp, dispStartIdx, dispEndIdx] = ...
130+
sortRowsTol(whichSteps, 0, 1);
131+
thisMean = arrayfun(@(x,y) mean(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
132+
thisSD = arrayfun(@(x,y) std(whichSteps(x:y,2)) ,dispStartIdx,dispEndIdx);
133+
thisSEM = thisSD./sqrt(dispEndIdx-dispStartIdx+1);
134+
thisDisp = eachDisp(:,1);
135+
136+
noPreSummary = [thisDisp thisMean thisSD thisSEM];
137+
138+
relPreNorm = relPreSummary(:,1);
139+
relPreNorm(:,2:4) = relPreSummary(:,2:4)/max(noPreSummary(:,2));
140+
absPreNorm = absPreSummary(:,1);
141+
absPreNorm(:,2:4) = absPreSummary(:,2:4)/max(noPreSummary(:,2));
142+
noPreNorm = noPreSummary(:,1);
143+
noPreNorm(:,2:4) = noPreSummary(:,2:4)/max(noPreSummary(:,2));
144+
145+
146+
%% Format tables and export source data and summary stats as text files for
147+
% reading or for Igor import
148+
149+
% Turn arrays into tables and include variable names
150+
out_Names = {'Abs_Position_um','Rel_Disp_um','Current_pA','nReps'};
151+
152+
out_PreSummRel = array2table(relPreSummary,'Var',{'Pre_Rel_Disp_um','Mean_Current_pA','SD','SEM'});
153+
out_PreSummAbs = array2table(absPreSummary,'Var',{'Pre_Abs_Disp_um','Mean_Current_pA','SD','SEM'});
154+
out_NoPreSumm = array2table(noPreSummary,'Var',{'NoPre_Disp_um','Mean_Current_pA','SD','SEM'});
155+
156+
out_PreNormRel = array2table(relPreNorm,'Var',{'Pre_Rel_Disp_um','Norm_Current','SD','SEM'});
157+
out_PreNormAbs = array2table(absPreNorm,'Var',{'Pre_Abs_Disp_um','Norm_Current','SD','SEM'});
158+
out_NoPreNorm = array2table(noPreNorm,'Var',{'NoPre_Disp_um','Norm_Current','SD','SEM'});
159+
160+
out_PreStepsOn = array2table(on_PreSteps,'VariableNames',out_Names);
161+
out_PreStepsOff = array2table(off_PreSteps,'VariableNames',out_Names);
162+
out_NoPreStepsOn = array2table(on_NoPreSteps,'VariableNames',out_Names);
163+
out_NoPreStepsOff = array2table(off_NoPreSteps,'VariableNames',out_Names);
164+
165+
% Write tables to xls file
166+
[fname, pname] = uiputfile({'*.xls','Excel file'},'Save source data as');
167+
168+
writetable(out_PreSummRel, fullfile(pname,fname),'Sheet','Summary','Range','A2');
169+
writetable(out_PreSummAbs, fullfile(pname,fname),'Sheet','Summary','Range','F2');
170+
writetable(out_NoPreSumm, fullfile(pname,fname),'Sheet','Summary','Range','K2');
171+
172+
writetable(out_PreNormRel, fullfile(pname,fname),'Sheet','Summary_Normalized','Range','A2');
173+
writetable(out_PreNormAbs, fullfile(pname,fname),'Sheet','Summary_Normalized','Range','F2');
174+
writetable(out_NoPreNorm, fullfile(pname,fname),'Sheet','Summary_Normalized','Range','K2');
175+
176+
writetable(out_PreStepsOn, fullfile(pname,fname),'Sheet','onPreSteps');
177+
writetable(out_NoPreStepsOn, fullfile(pname,fname),'Sheet','onNoPreSteps');
178+
writetable(out_PreStepsOff, fullfile(pname,fname),'Sheet','offPreSteps');
179+
writetable(out_NoPreStepsOff, fullfile(pname,fname),'Sheet','offNoPreSteps');
180+
181+
%% Format wave names and export traces as text files for Igor
71182
% Create name for Igor wave for each trace
72183
preRelSizes = cellstr(num2str(preRelSizes));
73184
preRelSizes = cellfun(@(x) regexprep(x,'-','neg'), preRelSizes,'un',0);
@@ -94,7 +205,7 @@
94205

95206

96207
% Write stimuli too
97-
preStim = ephysData.FAT123.data{2,12}/0.408;
208+
preStim = ephysData.FAT123.data{2,12}/0.408; % V to um factor
98209
noPreStim = ephysData.FAT123.data{2,15}/0.408;
99210

100211
preRelStimSizes = -2:7;

Analysis/SK/sortRowsTol.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
%pick out values which have a diff greater than tolerance from their
2020
%neighbor after sorting.
21-
isUnq(:,iCol) = [1; diff(abs(matA_sorted(:,sortOrder(iCol))))>tol(iCol)];
22-
isUnqEnd(:,iCol) = [diff(abs(matA_sorted(:,sortOrder(iCol))))>tol(iCol);1];
21+
isUnq(:,iCol) = [1; abs(diff(abs(matA_sorted(:,sortOrder(iCol)))))>tol(iCol)];
22+
isUnqEnd(:,iCol) = [abs(diff(abs(matA_sorted(:,sortOrder(iCol)))))>tol(iCol);1];
2323

2424
end
2525

0 commit comments

Comments
 (0)