-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
214 lines (174 loc) · 6.25 KB
/
Copy pathSConstruct
File metadata and controls
214 lines (174 loc) · 6.25 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## Copyright 2014-2017 David Miguel Susano Pinto
##
## Copying and distribution of this file, with or without modification,
## are permitted in any medium without royalty provided the copyright
## notice and this notice are preserved. This file is offered as-is,
## without any warranty.
import os.path
import subprocess
import json
import hashlib
env = Environment()
vars = Variables()
vars.Add('OCTAVE', default='octave',
help='The Octave interpreter')
vars.Add('IMAGEJ_PLUGINSDIR', default='/usr/share/imagej/plugins/',
help='Value for ImageJ plugins.dir')
vars.Update(env)
Help(vars.GenerateHelpText(env))
AddOption(
"--verbose",
dest = "verbose",
action = "store_true",
default = False,
help = "Print LaTeX and BibTeX output."
)
if not env.GetOption("verbose"):
env.AppendUnique(PDFLATEXFLAGS = "-interaction=batchmode")
env.AppendUnique(PDFTEXFLAGS = "-interaction=batchmode")
env.AppendUnique(TEXFLAGS = "-interaction=batchmode")
env.AppendUnique(LATEXFLAGS = "-interaction=batchmode")
env.AppendUnique(BIBTEXFLAGS = "--terse") # some ports of BibTeX may use --quiet instead
## Simple Builder to call Octave scripts. Note that the targets are
## all in a single command.
def octave_script(env, script, source, target, args=[]):
script = env.File(script)
octave_path = env.Dir('lib-octave')
c = env.Command(target, source, SCRIPT=script, OCTAVE_PATH=octave_path,
action='$OCTAVE -W --quiet --path $OCTAVE_PATH $SCRIPT $SOURCE $TARGETS')
env.Depends(c, [script])
return c
def octave_with_imagej(env, script, source, target, args=[]):
script = env.File(script)
octave_path = env.Dir('lib-octave')
c = env.Command(target, source, SCRIPT=script, OCTAVE_PATH=octave_path,
action='IMAGEJ_PLUGINSDIR=$IMAGEJ_PLUGINSDIR'
' xvfb-run $OCTAVE --quiet --path $OCTAVE_PATH'
' $SCRIPT $SOURCE $TARGETS')
env.Depends(c, [script])
return c
env.AddMethod(octave_script, "OctaveScript")
env.AddMethod(octave_with_imagej, "OctaveWithImageJ")
def path4script(fname=""):
return os.path.join("scripts", fname)
def path4data(fname=""):
return os.path.join("data", fname)
def path4result(fname=""):
return os.path.join("results", fname)
figures = [
env.OctaveScript(
script = path4script("first-frap.m"),
source = path4data("test8_R3D.dv"),
target = [path4result("first-frap-%d.png") %(i) \
for i in [20, 21, 55, 65, 75, 85]],
),
env.OctaveScript(
script = path4script("spot-distortion.m"),
source = path4data("New_L1_Sum.lsm"),
target = path4result("spot-distortion.png"),
),
env.OctaveScript(
script = path4script("confluent.m"),
source = path4data("H4 R45H_L3_Sum.lsm"),
target = path4result("confluent-hela.png"),
),
env.OctaveScript(
script = path4script("horse.m"),
source = path4data("Horse_confluent_H2B-GFP_01_08_R3D_D3D.dv"),
target = path4result("confluent-horse.png"),
),
env.OctaveScript(
script = path4script("ifrap.m"),
source = path4data("HeLa_H2B-PAGFP_01_12_R3D_D3D.dv"),
target = [path4result(f) for f in ['ifrap-pre.png', 'ifrap-post.png',
'ifrap.png']],
),
env.OctaveWithImageJ(
script = path4script("cropreg.m"),
source = path4data("HeLa_H3_1A5_01_6_R3D_D3D.dv"),
target = path4result("cropreg.png"),
),
]
env.Alias("figures", figures)
##
## manuscript (default target)
##
manuscript = env.PDF(target="kill-frap.pdf", source="kill-frap.tex")
env.Alias("kill-frap", manuscript)
Depends(manuscript, [figures])
env.Default(manuscript)
##
## "Configure" - check that we have all the required tools installed
##
def CheckProg(context, prog_name):
context.Message("Checking for %s..." % prog_name)
is_ok = context.env.WhereIs(prog_name)
context.Result(is_ok)
return is_ok
def CheckOctavePackage(context, pkg):
context.Message("Checking for Octave package %s..." % pkg)
is_ok = (subprocess.call(["octave", "-qf", "-W", "--eval", "pkg load " + pkg]) == 0)
context.Result(is_ok)
return is_ok
def CheckDataMD5(context, md5s):
context.Message("Checking for kill-frap data files integrity...")
for fpath, md5 in md5s.iteritems():
read_md5 = hashlib.md5(open(fpath, "rb").read()).hexdigest()
if md5 != read_md5:
context.Result("failed for " + fpath)
return False
else:
context.Result(True)
return True
def CheckIJinJavaClasspath(context):
context.Message("Checking if ImageJ (ij.jar) is in Octave's javaclasspath...")
cmd = 'try javaMethod ("getVersion", "ij.IJ"); catch exit (1) end'
is_ok = (subprocess.call(["octave", "-qf", "-W", "--eval", cmd]) == 0)
context.Result(is_ok)
return is_ok
conf = Configure (
env,
custom_tests = {
"CheckProg" : CheckProg,
"CheckOctavePackage" : CheckOctavePackage,
"CheckDataMD5" : CheckDataMD5,
"CheckIJinJavaClasspath" : CheckIJinJavaClasspath,
},
)
## Seriously, this should be the default. Otherwise, users won't even
## get to see the help text unless they pass the configure tests.
## And Configure(..., clean=False,help=False) does not really work,
## it just makes all configure tests fail.
if not (env.GetOption('help') or env.GetOption('clean')):
progs = {
"octave"
: "GNU Octave must be installed",
"xvfb-run"
: "xvfb-run is needed because of ImageJ",
}
for p_name, p_desc in progs.iteritems():
if not conf.CheckProg(p_name):
print p_desc
Exit(1)
for pkg in ['image', 'bioformats']:
if not conf.CheckOctavePackage(pkg):
print "Octave's %s package must be installed" % pkg
Exit(1)
with open(path4data("data-md5.json"), "r") as fid:
data_md5s = json.load(fid)
data_md5s = {path4data(fname) : md5 for fname, md5 in data_md5s.iteritems()}
for fpath in data_md5s.keys():
if not os.path.isfile(fpath):
print "Missing data file " + fpath
Exit(1)
if not conf.CheckIJinJavaClasspath():
print "ImageJ (ij.jar) is not in Octave's javaclasspath"
Exit(1)
## I guess we should also have a configure check for ImageJ commands
## because of StackReg.
if not conf.CheckDataMD5(data_md5s):
print "Found corrupt or incorrect data file"
Exit(1)
env = conf.Finish()