-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframeExporter.m
More file actions
383 lines (299 loc) · 10.7 KB
/
frameExporter.m
File metadata and controls
383 lines (299 loc) · 10.7 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
376
377
378
379
380
381
382
383
%% fullbkg
function frameExporter(~,datename,channelstoinput,stimulationFrame)
% datename = '2015_12_15 smad3g smFISH';
E={datename}; %beginning of file name for saving
%determine path to .m file being executed
mdir = mfilename('fullpath');
[~,b] = regexp(mdir,'Tracking\w*/');
if isempty(b)
[~,b] = regexp(mdir,'Tracking\w*\');
end
parentdir = mdir(1:b);
%determine path to gparent folder
[~,b ] = regexp(parentdir,'/');
if isempty(b)
[~,b] = regexp(parentdir,'\');
end
gparentdir = parentdir(1:b(end-1));
%assign path to experiment folder
cd(gparentdir)
expPath = strcat(gparentdir,datename);
cd(expPath)
%determine date and experiment number
[a,b] = regexp(datename,'exp[0-9]+');
expnum = datename(a:b);
dateofexp = datename(1:10);
%assign path to .mat image stack exports
mstackdir = 'mstack images';
flatfielddirname = 'flat mstack';
moviedirname = 'moviestack';
segdirname = 'segment mstack';
mstackPath = strcat(expPath,'/',mstackdir);
flatstackPath = [expPath '/' flatfielddirname];
segstackpath = [expPath '/' segdirname];
moviestackPath = [expPath '/' moviedirname];
%assign path to folder for metadata export files
metadir = strcat(parentdir,'Export/');
cd(metadir)
%%
FileName =datename;
[a,~] = regexp(datename,'_nuclei');
datequery = strcat(datename,'*metaData.mat');
filedatestr = datename(1:a-1);
cd(metadir)
load([datename '_nuclei_export.mat'])
filelist = dir(datequery);
if length({filelist.name}) ==1
metaData = load(char(filelist.name));
else
filename = uigetfile();
metaData = load(filename);
end
%determine the timeVector from metaData [dim 1 is scene#, dim 2 is each time frame]
timeVec = metaData.timeVec;
%load information regarding doses and scenes and tgfbeta addition
% [a,~] = regexp(FileName,'_nuclei');
datequery = strcat(FileName,'*DoseAndScene*');
cd(metadir)
filelist = dir(datequery);
if isempty(filelist)
dosestruct = makeDoseStruct; %run function to make doseStruct
else
dosestructstruct = load(char(filelist.name));
dosestruct = dosestructstruct.dosestruct;
end
%finished collecting metaData
%now combine metaDeta together
%determine the scenes present in the experiment in order to combine metadata
scenestr = 'scene';
sceneListArray = vertcat({exportNucleiStruct.(scenestr)});
sceneList = unique(sceneListArray);
sceneListArrayTwo = vertcat({dosestruct.(scenestr)});
%combine the exportStruct information with dosestruct information
for i=1:length(sceneList)
sceneChoice=sceneList{i};
indices = strcmp(sceneListArray,sceneChoice);
indicestwo = strcmp(sceneListArrayTwo,sceneChoice);
fnamesz = fieldnames(dosestruct);
for p = 1:length(fnamesz)
fnstr = fnamesz{p};
var = dosestruct(indicestwo).(fnstr);
if isnumeric(var)
[exportNucleiStruct(indices).(fnstr)] = deal(var);
else
[exportNucleiStruct(indices).(fnstr)] = deal(char(var));
end
end
end
%combine the exportStruct information with dosestruct information
for i=1:length(sceneList)
sceneChoice=sceneList{i};
indices = strcmp(sceneListArray,sceneChoice);
indicestwo = strcmp(sceneListArrayTwo,sceneChoice);
expdate = FileName(1:a-1);
fnamesz = fieldnames(dosestruct);
for p = 1:length(fnamesz)
fnstr1 = 'dosestr';
fnstr2 = 'conditions';
fnstr3 = 'expdate';
var1 = dosestruct(indicestwo).(fnstr1);
var2 = dosestruct(indicestwo).(fnstr2);
[exportNucleiStruct(indices).doseAndCondition] = deal([char(var1) char(var2)]);
[exportNucleiStruct(indices).doseconddate] = deal([expdate ' ' char(var1) ' ' char(var2)]);
[exportNucleiStruct(indices).(fnstr3)] = deal(expdate);
end
end
doseListArray = vertcat({exportNucleiStruct.dosestr});
%%
metadir = strcat(parentdir,'Export/');
cd(metadir)
%find associated extracted metadata
filelist = dir(strcat('*',dateofexp,'*',expnum,'*metaData.mat'));
metadatafile = char(filelist.name);
A = load(metadatafile);
dim = A.dimensions;
timeCount = A.timeCount;
timeMatrix = A.timeVec;
channelinputs =channelregexpmaker(channelstoinput);
cd(flatstackPath)
dirlist = dir('*.mat');
[~,~,~,channelsListed] = regexp([dirlist.name],channelinputs);
[~,~,~,sceneListArray] = regexp([dirlist.name],'s[0-9]+');
channelList = unique(channelsListed);
sceneList = unique(sceneListArray);
cd(flatstackPath)
% sceneVec = {'s29','s36'};
% conditionsArray = {'CMV-NG-Smad3 (NMuMG)','NG-Smad3(NMuMG)'};
% LigandArray = {'Tgf','Tgf'};
sceneVec = {'s005','s020','s035','s050','s065','s080','s095','s110'};
sceneVec = {'s05','s10','s15','s20','s25','s30'};
% conditionsArray = {'C2C12','C2C12','C2C12','C2C12','C2C12'};
% LigandArray = {'BMP-10','BMP-10','BMP-10','BMP-10','BMP-10'};
% smadArray = {'Citrine-Smad5','Citrine-Smad1','Citrine-Smad1','Citrine-Smad5','Citrine-Smad3'};
% scarlettArray = {'Scarlett-Smad1','Scarlett-Smad5','Scarlett-Smad1','Scarlett-Smad5','Scarlet-Smad1'};
%%
close all
%scaled individually
f997 = figure(997);
colormap(f997,'gray');
f997.Units = 'pixels';
f997.Position = [200 200 2045 512];
%
cycle=0;
for j = 1:length(sceneVec)
for c = 1:length(channelList) %cycle through one channel at a time
cycle=cycle+1;
h(cycle) = axes();
pos = zeros(1,4);
pos(1) = (j-1)./length(sceneVec);
pos(2) = (c-1)./length(channelList);
pos(3) = 1./length(sceneVec);
pos(4) = 1./length(channelList);
h(cycle).Position =pos;
end
end
[h.XTick]=deal([]);
[h.YTick]=deal([]);
[h.YDir] = deal('reverse');
[h.NextPlot] = deal('replacechildren');
%scaled identically
f998 = figure(998);
colormap(f998,'gray');
f998.Units = 'pixels';
f998.Position = [200 200 2045 512];
cycle=0;
for j = 1:length(sceneVec)
for c = 1:length(channelList) %cycle through one channel at a time
cycle=cycle+1;
hh(cycle) = axes();
pos = zeros(1,4);
pos(1) = (j-1)./length(sceneVec);
pos(2) = (c-1)./length(channelList);
pos(3) = 1./length(sceneVec);
pos(4) = 1./length(channelList);
hh(cycle).Position =pos;
end
end
[hh.XTick]=deal([]);
[hh.YTick]=deal([]);
[hh.YDir] = deal('reverse');
[hh.NextPlot] = deal('replacechildren');
%
cd(flatstackPath)
cycle =0;
for j = 1:length(sceneVec)
tic
for c = 1:length(channelList) %cycle through one channel at a time
cycle =cycle+1;
channel = channelList{c};
scenestr = sceneVec{j};
scenenum = str2double(scenestr(2:end));
dandc=exportNucleiStruct(scenenum).doseAndCondition;
disp(dandc);
filelist = dir(strcat('*',scenestr,'*',channel,'*.mat'));
filename = char(filelist.name);
mfile = matfile(filename);
imgs1 = mfile.flatstack;
cd(segstackpath)
filelist = dir(strcat('*',scenestr,'*',channel,'*background*.mat'));
filename = char(filelist.name);
mfile = matfile(filename);
imgs1back = mfile.IfFinal;
for kk = 1:size(imgs1,3)
imm = imgs1(:,:,kk);
immb = imgs1back(:,:,kk);
imgs1(:,:,kk) = imm-median(median(imm(~immb)));
end
cd(flatstackPath)
olddir = pwd;
SAVdir = strcat(expPath,'/',moviedirname,'/');
if isdir(SAVdir)
else
mkdir(SAVdir)
end
cd (SAVdir);
%
imgsnew = imgs1(100:400,100:400);
imgsnew(imgsnew>prctile(imgs1(:),98)) = prctile(imgs1(:),98);
imgsnew(imgsnew<prctile(imgs1(:),1)) = prctile(imgs1(:),1);
specialdir = [expPath '/FocusFrames'];
if ~isdir(specialdir)
mkdir(specialdir)
end
imagesc(h(cycle),imgsnew(:,:,end));
h(cycle).CLim = [prctile(imgsnew(:),2) prctile(imgsnew(:),99)];
h(cycle).Title.String = scenestr;
h(cycle).XLim = [0 size(imgsnew,1)];
h(cycle).YLim = [0 size(imgsnew,2)];
colorv = [0 1];
posv = [0.05 0];
for jo = 1:2
t=text(h(cycle),0,0,'r');
t.Position=[0,posv(jo)];
t.String = [scenestr '-' dandc];
t.Color = [colorv(jo) 0 0];
t.FontSize = 15;
t.VerticalAlignment = 'top';
t.FontWeight = 'bold';
end
cd(olddir)
imgs2 = imgs1(100:400,100:400,:);
%background subtraction
imagesc(hh(cycle),imgs2(:,:,1));
% h(cycle).CLim = [prctile(imgsnew(:),2) prctile(imgsnew(:),99)];
hh(cycle).CLim = [0 10000];%set CLIM
hh(cycle).Title.String = scenestr;
hh(cycle).XLim = [0 size(imgs2,1)];
hh(cycle).YLim = [0 size(imgs2,2)];
colorv = [0 1];
posv = [0.05 0];
for jo = 1:2
t=text(hh(cycle),0,0,'r');
t.Position=[0,posv(jo)];
t.String = [scenestr '-' dandc];
t.Color = [colorv(jo) 0 0];
t.FontSize = 15;
t.VerticalAlignment = 'top';
t.FontWeight = 'bold';
end
cd(olddir)
end
toc
end
% cd(specialdir)
cd('I:\Frick')
saveas(f997,[E{1} '-focustest.tif'],'tiff');
saveas(f998,[E{1} '-scaledidentically.tif'],'tiff');
end
function savethatimage(savename,SAVdir,mstackPath,flatstack,j)
disp(strcat(savename,'...',num2str(j)));
cd (SAVdir);
% imwrite(flatstack,char(savename),'tiff');
% save(flatstack,char(savename),'tiff');
% save(savename,'flatstack','-v7.3');
% save(savename,'flatstack','-v6');
imwrite( flatstack(:,:,1), savename,'WriteMode','overwrite');
cd (mstackPath);
end
function channelinputs =channelregexpmaker(channelstoinput)
channelinputs = '(';
for i=1:length(channelstoinput) % creates a string of from '(c1|c2|c3|c4)' for regexp functions
if i ==1 & length(channelstoinput)==1
channelinputs = channelstoinput{i};
elseif i ==1
channelinputs = strcat(channelinputs,channelstoinput{i});
elseif i < length(channelstoinput)
channelinputs = strcat(channelinputs,'|',channelstoinput{i});
else
channelinputs = strcat(channelinputs,'|',channelstoinput{i},')');
end
end
end
function chanstruct = alterChanName(chan)
[a,~] = regexp(chan,'(_|\W|\s|[0-9])'); %remove underscore, dashes, or whitespace
chanstruct = chan;
chanstruct(a) = [];
if isempty(chanstruct)
chanstruct = 'CFP';
end
end