-
Notifications
You must be signed in to change notification settings - Fork 12
/
bb_pipeline_func.py
executable file
·224 lines (205 loc) · 6.94 KB
/
bb_pipeline_func.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/env python
#
# Script name: bb_pipeline_func.py
#
# Description: Script with the functional pipeline.
# This script will call the rest of functional functions.
#
# Authors: Fidel Alfaro-Almagro, Stephen M. Smith & Mark Jenkinson
#
# Copyright 2017 University of Oxford
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import bb_pipeline_tools.bb_logging_tool as LT
import os.path
def bb_pipeline_func(subject, jobHold, fileConfiguration):
logger = LT.initLogging(__file__, subject)
logDir = logger.logDir
baseDir = logDir[0 : logDir.rfind("/logs/")]
jobsToWaitFor = ""
subname = subject.replace("/", "_")
st = (
# '${FSLDIR}/bin/fsl_sub -T 5 -N "bb_postprocess_struct_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_postprocess_struct_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ str(jobHold)
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_postprocess_struct "
+ subject
)
# print(st)
jobPOSTPROCESS = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 5 -N "bb_postprocess_struct_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_postprocess_struct_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ str(jobHold)
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_postprocess_struct "
+ subject,
)
# TODO: Embed the checking of the fieldmap inside the independent steps -- Every step should check if the previous one has ended.
rfMRI_nums = [k.split("_")[-1] for k in fileConfiguration.keys() if "rfMRI" in k]
print(f"FILE CONFIG IN FUNC: {fileConfiguration}")
# if ("rfMRI" in fileConfiguration) and (fileConfiguration["rfMRI"] != ""):
for i in range(len(rfMRI_nums)):
jobGEFIELDMAP = LT.runCommand(
logger,
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_STANDARD} -N "tvb_prepare_gradEchoFieldMap_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobPOSTPROCESS
+ " $$BB_BIN_DIR/bb_functional_pipeline/tvb_prepare_gradEchoFieldMap "
+ subject
)
jobPREPARE_R = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 15 -N "bb_prepare_rfMRI_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_prepare_rfMRI_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobGEFIELDMAP
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_prepare_rfMRI "
+ subject
+ f" {rfMRI_nums[i]}",
)
jobFEAT_R = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 1200 -N "bb_feat_rfMRI_ns_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_feat_rfMRI_ns_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobPREPARE_R
+ " feat "
+ baseDir
#
+ f"/fMRI/rfMRI_{i}.fsf " + subject,
)
jobFIX = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 175 -N "bb_fix_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MAX_MEM} -N "bb_fix_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobFEAT_R
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_fix "
+ subject
+ f" {rfMRI_nums[i]}",
)
### compute FC using parcellation
jobFC = LT.runCommand(
logger,
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_FC_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobFIX
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_FC "
+ subject
+ f" {rfMRI_nums[i]}",
)
### don't generate group-ICA RSNs
# jobDR = LT.runCommand(
# logger,
##'${FSLDIR}/bin/fsl_sub -T 120 -N "bb_ICA_dr_'
#'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_ICA_dr_'
# + subname
# + '" -l '
# + logDir
# + " -j "
# + jobFIX
# + " $BB_BIN_DIR/bb_functional_pipeline/bb_ICA_dual_regression "
# + subject,
# )
jobCLEAN = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 5 -N "bb_rfMRI_clean_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_rfMRI_clean_'
+ subname
+ '" -l '
+ logDir
+ " -j "
# + jobDR
+ jobFC
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_clean_fix_logs "
+ subject
+ f" {rfMRI_nums[i]}",
)
jobsToWaitFor = jobCLEAN
else:
logger.error(
"There is no rFMRI info. Thus, the Resting State part will not be run"
)
if jobsToWaitFor != "":
jobsToWaitFor += ","
tfMRI_nums = [
k.split("_")[-1]
for k in fileConfiguration.keys()
if "tfMRI" in k and k != "tfMRI_SBREF"
]
# if ("rfMRI" in fileConfiguration) and (fileConfiguration["rfMRI"] != ""):
for i in range(len(tfMRI_nums)):
# if ("tfMRI" in fileConfiguration) and (fileConfiguration["tfMRI"] != ""):
jobPREPARE_T = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 15 -N "bb_prepare_tfMRI_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_prepare_tfMRI_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobPOSTPROCESS
+ " $BB_BIN_DIR/bb_functional_pipeline/bb_prepare_tfMRI "
+ subject
+ f" {rfMRI_nums[i]}",
)
jobFEAT_T = LT.runCommand(
logger,
#'${FSLDIR}/bin/fsl_sub -T 400 -N "bb_feat_tfMRI_'
'${FSLDIR}/bin/fsl_sub -q ${QUEUE_MORE_MEM} -N "bb_feat_tfMRI_'
+ subname
+ '" -l '
+ logDir
+ " -j "
+ jobPREPARE_T
+ " feat "
+ baseDir
+ f"/fMRI/tfMRI_{i}.fsf",
)
if jobsToWaitFor != "":
# jobsToWaitFor = jobsToWaitFor + "," + jobFEAT_T
jobsToWaitFor += f",{jobFEAT_T}"
else:
jobsToWaitFor = jobFEAT_T
else:
logger.error(
"There is no tFMRI info. Thus, the Task Functional part will not be run"
)
if jobsToWaitFor == "":
jobsToWaitFor = "-1"
print("SUBMITTED FUNCTIONAL")
return jobsToWaitFor