-
Notifications
You must be signed in to change notification settings - Fork 12
/
bb_pipeline.py
executable file
·156 lines (123 loc) · 4.44 KB
/
bb_pipeline.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
#!/bin/env python
#
# Script name: bb_pipeline.py
#
# Description: Main script. This script will call the rest of scripts.
#
# 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 re
import os
import glob
import time
import logging
import sys, argparse, os.path
import bb_logging_tool as LT
from bb_file_manager import bb_file_manager
from bb_basic_QC import bb_basic_QC
from tvb_reparcellate_pipeline import tvb_reparcellate_pipeline
from bb_structural_pipeline.bb_pipeline_struct import bb_pipeline_struct
from bb_functional_pipeline.bb_pipeline_func import bb_pipeline_func
from bb_diffusion_pipeline.bb_pipeline_diff import bb_pipeline_diff
from bb_IDP.bb_IDP import bb_IDP
from tvb_bb_QC.tvb_bb_QC import tvb_bb_QC
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write("error: %s\n" % message)
self.print_help()
sys.exit(2)
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(cli_args=None):
if cli_args == None:
parser = MyParser(description="BioBank Pipeline Manager")
parser.add_argument("subjectFolder", help="Subject Folder")
argsa = parser.parse_args()
else:
parser = MyParser(description="BioBank Pipeline Manager")
parser.add_argument("subjectFolder", help="Subject Folder")
argsa = parser.parse_args(cli_args)
subject = argsa.subjectFolder
subject = subject.strip()
if subject[-1] == "/":
subject = subject[0 : len(subject) - 1]
logger = LT.initLogging(__file__, subject)
REPARCELLATE=os.environ['REPARCELLATE']
PARC_NAME=os.environ['PARC_NAME']
if REPARCELLATE=="true":
tvb_reparcellate_pipeline(subject, "none", PARC_NAME)
if REPARCELLATE=="false":
logger.info("Running file manager")
fileConfig = bb_file_manager(subject)
logger.info("File configuration before QC: " + str(fileConfig))
fileConfig = bb_basic_QC(subject, fileConfig)
logger.info("File configuration after running file manager: " + str(fileConfig))
# runTopup ==> Having fieldmap
if not (
(("AP" in fileConfig) and (fileConfig["AP"] != ""))
and (("PA" in fileConfig) and (fileConfig["PA"] != ""))
):
logger.warn("There is no proper AP/PA data. Thus, TOPUP will not be run")
runTopup = False
print("NO TOPUP")
else:
runTopup = True
# set for now
# runTopup = True
# Default value for job id. SGE does not wait for a job with this id.
jobSTEP1 = "-1"
jobSTEP2 = "-1"
jobSTEP3 = "-1"
jobSTEP4 = "-1"
jobSTEP5 = "-1"
# jobSTEP1 = bb_pipeline_struct(subject, runTopup, fileConfig)
bb_pipeline_struct(subject, runTopup, fileConfig)
#handle cases: when jobstep1 would typically trigger the following
if isinstance(jobSTEP1, int):
if jobSTEP1 == -1:
print(
"This subject could not be run. Please check the logs for more information."
)
return -1
if jobSTEP1[-3:] == ",-1":
jobSTEP1 = jobSTEP1[:-3]
# print(f"jobSTEP1: {jobSTEP1}")
# jobSTEP1 = int(jobSTEP1)
# if runTopup:
# jobSTEP2 = bb_pipeline_func(subject, fileConfig)
# jobSTEP3 = bb_pipeline_diff(subject, fileConfig)
# jobSTEP4 = bb_IDP(
# subject, fileConfig
# )
# jobSTEP5 = tvb_bb_QC(
# subject,
# fileConfig
# )
bb_pipeline_func(subject, fileConfig)
bb_pipeline_diff(subject, fileConfig)
bb_IDP(
subject, fileConfig
)
tvb_bb_QC(
subject,
fileConfig
)
LT.finishLogging(logger)
# return jobSTEP5
if __name__ == "__main__":
main()