-
Notifications
You must be signed in to change notification settings - Fork 2
/
_DKR_Batch_ROI_combining.ijm
135 lines (105 loc) · 3.21 KB
/
_DKR_Batch_ROI_combining.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
//created by Dan Rozelle 20140110
//requires several folders:
//
macro "go"{
if(nImages>0) exit ("close all images before proceeding");
if(isOpen("Results")){
selectWindow("Results");
run("Close");
}
if(isOpen("Log")){
selectWindow("Log");
run("Close");
}
//vars
setBatchMode(false);
//run("Monitor Memory...");
/**********************************************************/
//create dialog box
Dialog.create("Configure");
Dialog.addMessage("Select the folder Cropped Cells")
Dialog.addString("Filter","tif");
Dialog.show();
/**********************************************************/
//gather inputs
filter=Dialog.getString();
/**********************************************************/
//select directories and filter image list
dir1 = getDirectory("Choose source directory");
if (dir1=="")
exit("No directory available");
parent = File.getParent(dir1);
AVG_ROIs_folder = parent+File.separator+"5-AVG_ROIs"+File.separator;
single_cell_ROIs_folder = parent+File.separator+"4-single_cell_ROIs"+File.separator;
dir2 = parent+File.separator+"6-combined_ROIs"+File.separator;
File.makeDirectory(dir2);
if (!File.exists(dir2))
exit("Unable to create directory");
if(filter == ""){
list = getFileList(dir1);
}
else{
//get a list of all the files in this folder
preList = getFileList(dir1);
size=0;
//count each '*filter*' files
for(place=0;place<preList.length;place++){
if(endsWith(preList[place],filter)){
size++;
}
}
//create a new array and populate with filtered images
list=newArray(size);
position=0;
for(place=0;place<preList.length;place++){
if(endsWith(preList[place],filter)){
list[position]=preList[place];
position++;
}
}
}
/**********************************************************/
//Increment through each image
for(i=0; i<list.length; i++) {
//open a two color image in separate channel stacks
if(filter != 'tif'){
run("Bio-Formats Importer", "open="+dir1+list[i]+" view=Hyperstack stack_order=XYCZT");
}
else{
open(dir1+list[i]);
}
name = list[i];
print(name);
//insert batch functions here
basename = replace(name,".tif","");
//combine all individual AVG ROIs into a single one
roiManager("Open", AVG_ROIs_folder+basename+".zip");
roiManager("Deselect");
roiManager("Combine");
roiManager("Deselect");
roiManager("Delete");
roiManager("Add");
roiManager("Select", 0);
roiManager("Rename", "all AVGs");
//create a new ROI from the non-AVG cytoplasm
roiManager("Open", single_cell_ROIs_folder+basename+".zip");
roiManager("Select", 1);
roiManager("Rename", "cytoplasm");
roiManager("Select", newArray(0,1));
roiManager("XOR");
roiManager("Deselect");
roiManager("Add");
roiManager("Select", 2);
roiManager("Rename", "non_AVG_cytoplasm");
//save the new combined ROIs
roiManager("Deselect");
roiManager("Save", dir2+basename+".zip");
//measure all channels for each ROI
run("Set Measurements...", "area mean standard min shape integrated display redirect=None decimal=3");
roiManager("Multi Measure append");
//close remaining windows and reset ROIManager
roiManager("Reset");
while (nImages >0) close();
}
print('done');
}