Skip to content

Commit 5d04fac

Browse files
authored
Merge pull request #919 from feilong/patch-1
[ENH] Allow turning off random seeding for ANTs brain extraction
2 parents 91f773d + 070b69c commit 5d04fac

File tree

5 files changed

+53
-29
lines changed

5 files changed

+53
-29
lines changed

docs/workflows.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ is presented below:
3030
output_dir='.',
3131
bids_dir='.',
3232
skull_strip_template='OASIS',
33+
skull_strip_fixed_seed=False,
3334
template='MNI152NLin2009cAsym',
3435
output_spaces=['T1w', 'fsnative',
3536
'template', 'fsaverage5'],
@@ -68,6 +69,7 @@ T1w/T2w preprocessing
6869
output_spaces=['T1w', 'fsnative',
6970
'template', 'fsaverage5'],
7071
skull_strip_template='OASIS',
72+
skull_strip_fixed_seed=False,
7173
freesurfer=True,
7274
longitudinal=False,
7375
debug=False,

fmriprep/cli/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def get_parser():
176176
g_ants.add_argument('--skull-strip-template', action='store', default='OASIS',
177177
choices=['OASIS', 'NKI'],
178178
help='select ANTs skull-stripping template (default: OASIS))')
179+
g_ants.add_argument('--skull-strip-fixed-seed', action='store_true',
180+
help='do not use a random seed for skull-stripping - will ensure '
181+
'run-to-run replicability when used with --omp-nthreads 1')
179182

180183
# Fieldmap options
181184
g_fmap = parser.add_argument_group('Specific options for handling fieldmaps')
@@ -517,6 +520,7 @@ def build_workflow(opts, retval):
517520
t2s_coreg=opts.t2s_coreg,
518521
omp_nthreads=omp_nthreads,
519522
skull_strip_template=opts.skull_strip_template,
523+
skull_strip_fixed_seed=opts.skull_strip_fixed_seed,
520524
work_dir=work_dir,
521525
output_dir=output_dir,
522526
bids_dir=bids_dir,

