Skip to content

Commit 196f7fd

Browse files
committed
add batch processing macro and script examples
1 parent 93c4b8a commit 196f7fd

3 files changed

Lines changed: 184 additions & 49 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
3+
//define file suffix here, can be different, czi, lif, xml, etc
4+
suffix = ".tif";
5+
//define autotrace min intensity start
6+
dMinIntStart = 30000.;
7+
//minimum lenght for autotrace
8+
nMinLength = 100;
9+
10+
// Choose input directory
11+
input = getDirectory("Input directory");
12+
13+
//clear the log window
14+
print("\\Clear");
15+
16+
// Create timestamp to save log later
17+
timestamp = getTimeStamp_sec();
18+
19+
// Get file list
20+
list = getFileList(input);
21+
22+
nCount = 0;
23+
bFirst = true;
24+
25+
for (nFile = 0; nFile < list.length; nFile++)
26+
{
27+
if(endsWith(list[nFile], suffix))
28+
{
29+
basecurr = input + list[nFile];
30+
//in case you need only filename without extension somewhere later
31+
noExtFilename = substring(list[nFile], 0, lengthOf(list[nFile])-lengthOf(suffix));
32+
nCount++;
33+
if(bFirst)
34+
{
35+
run("Open 3D image", "open=[" + basecurr + "]");
36+
bFirst = false;
37+
}
38+
else
39+
{
40+
Ext.btOpenNext(basecurr);
41+
}
42+
43+
//make a folder to store things
44+
saveDir = input + toString(nCount) + "/";
45+
File.makeDirectory(saveDir);
46+
47+
//process image in BigTrace
48+
///set active channel for tracing (if multichannel)
49+
Ext.btSetActiveChannel(1);
50+
//maybe set other parameters, otherwise current stored (last used) will be used
51+
//....
52+
53+
//run auto-trace (all frames)
54+
Ext.btRunFullAutoTrace(dMinIntStart, nMinLength);
55+
//save ROIs in CSV
56+
Ext.btSaveROIs(saveDir + "rois.csv", "CSV");
57+
//obtain and save measurements
58+
Ext.btMeasureAndSave (saveDir + "Results.csv");
59+
//save straightened versions of ROIs
60+
//Ext.btStraighten(0, saveDir, "Round");
61+
//can save log file here too, after each volume, in case something goes wrong
62+
}
63+
64+
}
65+
Ext.btClose();
66+
selectWindow("Log");
67+
saveAs("Text", input + "BigTrace_IJmacro_" + timestamp + ".txt");
68+
69+
function getTimeStamp_sec()
70+
{
71+
// returns timestamp: yearmonthdayhourminutesecond
72+
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
73+
74+
TimeStamp = toString(year) + "-" + IJ.pad(month+1,2) + "-" + IJ.pad(dayOfMonth,2) + "-";
75+
TimeStamp = TimeStamp + IJ.pad(hour,2) + "-" + IJ.pad(minute,2) + "-" + IJ.pad(second,2);
76+
return TimeStamp;
77+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import ij.IJ
2+
import ij.io.DirectoryChooser
3+
import ij.text.TextWindow
4+
import ij.WindowManager
5+
import java.text.SimpleDateFormat
6+
import java.util.Date
7+
import java.io.File
8+
import bigtrace.BigTrace
9+
10+
//define file suffix here, can be different, czi, lif, xml, etc
11+
def suffix = ".tif"
12+
//define autotrace min intensity start
13+
def dMinIntStart = 30000 as double
14+
//minimum lenght for autotrace
15+
def nMinLength = 100 as int
16+
17+
// Choose input directory
18+
def dc = new DirectoryChooser("Input directory")
19+
def input = dc.getDirectory()
20+
21+
//clear the log window
22+
def logWindow = WindowManager.getWindow("Log")
23+
if (logWindow != null) {
24+
def textPanel = logWindow.getTextPanel()
25+
textPanel.clear()
26+
}
27+
// Create timestamp to save log later
28+
def sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
29+
def timestamp = sdf.format(new Date())
30+
31+
// Get file list
32+
def dir = new File(input)
33+
def list = dir.list()
34+
35+
int nCount = 0
36+
boolean bFirst = true
37+
38+
BT = new BigTrace();
39+
list.each { filename ->
40+
41+
if (filename.endsWith(suffix)) {
42+
43+
def basecurr = input + filename
44+
45+
// filename without extension
46+
def noExtFilename = filename[0..-(suffix.length()+1)]
47+
48+
nCount++
49+
50+
if (bFirst) {
51+
BT.run( basecurr )
52+
bFirst = false
53+
} else {
54+
BT.btMacro.macroOpenNext(basecurr)
55+
}
56+
//make a folder to store things
57+
def saveDir = input + nCount + File.separator
58+
new File(saveDir).mkdirs()
59+
60+
//process image in BigTrace
61+
62+
//set active channel for tracing (if multichannel)
63+
BT.btMacro.macroSetActiveChannel(1)
64+
//maybe set other parameters, otherwise current stored (last used) will be used
65+
//....
66+
67+
//run auto-trace (all frames)
68+
BT.btMacro.macroRunFullAutoTrace(dMinIntStart, nMinLength)
69+
//save ROIs in CSV
70+
BT.btMacro.macroSaveROIs(saveDir + "rois.csv", "CSV")
71+
//obtain and save measurements
72+
BT.btMacro.macroMeasureAndSave(saveDir + "Results.csv")
73+
//save straightened versions of ROIs
74+
//BT.btMacro.macroStraighten(0, saveDir, "Round")
75+
//can save log file here too, after each volume, in case something goes wrong
76+
}
77+
}
78+
BT.btMacro.macroClose()
79+
80+
//save log
81+
// Create filename
82+
def filePath = input + "BigTrace_groovy_Log_" + timestamp + ".txt"
83+
84+
// Save log to file
85+
new File(filePath).text = IJ.getLog()

0 commit comments

Comments
 (0)