-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchExperiments.m
179 lines (157 loc) · 4.5 KB
/
SearchExperiments.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function SearchExperiments(varargin)
% SearchExperiments(Flags)
% Looks though analyzed experiments and finds ones that meet a
% criterion, then reports their details and plots the waveforms
% INPUTS:
% Flags should be a series of comma separated name, value pairs
% e.g. SearchExperiments('CellType', 'GM', 'Category', 3, ...
% 'DutyCycle', [0.25, 0.5])
% will find all GM cells that are half-center (category 3)
% with a duty cycle between 0.25 and 0.5
% available flags:
% 'CellType' (should be a name, e.g. 'LP')
% 'Category' (0, 1, 2, 3)
% the rest are ranges (e.g. [0.9, 1.0])
% 'BurstFreq', 'AutoCorr', 'SpikesPerBurst', ...
% 'BurstSpikeFreq', 'DutyCycle', 'SlowWaveAmp'
doPlotWaveforms = false;
close all;
ExperimentsExists = evalin('base', 'exist(''ML_Experiments'')');
if(ExperimentsExists)
Experiments = evalin('base', 'ML_Experiments');
else
Experiments = LoadAllExperiments('MorrisLecarFolders.txt');
assignin('base', 'ML_Experiments', Experiments);
end
try
MatchList = GetSpecifiedAnalysis(Experiments, varargin{:});
catch errRecord
help SearchExperiments
rethrow(errRecord)
end
Intrinsics = LoadIPxls;
ValidID = unique({Intrinsics.ID});
an = MatchList(1);
if(length(an.matchData) == 0)
matchNames = {};
else
matchNames = fieldnames(an.matchData);
end
if ispc
slash = '\';
else
slash = '/';
end
fprintf('netID\tgsyn\tgh')
for n = 1:length(matchNames)
fprintf('\t%s', matchNames{n})
end
fprintf('\n')
keepList = [];
for ind = 1:length(MatchList);
an = MatchList(ind);
cellID = an.ID;
if(sum(strcmp(ValidID, cellID)) == 0)
continue
else
keepList = [keepList, ind];
end
fileName = an.FileName;
ind1 = strfind(fileName, slash);
ind1 = ind1(end);
if ispc
ind_ = strfind(fileName, '_');
if(ind_(1) > ind1)
subdir = [fileName((ind1+1):(ind_(2)-1)), slash];
fileName = [fileName(1:ind1), subdir, fileName((ind1+1):end)];
ind1 = strfind(fileName, slash);
ind1 = ind1(end);
end
end
ind2 = strfind(fileName, '.');
netID = fileName((ind1+1):(ind2-1));
fprintf('%s\t%d\t%d', netID, an.g_syn, an.g_h)
for n = 1:length(matchNames)
fprintf('\t%g', an.matchData.(matchNames{n}))
end
fprintf('\n')
if doPlotWaveforms
displayWaveform(fileName, netID)
end
end
MatchList = MatchList(keepList);
CellIDs = unique({MatchList.ID});
fprintf(' Number of unique cells: %g\n', length(CellIDs))
for n = 1:length(CellIDs)
fprintf(' %s\n', CellIDs{n})
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function displayWaveform(fileName, netID)
[t, vReal, vModel] = getData(fileName);
yRange = [min(min(vReal), min(vModel)), max(max(vReal), max(vModel))];
h = NamedFigure(netID);
set(h, 'WindowStyle', 'docked')
clf
h_axes = axes('Position', [0.0 0.0 1.0 1.0], 'Visible', 'off');
xPad = 0.075;
yPad = 0.075;
Width = 1.0 - 2.0 * xPad;
Height = 1.0 - 2.0 * yPad;
x = xPad;
y = yPad + 0.5 * Height;
axes('Position', [x, y, Width, 0.5*Height])
plot(t, vReal, 'b-', 'LineWidth', 2);
set(gca, 'xTickLabel', {})
ylabel('Real Cell Potential (mV)', 'FontSize', 18')
title(RealUnderscores(netID), 'FontSize', 18')
ylim([-75 -5])
xlim([0 40])
x = xPad;
y = yPad;
axes('Position', [x, y, Width, 0.5*Height])
plot(t, vModel, 'r-', 'LineWidth', 2);
ylabel('Model Cell Potential (mV)', 'FontSize', 18')
xlabel('Time (s)', 'FontSize', 18')
ylim([-75 -5])
xlim([0 40])
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t, vReal, vModel] = getData(fileName)
AbfS = LoadAbf(fileName);
tBig = AbfS.Time; % * 1000; %convert to ms
t = tBig(1):0.001:tBig(end);
FNames = fieldnames(AbfS.Units);
Current = [];
Voltage = [];
for n = 1:length(FNames)
Unit = AbfS.Units.(FNames{n});
if(strcmp(Unit, 'mV'))
Voltage = [Voltage, n];
elseif(strcmp(Unit, 'nA'))
Current = [Current, n];
end
end
if(length(Voltage == 2) ~= 2)
for n = 1:length(FNames)
disp(FNames)
end
error(['Incorrect number of voltage traces in ', FileName])
end
if(StringCheck(FNames{Voltage(1)}, 'model'))
if(StringCheck(FNames{Voltage(2)}, 'model'))
disp(FNames)
error(['Two model traces found in ', FileName])
end
vReal = AbfS.Data.(FNames{Voltage(2)});
vModel = AbfS.Data.(FNames{Voltage(1)});
elseif(StringCheck(FNames{Voltage(2)}, 'model'))
vReal = AbfS.Data.(FNames{Voltage(1)});
vModel = AbfS.Data.(FNames{Voltage(2)});
else
disp(FNames)
error(['No model traces found in ', FileName])
end
vReal = interp1(tBig, vReal, t);
vModel = interp1(tBig, vModel, t);
return