This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdx-cwl-postprocess-output-code.py
75 lines (64 loc) · 2.38 KB
/
dx-cwl-postprocess-output-code.py
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
import os
import dxpy
import json
import yaml
import subprocess
from pprint import pprint
# TODO: potentially pull these out to common utilities
def sh(cmd, ignore_error=False):
try:
print cmd
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError as e:
if ignore_error:
return
else:
sys.exit(e.returncode)
def shell_suppress(cmd, ignore_error=False):
out = ""
try:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
if ignore_error:
pass
else:
print e.output
raise
return out
@dxpy.entry_point('main')
def main(**kwargs):
folder = open("output_folder.txt").read()
with open("job_input.json") as f:
dxinputs = json.loads(f.read())
def is_file(ivalue):
return isinstance(ivalue, dict) and ('$dnanexus_link' in ivalue and ivalue['$dnanexus_link'].startswith("file-") or 'primaryFile' in ivalue)
def is_directory(ivalue):
return isinstance(ivalue, dict) and 'class' in ivalue and ivalue['class'] == 'Directory'
def compile_input_generic(iname, ivalue):
if isinstance(ivalue, list):
for x in ivalue:
compile_input_generic(iname, x)
elif isinstance(ivalue, dict):
if is_file(ivalue):
if 'primaryFile' in ivalue:
objid = ivalue['primaryFile']['$dnanexus_link']
else:
objid = ivalue['$dnanexus_link']
sh("unset DX_WORKSPACE_ID && dx mv $DX_PROJECT_CONTEXT_ID:{} $DX_PROJECT_CONTEXT_ID:{}".format(objid, folder))
if 'secondaryFiles' in ivalue:
compile_input_generic(iname, ivalue['secondaryFiles'])
elif is_directory(ivalue):
pass
#basedir_loc = os.path.dirname(ivalue['location'])
#sh("unset DX_WORKSPACE_ID && dx mv $DX_PROJECT_CONTEXT_ID:{} $DX_PROJECT_CONTEXT_ID:{}".format(ivalue['location'], folder))
else:
for k,v in ivalue.items():
compile_input_generic(k,v)
else:
return ivalue
print("DNANEXUS INPUTS:\n")
pprint(dxinputs)
for iname, ivalue in dxinputs.items():
compile_input_generic(iname, ivalue)
return dxinputs
dxpy.run()