-
Notifications
You must be signed in to change notification settings - Fork 0
/
bioact.txt
178 lines (151 loc) · 4.91 KB
/
bioact.txt
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
// vim: set filetype=javascript shiftwidth=2 tabstop=2 expandtab :
macro "bioact" {
// Determines how fluorescence changes over time.
//
// HOW TO USE:
// 1. Run without batch mode checked on an open stack of images
// to determine which threshold method is appropriate for your
// sample.
// 2. Run in batch mode on a project folder that contains the file
// structure produced by automated microscopy.
runBioact();
}
function runBioact() {
// Java uses '/' no matter what the operating system uses.
FS = "/";
thresholds = newArray("Default","MaxEntropy","Huang","RenyiEntropy");
wls = newArray("WL0","WL1","WL2","WL3","WL4","WL5");
max_slices = 150;
Dialog.create("Enter time info");
Dialog.addNumber("Max slices",max_slices);
Dialog.addNumber("Start time (min)",41);
Dialog.addNumber("Time step (min)",37.77778);
Dialog.addChoice("Threshold",thresholds,thresholds[0])
Dialog.addChoice("Wavelength",wls,wls[0])
Dialog.addCheckbox("Batch Mode",false);
Dialog.show();
max_slices = Dialog.getNumber();
start = Dialog.getNumber();
dt = Dialog.getNumber();
thresh = Dialog.getChoice();
wl = Dialog.getChoice();
bm = Dialog.getCheckbox();
title = "Results";
f = "["+title+"]";
if (isOpen(title))
print(f, "\\Clear");
else
run("Table...", "name="+f+" width=200 height=600");
headings = "\\Headings:position\tlocation\tslice\ttime\t"+
"area\tmeanbg\tbs.intden\trb_radius\tthreshold";
setBatchMode(bm);
print(f, headings);
if (bm) {
project_path = getDirectory("Choose a Directory");
position_dirs = getMatchingDirs(project_path,"[A-Z][0-9]+[a-z]");
for (p=0;p<position_dirs.length;p++) {
//setBatchMode(false);
name = replace(position_dirs[p],FS,"");
position = substring(name,0,lengthOf(name)-1);
location = substring(name,lengthOf(name)-1);
run("Image Sequence...", "open="+project_path+position_dirs[p]+wl
+FS+" number="+max_slices+" starting=1 increment=1 "+
"file=[.tif] sort ");
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel global");
stack_id = getImageID();
print("In folder " + name);
bioact(stack_id,position,location,max_slices);
}
} else {
bioact(getImageID(),getTitle(),"",max_slices);
}
}
function bioact(id,pos,loc,max_slices) {
getDimensions(WIDTH,HEIGHT,CHANNELS,SLICES,FRAMES);
rb_radius = 100;
rb_params = "rolling="+50+" sliding stack";
stack_dir = getDirectory("image");
selectImage(id);
// To avoid basing thresholding on first few images which may be out of
// focus.
setSlice(5);
run("Select None");
run("Gaussian Blur...", "sigma=1 stack");
run("Subtract Background...", rb_params);
run("8-bit");
run("Maximum...", "radius=3 stack");
setAutoThreshold(thresh+" dark");
run("Convert to Mask"," black");
run("Fill Holes","stack");
run("Options...", "iterations=2 count=1 black edm=Overwrite do=Nothing");
run("Dilate", "stack");
run("Options...", "iterations=1 count=1 black edm=Overwrite do=Nothing");
roiManager("reset");
print("Selection image");
for (i=0;i<nSlices;i++) {
slice = i+1;
print(" Slice " + slice);
setSlice(slice);
run("Create Selection");
List.setMeasurements;
max = List.getValue("Max");
if (max == 255) {
run("Make Inverse");
wait(500);
roiManager("Add");
}
}
selectImage(id);
close();
run("Image Sequence...", "open="+stack_dir+FS+" number="+max_slices+
" starting=1 increment=1 "+"file=[.tif] sort ");
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel global");
run("Subtract Background...", rb_params);
id = getImageID();
sels = roiManager("count");
print("Analysis image");
for (i=0;i<sels;i++) {
roiManager("Select",i);
slice = i+1;
setSlice(slice);
print(" Slice " + slice);
List.setMeasurements;
bg = List.getValue("Mean");
sd = List.getValue("StdDev");
selectImage(id);
run("Make Inverse");
List.setMeasurements;
area = List.getValue("Area");
intden = List.getValue("IntDen");
run("Select None");
bs_intden = intden - bg*area;
print(f, pos+"\t"+loc+"\t"+slice+"\t"+i*dt+start+"\t"+area+
"\t"+bg+"\t"+bs_intden+"\t"+rb_radius+"\t"+thresh);
}
if (is("Batch Mode")) {
selectImage(id);
close();
}
}
function getMatchingDirs(path,match) {
contents = getFileList(path);
n = 0;
names = newArray(contents.length);
for (i=0;i<contents.length;i++) {
if ( matches(replace(contents[i],FS,""), match) ) {
//print("Matched "+contents[i]);
names[i] = contents[i];
n++;
}
}
if (n == 0) exit("Didn't find any matches to "+match+" in "+path);
good_dirs = newArray(n);
gdi = 0;
for (i=0;i<names.length;i++) {
if ( matches(replace(names[i],FS,""), match) ) {
//print("Copying "+ names[i]);
good_dirs[gdi++] = names[i];
}
}
return good_dirs;
}