Skip to content

Commit 363a84c

Browse files
committed
enh: add a CLI argument for modality
1 parent f4e1de8 commit 363a84c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

nirodents/cli/brainextraction.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def get_parser():
2424
help="Number of CPUs available for multithreading processes.")
2525
parser.add_argument("--nprocs", action="store", type=int, default=cpu_count(),
2626
help="Number of processes that can be run in parallel.")
27+
parser.add_argument(
28+
"-m",
29+
"--mri-scheme",
30+
action="store",
31+
type=str,
32+
default="T2w",
33+
choices=("T2w", "T1w"),
34+
help="select a particular MRI scheme"
35+
)
2736
parser.add_argument(
2837
"-w",
2938
"--work-dir",
@@ -49,8 +58,9 @@ def main():
4958
opts = get_parser().parse_args()
5059
be = init_rodent_brain_extraction_wf(
5160
in_template=opts.template,
61+
bids_suffix=opts.mri_scheme,
5262
omp_nthreads=opts.omp_nthreads,
53-
debug=opts.debug
63+
debug=opts.debug,
5464
)
5565
be.base_dir = opts.work_dir
5666
be.inputs.inputnode.in_files = opts.input_image

nirodents/workflows/brainextraction.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ def init_rodent_brain_extraction_wf(
3737
final_normalization_quality='precise',
3838
in_template='WHS',
3939
init_normalization_quality='3stage',
40-
modality='T2w',
4140
mem_gb=3.0,
4241
name='rodent_brain_extraction_wf',
4342
omp_nthreads=None,
44-
tpl_suffix='T2star',
4543
template_spec=None,
4644
use_float=True,
4745
):
@@ -63,7 +61,7 @@ def init_rodent_brain_extraction_wf(
6361
name='inputnode')
6462

6563
# Find images in templateFlow
66-
tpl_target_path = get_template(in_template, resolution=debug + 1, suffix=tpl_suffix)
64+
tpl_target_path = get_template(in_template, resolution=debug + 1, suffix="T2star" if bids_suffix == "T2w" else "T1w")
6765
tpl_regmask_path = get_template(in_template, resolution=debug + 1, atlas='v3', desc='brain', suffix='mask')
6866
if tpl_regmask_path:
6967
inputnode.inputs.in_mask = str(tpl_regmask_path)
@@ -125,7 +123,7 @@ def init_rodent_brain_extraction_wf(
125123
interpolation='Linear', invert_transform_flags=True), name='warp_mask')
126124

127125
# Set up initial spatial normalization
128-
init_settings_file = f'data/brainextraction_{init_normalization_quality}_{modality}.json'
126+
init_settings_file = f'data/brainextraction_{init_normalization_quality}_{bids_suffix}.json'
129127
init_norm = pe.Node(Registration(from_file=pkgr_fn(
130128
'nirodents', init_settings_file)),
131129
name='init_norm',
@@ -163,7 +161,7 @@ def init_rodent_brain_extraction_wf(
163161
skullstrip_tpl.inputs.in_file = tpl_target_path
164162

165163
# Normalise skull-stripped image to brain template
166-
final_settings_file = f'data/brainextraction_{final_normalization_quality}_{modality}.json'
164+
final_settings_file = f'data/brainextraction_{final_normalization_quality}_{bids_suffix}.json'
167165
final_norm = pe.Node(Registration(from_file=pkgr_fn(
168166
'nirodents', final_settings_file)),
169167
name='final_norm',
@@ -194,7 +192,7 @@ def init_rodent_brain_extraction_wf(
194192

195193
sinker = pe.Node(DataSink(), name='sinker')
196194

197-
if modality.lower() == 't2w':
195+
if bids_suffix.lower() == 't2w':
198196
wf.connect([
199197
# resampling, truncation, initial N4, and creation of laplacian
200198
(inputnode, trunc, [('in_files', 'op1')]),
@@ -273,7 +271,7 @@ def init_rodent_brain_extraction_wf(
273271
])
274272
return wf
275273

276-
elif modality == 'mp2rage':
274+
elif bids_suffix == 't1w':
277275
wf.connect([
278276
# resampling and creation of laplacians
279277
(inputnode, res_target, [('in_files', 'in_file')]),

0 commit comments

Comments
 (0)