-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetSpecifiedAnalysis.m
173 lines (158 loc) · 5.43 KB
/
GetSpecifiedAnalysis.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
function MatchList = GetSpecifiedAnalysis(Experiments, varargin)
% MatchList = GetSpecifiedAnalysis(Experiments, Flags)
% Looks though analyzed Experiments and finds ones that meet a
% criterion, then returns them as MatchList
% INPUTS:
% Experiments: an array of structures
% Flags: 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'
% OUTPUTS:
% MatchList: an array of structures
% MatchList(n).matchData: structure with fields that record
% values that were searched for
% MatchList = GetSpecifiedAnalysis(Experiments, varargin)
% INPUT ARGUMENTS:
% -Experiments: array of structures containing experiment data
% -varargin: specify properties to narrow down results. All
% are individually optional, but must specify at least one.
% Condition: a string denoting cell-type (e.g. 'GM')
% Conductances: a two-element array, [g_syn, g_h]
% Category: an integer number, (0-3) corresponding to network type
% AutoCorr: a float number greater than zero and < 1
% OUTPUT:
% -MatchList: array of structures containing matching experiment data
[cellType, category, specList, searchList] = getSpecifications(varargin{:});
MatchList = [];
flagList = {'CellType', 'Category', 'BurstFreq', 'AutoCorr', ...
'SpikesPerBurst', 'BurstSpikeFreq', 'DutyCycle', 'SlowWaveAmp'};
for n=1:length(Experiments)
anList = Experiments(n).Analysis;
for m=1:length(anList)
an = anList(m);
if(length(cellType) > 0 && ~strcmp(stripNums(an.Condition), ...
lower(cellType)))
continue
end
if(isfinite(category) && an.Cat ~= category)
continue
end
matchData = []; ind = 3;
val = an.CellReal.Burst.Freq; ind = 3;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
val = an.CellReal.SlowWave.Corr; ind = 4;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
val = an.CellReal.Burst.SpikesPerBurst.Mean; ind = 5;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
val = an.CellReal.Burst.SpikeFreq; ind = 6;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
val = an.CellReal.Burst.DutyCycle; ind = 7;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
val = mean(an.CellReal.SlowWave.Amplitudes); ind = 8;
if ~InRange(val, specList{ind})
continue
elseif(searchList{ind})
matchData.(flagList{ind}) = val;
end
an.FolderNum = Experiments(n).FolderNum;
an.ID = sprintf('%u_%02u_%s', an.FolderNum, an.ExpNum, an.Condition);
an.matchData = matchData;
MatchList = [MatchList, an];
end
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = getSpecifications(varargin)
if(length(varargin) < 2 || mod(length(varargin), 2) == 1)
error('Invalid number of input arguments')
end
flagList = {'CellType', 'Category', 'BurstFreq', 'AutoCorr', ...
'SpikesPerBurst', 'BurstSpikeFreq', 'DutyCycle', 'SlowWaveAmp'};
flagList = lower(flagList);
specList = {'', NaN, [0, Inf], [-Inf, Inf], ...
[0, Inf], [0, Inf], [0, Inf], [0, Inf]};
searchList = {false, false, false, false, ...
false, false, false, false};
cellType = '';
category = NaN;
n = 1;
while(n < length(varargin))
flag = varargin{n};
if ~ischar(flag)
error(['Error with argument %d: \n', ...
'Search specifications must be strings.'], n + 1)
end
lowFlag = lower(flag);
flagInd = find(strcmp(flagList, lowFlag));
if(length(flagInd) == 0)
error('Unknown search specification: %s', lowFlag)
end
n = n + 1;
if(flagInd == 1)
cellType = varargin{n};
if ~ischar(flag)
error('CellType must be a string.')
elseif ~(strcmp(lower(cellType), 'gm') || ...
strcmp(lower(cellType), 'dg') || ...
strcmp(lower(cellType), 'lp') || ...
strcmp(lower(cellType), 'pd'))
error('Unknown cell type: %s', cellType)
end
elseif(flagInd == 2)
category = varargin{n};
else
specList{flagInd} = varargin{n};
if(length(specList{flagInd}) ~= 2)
error('Search specifications must be a range.')
end
searchList{flagInd} = true;
end
n = n + 1;
end
varargout = {cellType, category, specList, searchList};
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function stripStr = stripNums(conditionStr)
stripStr = regexp(conditionStr, '[a-zA-Z]*', 'match');
if(length(stripStr) == 0)
error('Cell type %s is invalid: must contain letters', conditionStr)
else
stripStr = lower(stripStr{1});
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function isInRange = InRange(x, range)
if( x < range(1) || x > range(2) )
isInRange = false;
else
isInRange = true;
end
return