/
LTQ-10-10-16-v12.31.ijm
319 lines (248 loc) · 10.4 KB
/
LTQ-10-10-16-v12.31.ijm
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
setBatchMode(true);
verbose = false;
//Set the source and directories
sdir = getDirectory("Choose Source Directory ");
inputdir = sdir+"Input/"
File.makeDirectory(inputdir);
//Create directories for the results
resultsdir = sdir+"Results/"
File.makeDirectory(resultsdir);
outputdir = sdir+"Output/"
File.makeDirectory(outputdir);
DNAmaskdir = sdir+"DNAmask/"
File.makeDirectory(DNAmaskdir);
DNAshapedir = sdir+"DNAshape/"
File.makeDirectory(DNAshapedir);
edgemaskdir = sdir+"edgemask/"
File.makeDirectory(edgemaskdir);
edgemasktifdir = sdir+"edgemasktif/"
File.makeDirectory(edgemasktifdir);
iminfodir = sdir+"iminfo/"
File.makeDirectory(iminfodir);
//Get the list of files in the input directory
list = getFileList(inputdir);
//Open each file one at a time if it is a .tif
for (i=0; i<list.length; i++){
if (endsWith(list[i], "tif")){
file = inputdir+list[i];
//Get the filename stem without the extension
stems = split(list[i],".");
stem = stems[0];
//generate the filepath
path = inputdir+stem+".tif";
//open the file
open(path);
run("Show Info...");
selectWindow("Info for "+stem+".tif");
saveAs("Text", iminfodir+stem+".txt");
selectWindow("Info for "+stem+".tif");
run("Close");
//Convert to 8-bit
//run("8-bit");
//split the channels
run("Split Channels");
//Store red channel name
w0 = "C1-"+stem+".tif";
//Store green channel name
w1 = "C2-"+stem+".tif";
//Store blue channel name
// w2 = "C3-"+stem+".tif";
w2 = w0;
//Duplicate the blue channel
selectWindow(w2);
run("Duplicate...", "title="+w2+" duplicate channels=1");
//Add Gaussian Blur
run("Gaussian Blur...", "sigma=2 scaled stack");
//Threshold automatically using an algorithm that maximises the inter-class entropy of the image histogram
//setAutoThreshold("MaxEntropy dark");
//run("Threshold...");
setThreshold(30, 255);
//run("Threshold...");
setOption("BlackBackground", true);
//Make a binary mask and fill holes (ignores the nucleolus)
setOption("BlackBackground", true);
run("Convert to Mask", "method=Default background=Default black");
run("Fill Holes", "stack");
//Run 3D segmentation and invert the result
print("Segmenting Genome Volume");
run("3D Simple Segmentation", "low_threshold=30 min_size=1000 max_size=-1");
run("3D OC Options", "volume surface nb_of_obj._voxels nb_of_surf._voxels centroid bounding_box dots_size=0 font_size=0 store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none");
print("Detecting Genome Volume");
run("3D Objects Counter", "threshold=1 slice=10 min.=500 max.=8912896 exclude_objects_on_edges objects surfaces centroids centres_of_masses statistics summary");
run("Brightness/Contrast...");
selectWindow("Objects map of Seg");
rename(stem+"-shape");
//waitForUser("Click OK");
run("3D Shape Measure");
saveAs("Results", DNAshapedir+stem+"-DNAshape.csv");
run("Clear Results");
selectWindow(stem+"-shape");
run("Find Edges", "stack");
setThreshold(1, 255);
run("Convert to Mask", "method=Default background=Default black");
saveAs("Tiff", edgemasktifdir+stem+"-edge.tif");
run("Close");
// waitForUser("Click OK");
selectWindow("Bin");
run("Invert", "stack");
//Subtract the binary mask from the original image
imageCalculator("Subtract create stack", w2,"Bin");
selectWindow("Result of "+w2);
rename("Segment1");
//Apply a median filter and another, less stringent threshold to the masked image
selectWindow("Segment1");
run("Gaussian Blur...", "sigma=0.5 scaled stack");
run("Median...", "radius=20 stack");
setThreshold(10, 255);
setOption("BlackBackground", true);
run("Convert to Mask", "method=Default background=Default black");
run("Fill Holes", "stack");
//Save an improved mask
saveAs("Tiff", DNAmaskdir+stem+"-mask.tif");
// waitForUser("Click OK");
selectWindow(stem+"-mask.tif");
run("Invert", "stack");
//Subtract the new mask from the original image
imageCalculator("Subtract create stack", w2,stem+"-mask.tif");
//Run 3D object counter
run("3D OC Options", "volume surface nb_of_obj._voxels nb_of_surf._voxels integrated_density mean_gray_value std_dev_gray_value median_gray_value minimum_gray_value maximum_gray_value centroid mean_distance_to_surface std_dev_distance_to_surface median_distance_to_surface centre_of_mass bounding_box dots_size=5 font_size=10 show_numbers white_numbers store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none");
print("Detecting Chromosome Shape");
run("3D Objects Counter", "threshold=30 slice=10 min.=500 max.=8912896 exclude_objects_on_edges objects surfaces centroids centres_of_masses statistics summary");
//Save measurements
selectWindow("Statistics for Result of "+w2);
saveAs("Results", resultsdir+"C1-"+stem+".csv");
selectWindow("Statistics for Result of "+w2);
run("Close");
//Make a boundary outline
selectWindow("Objects map of Result of "+w2);
run("Brightness/Contrast...");
run("Gaussian Blur...", "sigma=0.5 scaled stack");
setThreshold(1,255);
run("Convert to Mask", "method=Default background=Default black");
run("Fill Holes", "stack");
run("Despeckle", "stack");
//save another improved mask
saveAs("Tiff", DNAmaskdir+stem+"-mask.tif");
open(edgemasktifdir+stem+"-edge.tif");
setThreshold(1, 255);
run("Convert to Mask", "method=Default background=Default black");
run("Rotate 90 Degrees Right");
edgepath = edgemaskdir+stem+"-edge";
print(edgepath);
run("Image Sequence... ", "format=Text name="+stem+"- start=0 digits=4 use save="+edgepath+"-0000.txt save="+edgepath+"-0000.txt");
run("Rotate 90 Degrees Left");
open(edgemasktifdir+stem+"-edge.tif");
//Rename the centroid map channel
w3 ="Centroids map of Result of "+w2;
selectWindow(w3);
rename("centroids");
open(DNAmaskdir+stem+"-mask.tif");
selectWindow(stem+"-mask.tif");
//Merge into an overlay and save
run("Merge Channels...", "red="+stem+"-edge.tif green=centroids blue="+w2+" create keep ignore");
saveAs("Tiff", outputdir+stem+"-DNA-OL.tif");
run("Close All");
//Set the output directories for the red channel
ltdir = sdir+"LocusTagResults/";
File.makeDirectory(ltdir);
ltoutputdir = sdir+"LocusTagOutput/";
File.makeDirectory(ltoutputdir);
detoutputdir = sdir+"DetectionOutput/";
File.makeDirectory(detoutputdir);
open(DNAmaskdir+stem+"-mask.tif");
//rename("mask");
run("Invert", "stack");
open(path);
//Convert to 8-bit
//run("8-bit");
//split the channels
run("Split Channels");
//Store red channel name
w0 = "C2-"+stem+".tif";
//Store green channel name
// w1 = "C2-"+stem+".tif";
//Store blue channel name
w2 = "C1-"+stem+".tif";
imageCalculator("Subtract create stack",w0,stem+"-mask.tif");
run("Gaussian Blur...", "sigma=0.5 scaled stack");
//run("Auto Threshold", "method=Yen white stack");
setThreshold(80, 255);
setOption("BlackBackground", true);
run("Convert to Mask", "method=Default background=Default black");
run("Invert", "stack");
imageCalculator("Subtract create stack",w0,"Result of "+w0);
run("3D Simple Segmentation", "low_threshold=70 min_size=15 max_size=-1");
selectWindow("Bin");
run("Invert", "stack");
imageCalculator("Subtract create stack",w0,"Bin");
run("3D OC Options", "volume surface nb_of_obj._voxels nb_of_surf._voxels integrated_density mean_gray_value std_dev_gray_value median_gray_value minimum_gray_value maximum_gray_value centroid mean_distance_to_surface std_dev_distance_to_surface median_distance_to_surface centre_of_mass bounding_box dots_size=5 font_size=10 show_numbers white_numbers store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none");
print("Detecting Locus Tag Signal");
run("3D Objects Counter", "threshold=70 slice=10 min.=15 max.=8912896 exclude_objects_on_edges objects surfaces centroids centres_of_masses statistics summary");
selectWindow("Statistics for Result of "+w0);
saveAs("Results", ltdir+stem+".csv");
stat ="Statistics for Result of "+w0;
selectWindow(stat);
run("Close");
selectWindow("Objects map of Result of "+w0);
run("Brightness/Contrast...");
rename("Bin");
w5 ="Centroids map of Result of "+w0;
selectWindow(w5);
rename("centroids");
selectWindow("Bin");
run("Invert", "stack");
run("Merge Channels...", "red=Bin green=centroids blue="+w2+" create keep ignore");
saveAs("Tiff", ltoutputdir+stem+"-LT-OL.tif");
selectWindow("B&C");
run("Close");
//waitForUser("Click OK");
run("Close All");
//open(outputdir+stem+"-DNA-OL.tif");
//split the channels
// run("Split Channels");
//Store red channel name
// w10 = "C1-"+stem+"-DNA-OL.tif";
//Store green channel name
// w11 = "C2-"+stem+"-DNA-OL.tif";
//Store blue channel name
//w12 = "C3-"+stem+"-DNA-OL.tif";
//open(ltoutputdir+stem+"-LT-OL.tif");
//split the channels
// run("Split Channels");
//Store red channel name
// w13 = "C1-"+stem+"-LT-OL.tif";
//Store green channel name
// w14 = "C2-"+stem+"-LT-OL.tif";
//Store blue channel name
//w15 = "C3-"+stem+"-LT-OL.tif";
//imageCalculator("Add create stack",w11,w13);
//rename("DNA-cent-LT-mask");
//selectWindow("DNA-cent-LT-mask");
//run("RGB Color");
//run("8-bit Color", "number=256");
//imageCalculator("Add create stack",w10,w14);
//rename("DNA-mask-LT-cent");
//selectWindow("DNA-mask-LT-cent");
//run("RGB Color");
//run("8-bit Color", "number=256");
//open(DNAmaskdir+stem+"-mask.tif");
//run("Invert", "stack");
//imageCalculator("Subtract create stack",w12,stem+"-mask.tif");
//selectWindow("Result of "+w12);
//rename("blue");
//selectWindow("blue");
//run("RGB Color");
//run("8-bit Color", "number=256");
//waitForUser("Click OK");
//run("Merge Channels...", "red=DNA-cent-LT-mask green=DNA-mask-LT-cent blue=blue create");
//waitForUser("Click OK");
//selectWindow("Composite");
//run("Stack to RGB", "slices");
//waitForUser("Click OK");
//saveAs("Tiff", detoutputdir+stem+"-Det-OL.tif");
//waitForUser("Click OK");
run("Close All");
}
}
setBatchMode(false);
run("Quit");