-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComparePhenotypeModelling.m
More file actions
358 lines (254 loc) · 11.2 KB
/
ComparePhenotypeModelling.m
File metadata and controls
358 lines (254 loc) · 11.2 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
%
% Phenotype can be WT,Isl2heterozygous,Isl2homozygous,ephrinA2mm,
% ephrinA5mm, ephrinA2mmA5mm, TKO
%
% Action can be: run, analyse
%
% expNum is used if you want to run multiple runs with same
% parameter from another script to do statistics. This allows you
% to separate the runs.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function report = ComparePhenotypeModelling(phenotype,action, ...
expNum,plotFigures,kMask,model, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(~exist('model'))
model = 'koulakov';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(~exist('expNum'))
expNum = '';
else
if(ischar(expNum))
% Fix for DS compiled code
expNum = str2num(expNum);
end
expNum = sprintf('-rep-%d', expNum);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(~exist('plotFigures'))
% Show figures!
plotFigures = 1;
else
if(ischar(plotFigures))
plotFigures = str2num(plotFigures);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(~exist('kMask'))
disp('No masking of gradients.')
kMask = 0; % 0 = no masking, 2 = subtractive masking
elseif(ischar(kMask))
% DS compile code fix, he parses the numbers as strings...
kMask = str2num(kMask);
end
% Added extra asserts to help DS
assert(kMask == 0 | kMask == 2 | kMask == 3);
assert(kMask ~= 1); % This is reaction scheme masking, make sure
% we dont do this by accident...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DWgrid = true; % Do DW grid analysis?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(strcmpi('Math5',phenotype))
% Do not do DW grid analysis for Math5 - the code crashes
DWgrid = false;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nSC = 2000; %5000;
typeFlag = 1; %2;
forwardChem = 90; %20;
reverseChem = 0; %10;
betaMod = 3/2;
gammaAct = 0.05/8; % Make it weaker (default Koulakov is 0.05/2)
% See FitCI.m, uses Stafford 2009 data
% Assums retina is 5mm (flattened out)
bActB2KO = 1/(5e-3*1260);
gammaActB2KO = gammaAct*9.275/22.64;
noiseLevel = 0; % Lower value means higher noise, 20 looks
% good! 0 = no noise
nStep = 10000*nSC;
repStep = 1000*nSC; % inf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
baseSimName = 'ComparePhenotype';
simName = sprintf('%s-%s-%s%s',baseSimName,model,phenotype,expNum);
experimentDir = sprintf('experiments/%s', baseSimName);
dataPath = sprintf('SAVE/%s', baseSimName);
figPath = sprintf('FIGS/%s', baseSimName);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch(action)
case 'run'
if(~exist(experimentDir))
mkdir(experimentDir);
end
if(~exist(figPath))
mkdir(figPath)
end
if(~exist(dataPath))
mkdir(dataPath)
end
filename = sprintf('%s/%s.txt', experimentDir, simName);
writeConfig(phenotype,filename);
switch(model)
case 'template'
% This sets up the intial conditions
r = RetinalMap();
r.loadExperimentConfigFile(filename);
r.placeRetinalRGCdisk();
r.placeSC();
r.loadGradients(r.phenotype);
% This is an example of how to integrate the your own model with
% the framework
templatemodel(r);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'koulakov'
r = RetinalMap(filename);
r.run();
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Gierer2D'
% Setup neuron position and gradients
r = RetinalMap();
r.loadExperimentConfigFile(filename);
r.placeRetinalRGCdisk();
r.placeSC();
r.loadGradients(r.phenotype);
% Export gradients and neuron locations to file
r.exportGradients();
% Write config file for Gierer2D R code
RGCfile = sprintf('%s-retinal-gradients.txt',r.simName);
SCfile = sprintf('%s-SC-gradients.txt',r.simName);
paramFilename = sprintf('%s-parameters.R',r.simName);
paramFilenameFull = sprintf('%s/%s',r.dataPath, paramFilename);
% The R code runs in the SAVE/Gierer2D code, so no need for path
outputFile = sprintf('%s-weights.dat',r.simName);
outputFileFull = sprintf('%s/%s',r.dataPath,outputFile);
fid = fopen(paramFilenameFull,'w');
fprintf(fid,'% Automatically generated by ComparePhenotypeModelling.m\n');
fprintf(fid,'rgc.file = "%s"\n', RGCfile);
fprintf(fid,'sc.file = "%s"\n', SCfile);
fprintf(fid,'op.file = "%s"\n', outputFile);
for i = 1:length(varargin)
fprintf('Writing to Gierer config file: %s\n', varargin{i})
fprintf(fid,'%s\n',varargin{i});
end
fclose(fid);
% Call Gierer2D code in R
wd = pwd;
sysCmd = sprintf('cd %s; %s/gierer/inst/runGierer2Dv3.R %s', ...
r.dataPath, wd, paramFilename);
fprintf('Doing: %s\n',sysCmd)
system(sysCmd)
% Import resulting weight matrix back into matlab
% r.importConnectionMatrix(outputFileFull);
r.importConnectionIndexes(outputFileFull);
r.curStep = NaN;
% Save state, will contain all information at endpoint
r.saveState();
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'WhiteCow'
% Setup neuron position and gradients
r = RetinalMap();
r.loadExperimentConfigFile(filename);
r.placeRetinalRGCdisk();
r.placeSC();
r.loadGradients(r.phenotype);
% Export gradients and neuron locations to file
r.exportGradients();
% Write config file for Whitelaw and Cowan R code
% !!! Should the file names include the path?!
RGCfile = sprintf('%s-retinal-gradients.txt',r.simName);
SCfile = sprintf('%s-SC-gradients.txt',r.simName);
paramFilename = sprintf('%s-parameters.R',r.simName);
paramFilenameFull = sprintf('%s/%s',r.dataPath, paramFilename);
outputFile = sprintf('%s-weights.dat',r.simName);
outputFileFull = sprintf('%s/%s',r.dataPath,outputFile);
fid = fopen(paramFilenameFull,'w');
fprintf(fid,'% Automatically generated by ComparePhenotypeModelling.m\n');
fprintf(fid,'rgc.file = "%s/%s"\n', r.dataPath, RGCfile);
fprintf(fid,'sc.file = "%s/%s"\n', r.dataPath, SCfile);
fprintf(fid,'op.file = "%s"\n', outputFileFull);
fclose(fid);
% Call Whitelaw and Cowan code in R
sysCmd = sprintf('WhitelawCowan/runWhitelawCowan.R %s', ...
paramFilenameFull);
fprintf('Doing: %s\n',sysCmd)
system(sysCmd)
% Import resulting weight matrix back into matlab
r.importConnectionMatrix(outputFileFull);
r.curStep = NaN;
% Save state, will contain all information at endpoint
r.saveState();
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Markerinduction'
r = markerInductionBatch(filename);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'GrimbertCang'
useAltP = true;
Pfactor = 1;
ignoreGradients = false;
r = runGrimbertCang([],useAltP,Pfactor,ignoreGradients,filename);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
otherwise
disp(['Unsupported model, use: koulakov, Gierer2D, WhitelawCowan, ' ...
'GrimbertCang or Markerinduction'])
report = [];
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
report = r;
case 'analyse'
skipTables = 1;
filename = sprintf('%s/%s.mat', ...
dataPath, simName);
r = RetinalMap();
r.loadState(filename,skipTables);
report = r.makeReport(plotFigures,DWgrid);
otherwise
fprintf('Unknown action: %s\n', action)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function writeConfig(phenotype, filename)
fid = fopen(filename,'w');
fprintf(fid,'% Automatically generated by ComparePhenotypeModelling.m\n');
fprintf(fid,'obj.nSC = %d;\n', nSC);
% !!! Math5
if(strcmpi('Math5',phenotype))
fprintf('RGC population reduced to 10%\n')
fprintf(fid,'obj.nRGC = %d;\n', nSC*0.1);
else
fprintf(fid,'obj.nRGC = %d;\n', nSC);
end
fprintf(fid,'obj.eyeType = ''disk'';\n');
fprintf(fid,'obj.gradientGenerationMethod = ''phenotype'';\n');
fprintf(fid,'obj.phenotype = ''%s'';\n', phenotype);
fprintf(fid,'obj.RGCnoiseLevelN = %f;\n', noiseLevel);
fprintf(fid,'obj.SCnoiseLevelN = %f;\n', noiseLevel);
fprintf(fid,'obj.kMask = %f;\n', kMask);
fprintf(fid,'obj.typeFlag = %d;\n', typeFlag);
fprintf(fid,'obj.alphaForwardChem = %d;\n', forwardChem);
fprintf(fid,'obj.betaForwardChem = %d;\n', forwardChem*betaMod);
fprintf(fid,'obj.alphaReverseChem = %d;\n', reverseChem);
fprintf(fid,'obj.betaReverseChem = %d;\n', reverseChem*betaMod);
if(strcmpi('Beta2KO',phenotype))
% !!! Beta2 KO
fprintf(fid,'obj.bAct = %d;\n', bActB2KO);
fprintf(fid,'obj.gammaAct = %d;\n', gammaActB2KO);
else
% WT
fprintf(fid,'obj.gammaAct = %d;\n', gammaAct);
% Use default bAct value.
end
fprintf(fid,'obj.simName = ''%s'';\n', simName);
fprintf(fid,'obj.dataPath = ''%s'';\n', dataPath);
fprintf(fid,'obj.figurePath = ''%s'';\n', figPath);
fprintf(fid,'obj.nSteps = %d;\n', nStep);
fprintf(fid,'obj.useLocalJumps = false;\n');
fprintf(fid,'obj.RGCwidth = 2;\n');
% We want intermediate saves
fprintf(fid,'obj.reportStep = %d;\n',repStep);
% Display figures
fprintf(fid,'obj.plotFigures = %d;\n',plotFigures)
% disp('Changing gradient generation file from default.')
% fprintf(fid,'obj.gradientInfoFile = ''gradients/Eph-ephrins-more-Isl2-paper.csv'';\n')
fclose(fid);
end
end