fmriprep/workflows/anatomical.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
def init_anat_preproc_wf(skull_strip_template, output_spaces, template, debug,
5656
freesurfer, longitudinal, omp_nthreads, hires, reportlets_dir,
5757
output_dir, num_t1w,
58-
name='anat_preproc_wf'):
58+
skull_strip_fixed_seed=False, name='anat_preproc_wf'):
5959
r"""
6060
This workflow controls the anatomical preprocessing stages of FMRIPREP.
6161
@@ -119,6 +119,9 @@ def init_anat_preproc_wf(skull_strip_template, output_spaces, template, debug,
119119
Directory in which to save derivatives
120120
name : str, optional
121121
Workflow name (default: anat_preproc_wf)
122+
skull_strip_fixed_seed : bool
123+
Do not use a random seed for skull-stripping - will ensure
124+
run-to-run replicability when used with --omp-nthreads 1 (default: ``False``)
122125
123126
124127
**Inputs**
@@ -562,7 +565,8 @@ def _set_threads(in_list, maximum):
562565
return workflow
563566

564567

565-
def init_skullstrip_ants_wf(skull_strip_template, debug, omp_nthreads, name='skullstrip_ants_wf'):
568+
def init_skullstrip_ants_wf(skull_strip_template, debug, omp_nthreads,
569+
skull_strip_fixed_seed=False, name='skullstrip_ants_wf'):
566570
r"""
567571
This workflow performs skull-stripping using ANTs' ``BrainExtraction.sh``
568572
@@ -581,6 +585,9 @@ def init_skullstrip_ants_wf(skull_strip_template, debug, omp_nthreads, name='sku
581585
Enable debugging outputs
582586
omp_nthreads : int
583587
Maximum number of threads an individual process may use
588+
skull_strip_fixed_seed : bool
589+
Do not use a random seed for skull-stripping - will ensure
590+
run-to-run replicability when used with --omp-nthreads 1 (default: ``False``)
584591
585592
**Inputs**
586593
@@ -633,7 +640,7 @@ def init_skullstrip_ants_wf(skull_strip_template, debug, omp_nthreads, name='sku
633640

634641
t1_skull_strip = pe.Node(
635642
BrainExtraction(dimension=3, use_floatingpoint_precision=1, debug=debug,
636-
keep_temporary_files=1),
643+
keep_temporary_files=1, use_random_seeding=not skull_strip_fixed_seed),
637644
name='t1_skull_strip', n_procs=omp_nthreads)
638645

639646
t1_skull_strip.inputs.brain_template = brain_template

fmriprep/workflows/base.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
from .bold import init_func_preproc_wf
3434

3535

36-
def init_fmriprep_wf(subject_list, task_id, run_uuid,
36+
def init_fmriprep_wf(subject_list, task_id, run_uuid, work_dir, output_dir, bids_dir,
3737
ignore, debug, low_mem, anat_only, longitudinal, t2s_coreg,
38-
omp_nthreads, skull_strip_template, work_dir, output_dir, bids_dir,
38+
omp_nthreads, skull_strip_template, skull_strip_fixed_seed,
3939
freesurfer, output_spaces, template, medial_surface_nan, cifti_output, hires,
4040
use_bbr, bold2t1w_dof, fmap_bspline, fmap_demean, use_syn, force_syn,
4141
use_aroma, ignore_aroma_err, aroma_melodic_dim, template_out_grid):
@@ -56,6 +56,9 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
5656
wf = init_fmriprep_wf(subject_list=['fmripreptest'],
5757
task_id='',
5858
run_uuid='X',
59+
work_dir='.',
60+
output_dir='.',
61+
bids_dir='.',
5962
ignore=[],
6063
debug=False,
6164
low_mem=False,
@@ -64,9 +67,7 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
6467
t2s_coreg=False,
6568
omp_nthreads=1,
6669
skull_strip_template='OASIS',
67-
work_dir='.',
68-
output_dir='.',
69-
bids_dir='.',
70+
skull_strip_fixed_seed=False,
7071
freesurfer=True,
7172
output_spaces=['T1w', 'fsnative',
7273
'template', 'fsaverage5'],
@@ -94,6 +95,12 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
9495
Task ID of BOLD series to preprocess, or ``None`` to preprocess all
9596
run_uuid : str
9697
Unique identifier for execution instance
98+
work_dir : str
99+
Directory in which to store workflow execution state and temporary files
100+
output_dir : str
101+
Directory in which to save derivatives
102+
bids_dir : str
103+
Root directory of BIDS dataset
97104
ignore : list
98105
Preprocessing steps to skip (may include "slicetiming", "fieldmaps")
99106
debug : bool
@@ -111,12 +118,9 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
111118
Maximum number of threads an individual process may use
112119
skull_strip_template : str
113120
Name of ANTs skull-stripping template ('OASIS' or 'NKI')
114-
work_dir : str
115-
Directory in which to store workflow execution state and temporary files
116-
output_dir : str
117-
Directory in which to save derivatives
118-
bids_dir : str
119-
Root directory of BIDS dataset
121+
skull_strip_fixed_seed : bool
122+
Do not use a random seed for skull-stripping - will ensure
123+
run-to-run replicability when used with --omp-nthreads 1
120124
freesurfer : bool
121125
Enable FreeSurfer surface reconstruction (may increase runtime)
122126
output_spaces : list
@@ -176,6 +180,9 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
176180
single_subject_wf = init_single_subject_wf(subject_id=subject_id,
177181
task_id=task_id,
178182
name="single_subject_" + subject_id + "_wf",
183+
reportlets_dir=reportlets_dir,
184+
output_dir=output_dir,
185+
bids_dir=bids_dir,
179186
ignore=ignore,
180187
debug=debug,
181188
low_mem=low_mem,
@@ -184,9 +191,7 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
184191
t2s_coreg=t2s_coreg,
185192
omp_nthreads=omp_nthreads,
186193
skull_strip_template=skull_strip_template,
187-
reportlets_dir=reportlets_dir,
188-
output_dir=output_dir,
189-
bids_dir=bids_dir,
194+
skull_strip_fixed_seed=skull_strip_fixed_seed,
190195
freesurfer=freesurfer,
191196
output_spaces=output_spaces,
192197
template=template,
@@ -218,10 +223,10 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
218223
return fmriprep_wf
219224

220225

221-
def init_single_subject_wf(subject_id, task_id, name,
226+
def init_single_subject_wf(subject_id, task_id, name, reportlets_dir, output_dir, bids_dir,
222227
ignore, debug, low_mem, anat_only, longitudinal, t2s_coreg,
223-
omp_nthreads, skull_strip_template, reportlets_dir, output_dir,
224-
bids_dir, freesurfer, output_spaces, template, medial_surface_nan,
228+
omp_nthreads, skull_strip_template, skull_strip_fixed_seed,
229+
freesurfer, output_spaces, template, medial_surface_nan,
225230
cifti_output, hires, use_bbr, bold2t1w_dof, fmap_bspline, fmap_demean,
226231
use_syn, force_syn, template_out_grid,
227232
use_aroma, aroma_melodic_dim, ignore_aroma_err):
@@ -241,25 +246,26 @@ def init_single_subject_wf(subject_id, task_id, name,
241246
242247
from fmriprep.workflows.base import init_single_subject_wf
243248
wf = init_single_subject_wf(subject_id='test',
244-
name='single_subject_wf',
245249
task_id='',
246-
longitudinal=False,
247-
t2s_coreg=False,
248-
omp_nthreads=1,
249-
freesurfer=True,
250+
name='single_subject_wf',
250251
reportlets_dir='.',
251252
output_dir='.',
252253
bids_dir='.',
254+
ignore=[],
255+
debug=False,
256+
low_mem=False,
257+
anat_only=False,
258+
longitudinal=False,
259+
t2s_coreg=False,
260+
omp_nthreads=1,
253261
skull_strip_template='OASIS',
262+
skull_strip_fixed_seed=False,
263+
freesurfer=True,
254264
template='MNI152NLin2009cAsym',
255265
output_spaces=['T1w', 'fsnative',
256266
'template', 'fsaverage5'],
257267
medial_surface_nan=False,
258268
cifti_output=False,
259-
ignore=[],
260-
debug=False,
261-
low_mem=False,
262-
anat_only=False,
263269
hires=True,
264270
use_bbr=True,
265271
bold2t1w_dof=9,
@@ -297,6 +303,9 @@ def init_single_subject_wf(subject_id, task_id, name,
297303
Maximum number of threads an individual process may use
298304
skull_strip_template : str
299305
Name of ANTs skull-stripping template ('OASIS' or 'NKI')
306+
skull_strip_fixed_seed : bool
307+
Do not use a random seed for skull-stripping - will ensure
308+
run-to-run replicability when used with --omp-nthreads 1
300309
reportlets_dir : str
301310
Directory in which to save reportlets
302311
output_dir : str
@@ -423,6 +432,7 @@ def init_single_subject_wf(subject_id, task_id, name,
423432
# Preprocessing of T1w (includes registration to MNI)
424433
anat_preproc_wf = init_anat_preproc_wf(name="anat_preproc_wf",
425434
skull_strip_template=skull_strip_template,
435+
skull_strip_fixed_seed=skull_strip_fixed_seed,
426436
output_spaces=output_spaces,
427437
template=template,
428438
debug=debug,

fmriprep/workflows/tests/test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_single_subject_wf(self, _):
2222
t2s_coreg=False,
2323
omp_nthreads=1,
2424
skull_strip_template='OASIS',
25+
skull_strip_fixed_seed=False,
2526
reportlets_dir='.',
2627
output_dir='.',
2728
bids_dir='.',

0 commit comments

Comments
 (0)