-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_params.m
More file actions
375 lines (317 loc) · 15.8 KB
/
load_params.m
File metadata and controls
375 lines (317 loc) · 15.8 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
function [] = load_params
%%load_params: Load parameters for assays
global info
%% Import general experimental information
% These values will be common across all assay types
disp('Reading data from file....');
% Detect names of tabs in excel spreadsheet
[~, info.sheets] = xlsfinfo(info.calledfile);
alphabet = ['A':'Z'];
[~, headers, ~] = xlsread(info.calledfile, 'Index');
% Number of worm tracks to analyze
[I, J] = find(contains(headers, 'Number of Worms'));
if ~isempty(I) && ~isempty(J)
info.numworms = importfileXLS(info.calledfile, 'Index', strcat(alphabet(J), num2str(I+1)));
else
error('User Error. We could not locate the "Number of Worms" cell. Please check your index file.');
end
% Length of track (number of frames)
[I, J] = find(contains(headers, 'Number of Images'));
if ~isempty(I) && ~isempty(J)
info.tracklength = importfileXLS(info.calledfile, 'Index', strcat(alphabet(J), num2str(I+1)));
else
error('User Error. We could not locate the "Number of Images" cell. Please check your index file.');
end
% Quality check
if isempty(info.numworms) || isempty(info.tracklength)
error('User Error. The Index tab in your .xlsx file contains missing/incorrect values related to the number of worms or track length.');
end
% Unique IDs for worms
[I, J] = find(contains(headers, {'UID', 'ID'}));
if ~isempty(I) && ~isempty(J)
[~, info.wormUIDs] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
else
error('User Error. We could not locate the "UID" column. Please check your index file.');
end
% Quality check
if info.numworms > size(info.wormUIDs,1)
info.numworms = size(info.wormUIDs,1)
disp('Warning, the number of unique IDs found is less than the user-specified number of worms. The number of worms variable has been adjusted to match available data.')
end
% Camera sizing parameter (pixels per cm)
refstr = {'pixels per cm', 'ppcm', 'pixelspercm'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.pixelspercm(:,1) = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
else
error('User Error. We could not locate the "pixels per cm" cell. Please check your index file.');
end
if ~isequal(numel(info.wormUIDs),numel(info.pixelspercm(:,1)))
error('User Error. There appears to be missing values in the pixels per cm column.');
end
% Sampling frequency (value is 'Frame recorded every X seconds' - this is the input given to Basler's Pylon Viewer software)
refstr = {'frame', 'Frame', 'rate', 'Rate', 'sample'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.samplefreq(:,1) = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
else
disp('No sampling frequency values provided. The program will assume a frame rate (i.e. sampling frequency) of 1 image every 2 seconds.');
info.samplefreq(:,1) = repmat(2,info.numworms,1);
end
%% Import experimental information for thermotaxis assays
if contains(info.assaytype, 'OdorThermo_22') || contains(info.assaytype, 'Odor_22') ...
|| contains(info.assaytype, 'Iso_22') || contains(info.assaytype, 'Thermo_22')
% Gradient reference, generally the starting location of worms in the
% gradient (e.g. T(start))
refstr = {'T(start)', 'T(ref)', 'T(odor)', 'Gradient(start)', 'Gradient(ref)'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.ref = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient min value
refstr = {'Low gradient', 'Gradient low', 'Low','min', 'Min'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.min = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient max value
refstr = {'High Gradient', 'Gradient high', 'High', 'max', 'Max'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.max = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient steepness
refstr = {'cmperdeg', 'Gradient slope', 'gradient slope', 'Gradient Slope'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.rate = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
%% Import assay-specific parameters for thermotaxis assays
% If the assay type selected is Multisensory or Isothermal + Odor
if contains(info.assaytype, 'OdorThermo_22') || contains(info.assaytype, 'Odor_22')
% Import Landmark Coodinates
refstr = {'OdorXCoord','XCoord', 'X coordinates', 'RefXCoord'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.ref.x = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
refstr = {'OdorYCoord','YCoord', 'Y coordinates', 'RefYCoord'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.ref.y = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Quality Checks of Landmark Coordinates
if ~isequal(numel(info.ref.x),numel(info.ref.y),numel(info.wormUIDs))
error('User Error. The Index tab in your .xlsx file contains missing values in columns containing landmark X/Y coordinates.');
end
% Odor Scoring Region
[~, info.SR.shape] = xlsread(info.calledfile, 'Index', 'A14');
if info.SR.shape{1} == 'C' % scoring region shape is a circle
info.SR.w = 2; % width, in cm
info.SR.h = 2; % height, in cm
elseif info.SR.shape{1} == 'S' %scoring region shape is square-ish aka a rectangle (staying away from using 'R' as anything but 'Right')
info.SR.w = 2; % width, in cm
info.SR.h = 3; % height, in cm
else
error('User Error. The Odor Arena shape value does not match expected values. It should be S (square-ish) or C (circle)');
end
end
% If the assay type is a Pure isothermal (4) or Pure thermotaxis (1)
if contains(info.assaytype, 'Iso_22') || contains(info.assaytype, 'Thermo_22')
% Import Landmark Coodinates
refstr = {'XCoord', 'X coordinates', 'RefXCoord', 'T(s) XCoord'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.ref.x = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
[info.ref.y] = deal(NaN(1,info.numworms)); %Will populate this later.
end
end
%% Import experimental information for chemotaxis assays
if contains(info.assaytype, 'Bact_4.9') || contains(info.assaytype, 'C02_3.75') ...
|| contains(info.assaytype, 'Pher_5') || contains(info.assaytype, 'Odor_5')
% Orientation for non-thermotaxis assays
[I, J] = find(contains(headers, {'Orientation', 'orientation'}));
if ~isempty(I) && ~isempty(J)
[~, info.plateorient] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
if isempty(info.plateorient)
[info.plateorient] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
end
% Alignment ROIs for rotation - usually the gas ports or odor regions
[I, J] = find(contains(headers, 'XL'));
info.ref.Lx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YL'));
info.ref.Ly = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'XR'));
info.ref.Rx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YR'));
info.ref.Ry = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
%% Import assay-specific parameters for chemotaxis assays
if contains(info.assaytype, 'Bact_4.9')
info.radius = 4.9/2; % radius of bacterial chemotaxis assay circle
info.scoringradius = 2/2; % radius of scoring circles
info.inter_port_interval = (info.radius*2)-(info.scoringradius*2); % calculate distance between centers of two ports
info.inter_port_interval = repmat(info.inter_port_interval, info.numworms,1);
disp('Bacterial Chemotaxis Assay Parameters Loaded');
end
if contains(info.assaytype, 'C02_3.75')
info.radius = 3.75/2; % radius of CO2 assay circle
info.portradius = 0.3175/2; % inner radius of CO2/Air ports
info.inter_port_interval = 4.75; % NB measured this distance for ASB on 9/24/19
info.inter_port_interval = repmat(info.inter_port_interval, info.numworms,1);
disp('CO2 Assay Parameters Loaded');
end
if contains(info.assaytype, 'Pher_5')
info.radius = 5/2; % radius of pheromone chemotaxis assay circle; provided to ASB on 12/2/19
info.scoringradius = 2/2; % radius of scoring circles
info.inter_port_interval = (info.radius*2)-(info.scoringradius*2); % calculate distance between centers of two ports
info.inter_port_interval = repmat(info.inter_port_interval, info.numworms,1);
disp('Pheromone Assay Parameters Loaded');
end
if contains(info.assaytype, 'Odor_5')
info.radius = 5/2; % radius of odor chemotaxis assay circle
info.scoringradius = 1/2; % radius of scoring circles
info.inter_port_interval = repmat(2, info.numworms,1); % MLC gave ASB this distance on 12/4/19
disp('Odor Assay Parameters Loaded');
end
end
%% Import experimental information for custom linear assays
if contains(info.assaytype, 'Custom_linear')
% Orientation for non-thermotaxis assays
[I, J] = find(contains(headers, {'Orientation', 'orientation'}));
if ~isempty(I) && ~isempty(J)
[~, info.plateorient] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
% If plate orientation values aren't letters (e.g. Y/N), then this
% next code chunk assumes they are numbers (e.g. logical 1/0) and
% imports numbers.
if isempty(info.plateorient)
[info.plateorient] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
end
% Alignment ROIs for rotation - usually the gas ports or odor regions
[I, J] = find(contains(headers, 'XL'));
info.ref.Lx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YL'));
info.ref.Ly = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'XR'));
info.ref.Rx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YR'));
info.ref.Ry = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
% Distance between alignment ROIs
refstr = {'alignment distance', 'Alignment distance', 'inter-port interval', 'Inter-alignment distance'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.inter_port_interval = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient min value
refstr = {'Gradient low', 'gradient low', 'Low','min', 'Min'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.min = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient max value
refstr = {'Gradient High', 'gradient high', 'High', 'max', 'Max'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.max = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
% Gradient steepness
refstr = {'cmperdeg', 'Gradient slope', 'gradient slope'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.gradient.rate = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
end
%% Import experimental information for basic information about worm tracks, ignoring gradients
if contains(info.assaytype, 'Basic_info') || contains(info.assaytype, 'GasShift')
% Alignment ROIs for rotation - usually the gas ports or odor regions
[I, J] = find(contains(headers, 'XL'));
info.ref.Lx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YL'));
info.ref.Ly = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'XR'));
info.ref.Rx = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
[I, J] = find(contains(headers, 'YR'));
info.ref.Ry = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
% Distance between alignment ROIs
refstr = {'alignment distance', 'Alignment distance', 'inter-port interval', 'Inter-alignment distance'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
info.inter_port_interval = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1),...
':',alphabet(J), num2str(info.numworms+1)));
end
end
%% Import timing information when assays involve sequential presentation of stimuli
if contains(info.assaytype, 'GasShift')
% Timing of stimulus presentation
refstr = {'Stimulus Timing'};
[I, J] = find(contains(headers, refstr));
if ~isempty(I) && ~isempty(J)
[~,~,info.stim_timing] = xlsread(info.calledfile, 'Index', strcat(...
alphabet(J), num2str(I+1)));
info.stim_timing = str2double(split(info.stim_timing, {',',';'}));
end
end
end