-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmp_trk_reprocess.py
executable file
·167 lines (122 loc) · 4.8 KB
/
cmp_trk_reprocess.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
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
#!/usr/bin/env python
Gstr_synopsis = """
NAME
cmp_trk_reprocess.py
SYNPOSIS
cmp_trk_reprocess.py --trk <a_trkFile>
ARGS
a_trkFile trk format file to reprocess in the
connectivity pipeline.
DESCRIPTION
'cmp_trk_reprocess.py' re-runs an already completed
connectivity analysis using the passed <a_trkFile> to
process connectivity.
It assumes by design that the FreeSurfer recon has been
completed, and merely runs the final stages of the pipeline
generating a new connectome pickle object.
New cff files are created and renamed explicitly to match
the <a_trkFile> name.
AUTHORS
Rudolph Pienaar
Children's Hospital Boston, 2011
HISTORY
03 November 2011
o Initial design and coding based off 'connectome_web.py'
"""
import cmp,cmp.connectome,cmp.gui,cmp.configuration,cmp.pipeline,cmp.logme
import sys
import os
import shutil, glob
from optparse import OptionParser
from _common import systemMisc as sM
def parseCommandLine(conf):
"""Setup and parse command-line options"""
parser = OptionParser(usage="%prog [options]")
parser.add_option("-p", "--projectName",
dest="projectName",
help="Project name")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose")
parser.add_option("-t", "--trkFile",
dest="trkFile",
help="t file")
parser.add_option("--skipCompletedStages",
dest="skipCompletedStages",
action="store_true",
help="Skip previously completed stages.")
parser.add_option("--writePickle",
dest="writePickle",
help="Filename to write pickle for use with CMT GUI. Exit after writing pickle file.")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.error("Wrong number of arguments")
# Parse command-line options
if options.trkFile == None:
parser.error('You must specify a "--trkFile"')
if options.projectName:
conf.project_name = options.projectName
else:
conf.project_name = 'cmt_trk_reprocess'
if options.skipCompletedStages:
conf.skip_completed_stages = True
# This must be the last step, write the configuration object
# out to a pickle file for use in the CMT GUI
if options.writePickle:
conf.save_state(os.path.abspath(options.writePickle))
return options
def prepForExecution(conf, options):
"""Prepare the files for execution of the cmp pipeline"""
# First, setup the pipeline status so we can determine the inputs
cmp.connectome.setup_pipeline_status(conf)
def main():
"""Main entrypoint for program"""
# Create configuration object (the GUI object
# is subclassed from PipelineConfiguration and
# we use this so we can serialize it as a pickle
# if we want to)
conf = cmp.gui.CMPGUI()
# Default Options
conf.freesurfer_home = os.environ['FREESURFER_HOME']
conf.fsl_home = os.environ['FSLDIR']
conf.dtk_matrices = os.environ['DSI_PATH']
conf.dtk_home = os.path.dirname(conf.dtk_matrices) # DTK home is one up from the matrices
conf.subject_raw_glob_diffusion = '*.dcm'
conf.subject_raw_glob_T1 = '*.dcm'
conf.subject_raw_glob_T2 = '*.dcm'
conf.do_convert_T2 = False
conf.diffusion_imaging_model = "DTI"
conf.streamline_param = ''
# Only execute the final connectome stages
conf.active_dicomconverter = False
conf.active_registration = False
conf.active_segmentation = False
conf.active_parcellation = False
conf.active_applyregistration = False
conf.active_reconstruction = False
conf.active_tractography = False
conf.active_fiberfilter = False
conf.active_connectome = True
conf.active_statistics = True
conf.active_cffconverter = True
conf.skip_completed_stages = False
# Setup and parse command-line options
options = parseCommandLine(conf)
# XXX: These are hardcoded for now until I figure out how they
# should be set
conf.creator = 'Neuroimaging Web Pipeline'
conf.publisher = 'CHB'
conf.legalnotice = 'institution-specific'
conf.email = 'default@default.edu'
# If writing pickle, return
if options.writePickle:
return
# Prepare the directory structure for execution
prepForExecution(conf, options)
# Before running, reset the pipeline status because it will
# get created in mapit()
conf.pipeline_status = cmp.pipeline_status.PipelineStatus()
# Execute the 'cmp' pipeline!
print "About to execute!"
cmp.connectome.mapit(conf)
if __name__ == '__main__':
main()