forked from NIST-MNI/nist_mni_pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiplScoopFusionGrading.py
executable file
·189 lines (150 loc) · 6.16 KB
/
iplScoopFusionGrading.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @author Vladimir S. FONOV
# @date 12/10/2014
#
# Run fusion segmentation
from __future__ import print_function
import shutil
import os
import sys
import csv
import traceback
import argparse
import json
import tempfile
import re
import copy
import random
# MINC stuff
from ipl.minc_tools import mincTools,mincError
# internal funcions
from ipl.grading import *
# scoop parallel execution
from scoop import futures, shared
def parse_options():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Build fusion grading library')
parser.add_argument('--create',
help="Create new library with parameters in json format",
dest='create')
parser.add_argument('--cv',
help="Run cross-validation using existing library with parameters in json format",
dest='cv')
parser.add_argument('--cv-iter',
help="Run one iteration from cross validation, use -1 to aggregate all CVs",
type=int,
dest='cv_iter')
parser.add_argument('--grade',
help="Apply segmentation using provided library",
dest='grade')
parser.add_argument('--library',
help="Specify library",
dest='library')
parser.add_argument('--input',
help="input file, required for application of method",
dest='input')
parser.add_argument('--options',
help="Segmentation options in json format",
dest='options')
parser.add_argument('--output',
help="Output directory/file, required for application of method",
dest='output')
parser.add_argument('--work',
help="Work directory, place to store temporary files",
dest='work')
parser.add_argument('--mask',
help="Input mask",
dest='mask')
parser.add_argument('--debug',
action="store_true",
dest="debug",
default=False,
help='Print debugging information' )
parser.add_argument('--cleanup',
action="store_true",
dest="cleanup",
default=False,
help='Remove most temporary files' )
parser.add_argument('--variant_fuse',
default='fuse',
dest='variant_fuse')
parser.add_argument('--variant_reg',
default='ec',
dest='variant_reg')
parser.add_argument('--exclude',
dest='exclude',
help='exclude based on this regex pattern from the library')
options = parser.parse_args()
if options.debug:
print(repr(options))
return options
if __name__ == '__main__':
options = parse_options()
if options.create is not None and options.output is not None:
create_parameters={}
try:
with open(options.create,'r') as f:
create_parameters=json.load(f)
except :
print("Error loading configuration:{} {}".format(options.create,sys.exc_info()[0]),file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exit( 1)
try:
generate_library(create_parameters, options.output, debug=options.debug,
cleanup=options.cleanup)
except :
print("Error in library generation {}".format(sys.exc_info()[0]),file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exit(1)
elif options.cv is not None and \
options.grade is not None and \
options.output is not None:
cv_parameters={}
try:
with open(options.cv,'r') as f:
cv_parameters=json.load(f)
except :
print("Error loading configuration:{}\n{}".format(options.cv,sys.exc_info()[0]),file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exit(1)
library=load_library_info( options.grade )
grading_parameters={}
if options.options is not None:
try:
with open(options.options,'r') as f:
grading_parameters=json.load(f)
except :
print("Error loading configuration:{}\n{}".format(options.options,sys.exc_info()[0]),file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exit(1)
cv_fusion_grading(cv_parameters,
library,
options.output,
grading_parameters,
debug=options.debug,
cleanup=options.cleanup,
cv_iter=options.cv_iter)
elif options.grade is not None and options.input is not None:
library=load_library_info(options.grade)
grading_parameters={}
if options.options is not None:
try:
with open(options.options,'r') as f:
grading_parameters=json.load(f)
except :
print("Error loading configuration:{}\n{}".format(options.options,sys.exc_info()[0]),file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exit(1)
fusion_grading(options.input, library,
options.output,
input_mask=options.mask,
parameters=grading_parameters,
debug=options.debug,
fuse_variant=options.variant_fuse,
regularize_variant=options.variant_reg,
work_dir=options.work,
cleanup=options.cleanup,
exclude_re=options.exclude)
# kate: space-indent on; indent-width 4; indent-mode python;replace-tabs on;word-wrap-column 80