forked from sct-pipeline/gm-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMGM
executable file
·88 lines (76 loc) · 3.49 KB
/
WMGM
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
#!/usr/bin/env python
#
# This script is initiated by daemon_SOFTWEB_2files.py, which communicates with the data submission on NiftyWeb.
# WMGM is run without an extension.
#
# Three inputs are provided to NiftyWeb. Two are NIfTI files: an initial scan (image1) and a re-scan without
# repositioning (image2). The third input is a PDF containing protocol information. In addition, 4 parameters are
# provided (field strength, coil type, sequence, and data type). Each NiftyWeb submission is assigned an ID when it is
# added to the queue for processing.
#
# Dependency:
# - SCT's Python
#
# USAGE (normal launch through the daemon):
# ${SCT_DIR}/python/bin/python PATH_TO_DAEMON/daemon_SOFTWEB_2files.py WMGM <ID> <IMAGE1> <IMAGE2>
#
# USAGE (for debugging):
# ${SCT_DIR}/python/bin/python WMGM <ID> <IMAGE1> <IMAGE2>
#
# WMGM extracts the two NIfTI files, and calls process_data.py to process and analyze the data. WMGM then waits for
# these results files to be returned:
# ID_WMGM.txt: text file containing metric results
# ID_WMGM.zip: folder containing text file with results as well as cord and gray matter segmentations
#
# Once the results files have been generated, they are returned to the user by the daemon.
#
# Authors: Stephanie Alley, Julien Cohen-Adad
import os, sys, subprocess, time, argparse
# get path of running script
path_script = os.path.dirname(os.path.abspath(os.path.basename(__file__)))
# append path to allow import
sys.path.append(path_script)
import process_data
def get_parameters():
parser = argparse.ArgumentParser(description='Extract the two NIfTI images and submission ID, and use them to call '
'process_data.py.')
parser.add_argument('num', help='NiftyWeb ID')
parser.add_argument('image_1', help='Initial scan')
parser.add_argument('image_2', help='Re-scan')
parser.add_argument('pdf', help='File name of pdf protocol.')
parser.add_argument('-field', help='Field strength [T]', required=False)
parser.add_argument('-coil', help='Type of coil', required=False)
parser.add_argument('-sequence', help='Type of sequence', required=False)
parser.add_argument('-data', help='Name of dataset', required=False)
args = parser.parse_args()
return args
def main():
# get arguments
num = args.num
image_1 = os.path.basename(args.image_1)
image_2 = os.path.basename(args.image_2)
dir_data = os.path.abspath(os.path.dirname(args.image_1))
# Send email notification of request
#mail = 'mutt -s "Request received for {}"jcohen@polymtl.ca,f.carrasco@ucl.ac.uk < /dev/null'.format(num)
# subprocess.check_call(mail, shell=True)
os.chdir(dir_data)
# Initiate processing script
#process_data.main([image_1, image_2], None, None, num=num, create_txt_output=True)
subprocess.call(["/home/niftyweb_sct/sct/python/bin/python", "/home/niftyweb_sct/gm_challenge/process_data.py", "-i", image_1, image_2, "-n", num, "-o","{}_WMGM".format(num)])
#sys.exit(0)
# Check for output files to return to user
final_txt = os.path.join(dir_data + '/' + num + '_WMGM.txt')
final_zip = os.path.join(dir_data + '/' + num + '_WMGM.zip')
if (os.path.isfile(final_txt)) and (os.path.isfile(final_zip)):
sys.exit(0)
else:
sys.exit(1)
# done = 0
# while(done == 0):
# if (os.path.isfile(final_txt)) and (os.path.isfile(final_zip)):
# done = 1
# else:
# time.sleep(60)
if __name__ == "__main__":
args = get_parameters()
main()