Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 050fda4

Browse files
committed
fix: cli-params from PR #40 : removed datatype because it was giving an error, also made params be part of the inputnode rather than workflow generator function
1 parent 9dc94e7 commit 050fda4

File tree

3 files changed

+19
-49
lines changed

3 files changed

+19
-49
lines changed

dmriprep/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
help="Fixed number of eddy iterations. See "
2323
"https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide"
2424
"#A--niter",
25-
default=5)
25+
default=5, type=(int))
2626
@click.option('--slice-outlier-threshold',
2727
help="Number of allowed outlier slices per volume. "
2828
"If this is exceeded the volume is dropped from analysis. "
2929
"If an int is provided, it is treated as number of allowed "
3030
"outlier slices. If a float between 0 and 1 "
3131
"(exclusive) is provided, it is treated the fraction of "
3232
"allowed outlier slices.",
33-
default=0.02, type=(float, int))
33+
default=0.02)
3434
@click.argument('bids_dir',
3535
)
3636
@click.argument('output_dir',

dmriprep/run.py

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def run_dmriprep(dwi_file, bvec_file, bval_file,
12-
subjects_dir, working_dir, out_dir):
12+
subjects_dir, working_dir, out_dir):
1313

1414
"""
1515
Runs dmriprep for acquisitions with just one PE direction.
@@ -234,7 +234,7 @@ def rang(b):
234234
return dmri_corrected, bvec_rotated, art_file, motion_file, outlier_file
235235

236236

237-
def run_dmriprep_pe(subject_id, dwi_file, dwi_file_ap, dwi_file_pa,
237+
def run_dmriprep_pe(subject_id, dwi_file, dwi_file_AP, dwi_file_PA,
238238
bvec_file, bval_file,
239239
subjects_dir, working_dir, out_dir,
240240
eddy_niter=5, slice_outlier_threshold=0.02):
@@ -248,10 +248,10 @@ def run_dmriprep_pe(subject_id, dwi_file, dwi_file_ap, dwi_file_pa,
248248
dwi_file : str
249249
Path to dwi nifti file
250250
251-
dwi_file_ap : str
251+
dwi_file_AP : str
252252
Path to EPI nifti file (anterior-posterior)
253253
254-
dwi_file_pa : str
254+
dwi_file_PA : str
255255
Path to EPI nifti file (posterior-anterior)
256256
257257
bvec_file : str
@@ -289,43 +289,33 @@ def run_dmriprep_pe(subject_id, dwi_file, dwi_file_ap, dwi_file_pa,
289289
--------
290290
dmriprep.run.get_dmriprep_pe_workflow
291291
"""
292-
wf = get_dmriprep_pe_workflow(
293-
eddy_niter=eddy_niter,
294-
slice_outlier_threshold=slice_outlier_threshold
295-
)
292+
wf = get_dmriprep_pe_workflow()
296293
wf.base_dir = op.join(op.abspath(working_dir), subject_id)
297294

298295
inputspec = wf.get_node('inputspec')
299296
inputspec.inputs.subject_id = subject_id
300297
inputspec.inputs.dwi_file = dwi_file
301-
inputspec.inputs.dwi_file_ap = dwi_file_ap
302-
inputspec.inputs.dwi_file_pa = dwi_file_pa
298+
inputspec.inputs.dwi_file_ap = dwi_file_AP
299+
inputspec.inputs.dwi_file_pa = dwi_file_PA
303300
inputspec.inputs.bvec_file = bvec_file
304301
inputspec.inputs.bval_file = bval_file
305302
inputspec.inputs.subjects_dir = subjects_dir
306303
inputspec.inputs.out_dir = op.abspath(out_dir)
304+
inputspec.inputs.eddy_niter = eddy_niter
305+
inputspec.inputs.slice_outlier_threshold = slice_outlier_threshold
307306

308307
# write the graph (this is saved to the working dir)
309308
wf.write_graph()
310309

311310
wf.run()
312311

313312

