Skip to content

Commit 9b8fda9

Browse files
committed
workflow xml creator and example file
1 parent 03e9895 commit 9b8fda9

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

create_workflow_xml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/python
2+
3+
# See file COPYING distributed with the xnnppx package for the copyright
4+
# and license.
5+
6+
import sys
7+
import os
8+
try:
9+
import yaml
10+
have_yaml = True
11+
except:
12+
have_yaml = False
13+
import xml.dom.minidom
14+
15+
def create_simple_element(doc, name, value):
16+
element = doc.createElement(name)
17+
element.appendChild(doc.createTextNode(value))
18+
return element
19+
20+
base_xml = """<?xml version="1.0" encoding="UTF-8"?>
21+
<Pipeline xmlns="http://nrg.wustl.edu/pipeline" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nrg.wustl.edu/pipeline ..\schema\pipeline.xsd" xmlns:fileUtils="http://www.xnat.org/java/org.nrg.imagingtools.utils.FileUtils">
22+
</Pipeline>
23+
"""
24+
25+
progname = os.path.basename(sys.argv.pop(0))
26+
27+
if len(sys.argv) == 0 or len(sys.argv) > 2:
28+
print
29+
print 'usage: %s <source file> [output file]' % progname
30+
print
31+
print 'source file may be python or YAML (if available)'
32+
print
33+
sys.exit(1)
34+
35+
in_fname = sys.argv.pop(0)
36+
37+
try:
38+
data = open(in_fname).read()
39+
except IOError, data:
40+
sys.stderr.write('%s: %s\n' % (progname, str(data)))
41+
sys.exit(1)
42+
43+
try:
44+
info = eval(data)
45+
except SyntaxError:
46+
if have_yaml:
47+
try:
48+
info = yaml.load(data)
49+
except yaml.scanner.ScannerError:
50+
sys.stderr.write("%s: couldn't interpret data in %s\n" % (progname, in_fname))
51+
sys.exit(1)
52+
else:
53+
sys.stderr.write("%s: couldn't interpret data in %s\n" % (progname, in_fname))
54+
sys.exit(1)
55+
56+
doc = xml.dom.minidom.parseString(base_xml)
57+
pn = doc.getElementsByTagName('Pipeline')[0]
58+
59+
pn.appendChild(create_simple_element(doc, 'name', info['name']))
60+
pn.appendChild(create_simple_element(doc, 'location', info['location']))
61+
pn.appendChild(create_simple_element(doc, 'description', info['description']))
62+
63+
documentation = doc.createElement('documentation')
64+
pn.appendChild(documentation)
65+
66+
if info.has_key('authors'):
67+
authors = doc.createElement('authors')
68+
for fullname in info['authors']:
69+
a = doc.createElement('author')
70+
(lastname, firstname) = fullname.split(',', 1)
71+
a.appendChild(create_simple_element(doc, 'lastname', lastname))
72+
a.appendChild(create_simple_element(doc, 'firstname', firstname))
73+
authors.appendChild(a)
74+
documentation.appendChild(authors)
75+
76+
if info.has_key('version'):
77+
documentation.appendChild(create_simple_element(doc, 'version', info['version']))
78+
79+
if info.has_key('input-parameters'):
80+
input_parameters = doc.createElement('input-parameters')
81+
for ip_d in info['input-parameters']:
82+
ip = doc.createElement('parameter')
83+
ip.appendChild(create_simple_element(doc, 'name', ip_d['name']))
84+
vals = doc.createElement('values')
85+
if ip_d['values'][0] == 's':
86+
vals.appendChild(create_simple_element(doc, 'schemalink', ip_d['values'][1]))
87+
elif ip_d['values'][0] == 'v':
88+
vals.appendChild(create_simple_element(doc, 'csv', ip_d['values'][1]))
89+
else:
90+
sys.stderr.write('%s: bad value type \"%s\"\n' % (progname, ip_d['values'][0]))
91+
sys.exit(1)
92+
ip.appendChild(vals)
93+
ip.appendChild(create_simple_element(doc, 'description', ip_d['description']))
94+
input_parameters.appendChild(ip)
95+
documentation.appendChild(input_parameters)
96+
97+
if info.has_key('appliesTo'):
98+
applies_to = doc.createElement('xnatInfo')
99+
applies_to.setAttribute('appliesTo', info['appliesTo'])
100+
pn.appendChild(applies_to)
101+
102+
parameters = doc.createElement('parameters')
103+
pn.appendChild(parameters)
104+
steps = doc.createElement('steps')
105+
pn.appendChild(steps)
106+
step = doc.createElement('step')
107+
step.setAttribute('id', '0')
108+
step.setAttribute('description', 'bogus step for validation')
109+
steps.appendChild(step)
110+
111+
if sys.argv:
112+
try:
113+
fo = open(sys.argv[0], 'w')
114+
fo.write(doc.toxml())
115+
fo.close()
116+
except IOError, data:
117+
sys.stderr.write('%s: %s\n' % (progname, str(data)))
118+
sys.exit(1)
119+
else:
120+
print doc.toxml()
121+
122+
sys.exit(0)
123+
124+
# eof

recon_all.info

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{'name': 'recon_all',
2+
'description': 'freesurfer recon-all',
3+
'location': '/home/vmuser/xnat/pipeline/catalog/candi-store',
4+
'authors': ['Haselgrove, Christian'],
5+
'version': '0.1',
6+
'appliesTo': 'xnat:mrSessionData',
7+
'input-parameters': [
8+
{'name': 'session', 'values': ('s', 'xnat:experimentData/ID'), 'description': 'Experiment ID'},
9+
{'name': 'sessionLabel', 'values': ('s', 'xnat:experimentData/label'), 'description': 'Session Label'},
10+
{'name': 'xnat_project', 'values': ('s', 'xnat:experimentData/project'), 'description': 'Project ID'}
11+
]
12+
}

0 commit comments

Comments
 (0)