-
Notifications
You must be signed in to change notification settings - Fork 2
/
BatchParseLSMMetadata.txt
71 lines (62 loc) · 1.85 KB
/
BatchParseLSMMetadata.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
// "BatchParseLSMMetadata"
//
// This macro batch processes all the lsm files in a folder
// extracting the metadata and saves an output xml file
// Requires LSM Toolbox 4.0f
// (Slightly) Adapted by Greg Jefferis from code at
// http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt
requires("1.33s");
dir = getArgument; // if we're running from the command line
if (dir=="") // interactive
dir = getDirectory("Choose a stacks directory");
//outputDir = getDirectory("Choose output directory");
// just leave the xml files next to the lsm images for now
outputDir=dir;
setBatchMode(true);
// Access to macro functions in LSM Toolbox
run("Show LSMToolbox","ext");
count = 0;
countFiles(dir);
print("Total files: "+count);
n = 0;
processFiles(dir, outputDir);
function countFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
countFiles(""+dir+list[i]);
else // only count if this is an lsm file
if(isLSMFile(list[i])) count++;
}
}
function processFiles(dir,outputDir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+dir+list[i], ""+outputDir+list[i]);
else {
if(isLSMFile(list[i])){
showProgress(n++, count);
processFile(dir,outputDir,list[i]);
}
}
}
}
function processFile(dir,outputDir,file) {
path = dir+file;
// Contstruct the output path
xmlpath=outputDir+substring(file,0,lengthOf(file)-4)+".xml";
ignorepath=outputDir+substring(file,0,lengthOf(file)-4)+".ignore";
// if it doesn't exist
if(!File.exists(xmlpath) && !File.exists(ignorepath)){
// then Parse XML metadata for that image
print("Parsing metadata for: "+file);
xml = Ext.lsmXML(path);
File.saveString(xml, xmlpath);
}
}
function isLSMFile(file){
if (endsWith(file, ".lsm") || endsWith(file,".LSM")) return true;
else return false;
}