314-
def get_dmriprep_pe_workflow(eddy_niter=5, slice_outlier_threshold=0.02):
313+
def get_dmriprep_pe_workflow():
315314
"""Return the dmriprep (phase encoded) nipype workflow
316315
317316
Parameters
318317
----------
319-
eddy_niter : int, default=5
320-
Fixed number of eddy iterations. See
321-
https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide#A--niter
322318
323-
slice_outlier_threshold: int or float
324-
Number of allowed outlier slices per volume. If this is exceeded the
325-
volume is dropped from analysis. If `slice_outlier_threshold` is an
326-
int, it is treated as number of allowed outlier slices. If
327-
`slice_outlier_threshold` is a float between 0 and 1 (exclusive), it is
328-
treated the fraction of allowed outlier slices.
329319
330320
Returns
331321
-------
@@ -353,24 +343,11 @@ def get_dmriprep_pe_workflow(eddy_niter=5, slice_outlier_threshold=0.02):
353343
'bvec_file',
354344
'bval_file',
355345
'subjects_dir',
356-
'out_dir'
346+
'out_dir',
347+
'eddy_niter',
348+
'slice_outlier_threshold'
357349
]), name="inputspec")
358350

359-
# inputspec.inputs.subject_id = subject_id
360-
# inputspec.inputs.dwi_file = dwi_file
361-
# inputspec.inputs.dwi_file_ap = dwi_file_ap
362-
# inputspec.inputs.dwi_file_pa = dwi_file_pa
363-
# inputspec.inputs.bvec_file = bvec_file
364-
# inputspec.inputs.bval_file = bval_file
365-
# inputspec.inputs.subjects_dir = subjects_dir
366-
# inputspec.inputs.out_dir = op.abspath(out_dir)
367-
#
368-
# # some bookkeeping (getting the filename, getting the BIDS subject name)
369-
# dwi_fname = op.split(dwi_file)[1].split(".nii.gz")[0]
370-
# bids_sub_name = subject_id
371-
# assert bids_sub_name.startswith("sub-")
372-
373-
# Grab the preprocessing all_fsl_pipeline
374351
# AK: watch out, other datasets might be encoded LR
375352
epi_ap = {'echospacing': 66.5e-3, 'enc_dir': 'y-'}
376353
epi_pa = {'echospacing': 66.5e-3, 'enc_dir': 'y'}
@@ -379,17 +356,13 @@ def get_dmriprep_pe_workflow(eddy_niter=5, slice_outlier_threshold=0.02):
379356
# initialize an overall workflow
380357
wf = pe.Workflow(name="dmriprep")
381358

382-
# prep.inputs.inputnode.in_file = dwi_file
383-
# prep.inputs.inputnode.in_bvec = bvec_file
384-
# prep.inputs.inputnode.in_bval = bval_file
385-
386359
wf.connect(inputspec, 'dwi_file', prep, 'inputnode.in_file')
387360
wf.connect(inputspec, 'bvec_file', prep, 'inputnode.in_bvec')
388361
wf.connect(inputspec, 'bval_file', prep, 'inputnode.in_bval')
362+
wf.connect(inputspec, 'eddy_niter', prep, 'fsl_eddy.niter')
389363

390364
eddy = prep.get_node('fsl_eddy')
391365
eddy.inputs.repol = True
392-
eddy.inputs.niter = eddy_niter
393366

394367
def id_outliers_fn(outlier_report, threshold, dwi_file):
395368
"""Get list of scans that exceed threshold for number of outliers
@@ -453,9 +426,9 @@ def num_outliers(scan, outliers):
453426
name="id_outliers_node"
454427
)
455428

456-
id_outliers_node.inputs.threshold = slice_outlier_threshold
457429
wf.connect(inputspec, 'dwi_file', id_outliers_node, 'dwi_file')
458-
# id_outliers_node.inputs.dwi_file = dwi_file
430+
wf.connect(inputspec, 'slice_outlier_threshold', id_outliers_node, 'threshold')
431+
459432
wf.connect(prep, "fsl_eddy.out_outlier_report",
460433
id_outliers_node, "outlier_report")
461434

@@ -590,7 +563,6 @@ def apply_transform_to_bvecs_fn(bvec_file, reg_mat_file):
590563
wf.connect(id_outliers_node, "drop_scans", drop_outliers_node, "drop_scans")
591564
wf.connect(voltransform, "transformed_file", drop_outliers_node, "in_file")
592565
wf.connect(inputspec, 'bval_file', drop_outliers_node, 'in_bval')
593-
# drop_outliers_node.inputs.in_bval = bval_file
594566
wf.connect(apply_transform_to_bvecs_node, "out_bvec", drop_outliers_node, "in_bvec")
595567

596568
# lets compute the tensor on both the dropped volume scan
@@ -604,7 +576,6 @@ def apply_transform_to_bvecs_fn(bvec_file, reg_mat_file):
604576
wf.connect(voltransform, 'transformed_file', get_tensor_eddy, "in_file")
605577
wf.connect(apply_transform_to_bvecs_node, 'out_bvec', get_tensor_eddy, "in_bvec")
606578
wf.connect(inputspec, 'bval_file', get_tensor_eddy, 'in_bval')
607-
# get_tensor_eddy.inputs.in_bval = bval_file
608579

609580
# AK: What is this, some vestigal node from a previous workflow?
610581
# I'm not sure why the tensor gets scaled. but i guess lets scale it for
@@ -671,8 +642,6 @@ def binarize_aparc(aparc_aseg):
671642
datasink = pe.Node(nio.DataSink(), name="sinker")
672643
wf.connect(inputspec, 'out_dir', datasink, 'base_directory')
673644
wf.connect(inputspec, 'subject_id', datasink, 'container')
674-
# datasink.inputs.base_directory = op.join(op.abspath(out_dir), subject_id)
675-
# datasink.inputs.container = subject_id
676645

677646
wf.connect(drop_outliers_node, "out_file", datasink, "dmriprep.dwi.@thinned")
678647
wf.connect(drop_outliers_node, "out_bval", datasink, "dmriprep.dwi.@bval_thinned")

docker/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ dependencies:
1010
- pip:
1111
- "--editable=git+https://github.com/nipy/nipype@fa0a101fec2d010dcb68910000f66d7c64e5d03e#egg=nipype"
1212
- bids
13+
- duecredit

0 commit comments

Comments
 (0)