-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path06_run_mriqc.py
78 lines (63 loc) · 2.02 KB
/
06_run_mriqc.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
# Environment ------------------------------------------------------------------
import os
import click
from pathlib import Path
# Paremeters are read from the config.py file
import config
# Main -------------------------------------------------------------------------
def _uniq(input):
"""Search for unique subject ID"""
output = []
for x in input:
if x not in output:
output.append(x)
return output
def _parse_range(str_):
"""
Parse a string like numeric index set to a list
INPUT : "0-2,5,9-11"
OUTPUT: [0, 1, 2, 5, 9, 10, 11]
"""
list_ = set()
for chunk in str_.split(','):
unit = chunk.split('-')
list_.update(range(int(unit[0]), int(unit[-1]) + 1))
return sorted(list_)
@click.command()
@click.argument('range')
@click.option('--nthreads', default=8, help='Number of Threads', show_default=True)
@click.option('--dryrun', is_flag=True, help='print cmd only')
def main(range, nthreads, dryrun):
"""Run MRIQC"""
bids_dir = Path(config.outdir, 'BIDS_out')
output_dir = Path(config.outdir, 'derivatives', 'mriqc')
work_dir = Path(config.outdir, 'Work')
subjlist = _parse_range(range)
tmplist = []
# check if output directory exists; if not, make it
if not output_dir.is_dir():
output_dir.mkdir(parents=True, exist_ok=True)
for i in config.datasets:
tmplist.append(i[1])
labels = _uniq(tmplist)
for subj in subjlist:
label = labels[subj]
cmd = f'singularity run --cleanenv \
-B {bids_dir}:/data:ro \
-B {output_dir}:/out \
-B {work_dir}:/work \
{config.mriqc} \
/data \
/out \
participant \
--participant-label sub-{label} \
--n_proc {nthreads} \
--no-sub \
-w /work'
if dryrun:
print(cmd)
else:
os.system(cmd)
# Terminal Function ------------------------------------------------------------
if __name__ == '__main__':
main()