-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenMetadataFile
executable file
·84 lines (64 loc) · 2.79 KB
/
genMetadataFile
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
#!/usr/bin/env python3
import argparse
import flywheel
import fwgearutils
import json
import os
import pyjq
import subprocess
import sys
from flywheel_gear_toolkit import GearToolkitContext # GearToolkitContext object allows metadata method
CmdName = os.path.basename(sys.argv[0])
ap = argparse.ArgumentParser()
ap.add_argument('-a', '--atlas', default=None, action='store', help='Atlas name')
ap.add_argument('-c', '--config-file', default=None, action='store', help='Config json file to use instead of default config.json')
ap.add_argument('-i', '--id-string', default=None, action='store', help='IdString: 7_anat_T1w-trimmed')
ap.add_argument('-n', '--no-op', default=False, action='store_true', help='no-op')
ap.add_argument('-o', '--output-dir', default=None, action='store', help='Directory to copy the Ashs output file to')
ap.add_argument('-t', '--tags', default=None, action='store', help='comma separated list of tags to add to the files')
ap.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose')
ap.add_argument('ashsoutput', nargs='+', type=str, default=None, help='Files copy to output and add to .metadata.json')
args = ap.parse_args()
fw = fwgearutils.getFW(args, Root=True)
if (not fw):
print("{} : unable to initialize flywheel object".format(CmdName), file=sys.stderr)
sys.exit(1)
if (args.config_file):
ConfigJsonFile = args.config_file
else:
ConfigJsonFile='config.json'
#Modality = pyjq.all('first(..|.modality?|select(.!=null))', ConfigJson)
#Classification = pyjq.all('first(..|.classification?|select(.!=null))', ConfigJson)
IdString=args.id_string
Atlas=args.atlas
if (args.output_dir):
OutputDir=args.output_dir
else:
OutputDir="/flywheel/v0/output"
if (args.tags):
TagArgs="-t {}".format(args.tags)
else:
TagArgs=""
with GearToolkitContext(config_path=ConfigJsonFile) as context:
for File in args.ashsoutput:
SubProcessCmd = "./copyFile2Output -a {} -c {} -i {} -o {} {} {}".format(
Atlas
, ConfigJsonFile
, IdString
, OutputDir
, TagArgs
, File
)
if (args.verbose):
print(CmdName + ": " + SubProcessCmd, file=sys.stderr)
OutputJsonString = subprocess.getoutput(SubProcessCmd)
if (args.verbose):
print(OutputJsonString, file=sys.stderr)
OutputJson = json.loads(OutputJsonString)
OutputFilename = pyjq.all('.OutputFilename', OutputJson)[0]
Metadata = pyjq.all('.Metadata', OutputJson)[0]
if (Metadata):
if (args.verbose):
print("Filename = '{}', Metadata = '{}'".format(OutputFilename, Metadata), file=sys.stderr)
if (not args.no_op):
context.update_file_metadata(OutputFilename, **Metadata)