Skip to content

Commit 11670a6

Browse files
josephmjeoesteban
authored andcommitted
joining gradtable and skullstrip
1 parent db804f9 commit 11670a6

File tree

6 files changed

+491
-30
lines changed

6 files changed

+491
-30
lines changed

dmriprep/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Settings."""
44

5+
DEFAULT_MEMORY_MIN_GB = 0.01
56
NONSTANDARD_REFERENCES = ['anat', 'T1w', 'dwi', 'fsnative']

dmriprep/config/reports-spec.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ sections:
2626
caption: Surfaces (white and pial) reconstructed with FreeSurfer (<code>recon-all</code>)
2727
overlaid on the participant's T1w template.
2828
subtitle: Surface reconstruction
29+
- name: Diffusion
30+
ordering: session, acq, run
31+
reportlets:
32+
- bids: {datatype: dwi, desc: summary, suffix: dwi}
33+
- bids: {datatype: dwi, desc: validation, suffix: dwi}
34+
- bids: {datatype: dwi, suffix: 'dwi'}
35+
caption: Brain mask calculated on the dwi signal (red contour).
36+
subtitle: Brain mask
2937
- name: About
3038
reportlets:
3139
- bids: {datatype: anat, desc: about, suffix: T1w}

dmriprep/workflows/base.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..interfaces.reports import SubjectSummary, AboutSummary
3030
from ..utils.bids import collect_data
3131
from ..__about__ import __version__
32-
# from .dwi import init_dwi_preproc_wf
32+
from .dwi import init_dwi_preproc_wf
3333

3434

3535
def init_dmriprep_wf(
@@ -435,35 +435,20 @@ def init_single_subject_wf(
435435
if anat_only:
436436
return workflow
437437

438-
# for dwi_file in subject_data['dwi']:
439-
# dwi_preproc_wf = init_dwi_preproc_wf(
440-
# aroma_melodic_dim=aroma_melodic_dim,
441-
# bold2t1w_dof=bold2t1w_dof,
442-
# bold_file=bold_file,
443-
# cifti_output=cifti_output,
444-
# debug=debug,
445-
# dummy_scans=dummy_scans,
446-
# err_on_aroma_warn=err_on_aroma_warn,
447-
# fmap_bspline=fmap_bspline,
448-
# fmap_demean=fmap_demean,
449-
# force_syn=force_syn,
450-
# freesurfer=freesurfer,
451-
# ignore=ignore,
452-
# layout=layout,
453-
# low_mem=low_mem,
454-
# medial_surface_nan=medial_surface_nan,
455-
# num_bold=len(subject_data['bold']),
456-
# omp_nthreads=omp_nthreads,
457-
# output_dir=output_dir,
458-
# output_spaces=output_spaces,
459-
# reportlets_dir=reportlets_dir,
460-
# regressors_all_comps=regressors_all_comps,
461-
# regressors_fd_th=regressors_fd_th,
462-
# regressors_dvars_th=regressors_dvars_th,
463-
# t2s_coreg=t2s_coreg,
464-
# use_aroma=use_aroma,
465-
# use_syn=use_syn,
466-
# )
438+
for dwi_file in subject_data['dwi']:
439+
dwi_preproc_wf = init_dwi_preproc_wf(
440+
dwi_file=dwi_file,
441+
debug=debug,
442+
force_syn=force_syn,
443+
ignore=ignore,
444+
layout=layout,
445+
low_mem=low_mem,
446+
num_dwi=len(subject_data['dwi']),
447+
omp_nthreads=omp_nthreads,
448+
output_dir=output_dir,
449+
reportlets_dir=reportlets_dir,
450+
use_syn=use_syn,
451+
)
467452

468453
# workflow.connect([
469454
# (anat_preproc_wf, dwi_preproc_wf,

dmriprep/workflows/dwi/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Pre-processing dMRI workflows
3+
4+
.. automodule:: dmriprep.workflows.dwi.base
5+
.. automodule:: dmriprep.workflows.dwi.util
6+
7+
"""
8+
9+
from .base import init_dwi_preproc_wf
10+
from .util import init_dwi_reference_wf
11+
12+
_all__ = [
13+
'init_dwi_preproc_wf',
14+
'init_dwi_reference_wf'
15+
]

dmriprep/workflows/dwi/base.py

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
"""
2+
Orchestrating the dMRI-preprocessing workflow.
3+
4+
.. autofunction:: init_dwi_preproc_wf
5+
.. autofunction:: init_dwi_derivatives_wf
6+
7+
"""
8+
9+
from nipype import logging
10+
11+
from nipype.pipeline import engine as pe
12+
from nipype.interfaces import utility as niu
13+
14+
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
15+
16+
from ...config import DEFAULT_MEMORY_MIN_GB
17+
18+
from ...interfaces import DerivativesDataSink
19+
from ...interfaces.reports import DiffusionSummary
20+
from ...interfaces.vectors import CheckGradientTable
21+
22+
# dwi workflows
23+
from .util import init_dwi_reference_wf
24+
25+
26+
LOGGING = logging.getLogger('nipype.workflow')
27+
28+
29+
def init_dwi_preproc_wf(
30+
dwi_file,
31+
debug,
32+
force_syn,
33+
ignore,
34+
low_mem,
35+
omp_nthreads,
36+
output_dir,
37+
reportlets_dir,
38+
use_syn,
39+
layout=None,
40+
num_dwi=1,
41+
):
42+
"""
43+
This workflow controls the diffusion preprocessing stages of *dMRIPrep*.
44+
45+
Workflow Graph:
46+
.. workflow::
47+
:graph2use: orig
48+
:simple_form: yes
49+
50+
from dmriprep.workflows.dwi import init_dwi_preproc_wf
51+
from collections import namedtuple
52+
BIDSLayout = namedtuple('BIDSLayout', ['root'])
53+
wf = init_dwi_preproc_wf(
54+
dwi_file='/completely/made/up/path/sub-01_dwi.nii.gz',
55+
debug=False,
56+
force_syn=True,
57+
ignore=[],
58+
low_mem=False,
59+
omp_nthreads=1,
60+
output_dir='.',
61+
reportlets_dir='.',
62+
layout=BIDSLayout('.'),
63+
num_dwi=1,
64+
)
65+
66+
Parameters
67+
----------
68+
dwi_file : str
69+
dwi NIfTI file
70+
debug : bool
71+
Enable debugging outputs
72+
force_syn : bool
73+
**Temporary**: Always run SyN-based SDC
74+
ignore : list
75+
Preprocessing steps to skip (may include "sdc")
76+
low_mem : bool
77+
Write uncompressed .nii files in some cases to reduce memory usage
78+
omp_nthreads : int
79+
Maximum number of threads an individual process may use
80+
output_dir : str
81+
Directory in which to save derivatives
82+
reportlets_dir : str
83+
Absolute path of a directory in which reportlets will be temporarily stored
84+
use_syn : bool
85+
**Experimental**: Enable ANTs SyN-based susceptibility distortion correction (SDC).
86+
If fieldmaps are present and enabled, this is not run, by default.
87+
layout : BIDSLayout
88+
BIDSLayout structure to enable metadata retrieval
89+
num_dwi : int
90+
Total number of dwi files that have been set for preprocessing
91+
(default is 1)
92+
93+
Inputs
94+
------
95+
dwi_file
96+
dwi NIfTI file
97+
bvec_file
98+
File path of the b-values
99+
bval_file
100+
File path of the b-vectors
101+
102+
Outputs
103+
-------
104+
dwi_file
105+
dwi NIfTI file
106+
dwi_mask
107+
dwi mask
108+
109+
See also
110+
--------
111+
* :py_func:`~dmriprep.workflows.dwi.util.init_dwi_reference_wf
112+
113+
"""
114+
115+
wf_name = _get_wf_name(dwi_file)
116+
117+
# Build workflow
118+
workflow = Workflow(name=wf_name)
119+
workflow.__desc__ = """
120+
121+
Diffusion data preprocessing
122+
123+
: For each of the {num_dwi} dwi scans found per subject (across all sessions),
124+
the following preprocessing was performed.
125+
""".format(num_dwi=num_dwi)
126+
127+
workflow.__postdesc__ = """\
128+
"""
129+
130+
metadata = layout.get_metadata(dwi_file)
131+
132+
inputnode = pe.Node(niu.IdentityInterface(
133+
fields=['dwi_file']),
134+
name='inputnode')
135+
inputnode.inputs.dwi_file = dwi_file
136+
inputnode.inputs.bvec_file = layout.get_bvec(dwi_file)
137+
inputnode.inputs.bval_file = layout.get_bval(dwi_file)
138+
139+
outputnode = pe.Node(niu.IdentityInterface(
140+
fields=['dwi_file', 'bvec_file', 'bval_file', 'rasb_file',
141+
'dwi_mask']),
142+
name='outputnode')
143+
144+
summary = pe.Node(
145+
DiffusionSummary(
146+
pe_direction=metadata.get("PhaseEncodingDirection")),
147+
name='summary', mem_gb=DEFAULT_MEMORY_MIN_GB, run_without_submitting=True)
148+
149+
gradient_table = pe.Node(CheckGradientTable(), name='gradient_table')
150+
151+
dwi_reference_wf = init_dwi_reference_wf(omp_nthreads=1, gen_report=True)
152+
153+
# dwi_derivatives_wf = init_dwi_derivatives_wf()
154+
155+
# MAIN WORKFLOW STRUCTURE
156+
workflow.connect([
157+
(inputnode, gradient_table, [
158+
('dwi_file', 'dwi_file'),
159+
('bvec_file', 'in_bvec'),
160+
('bval_file', 'in_bval')]),
161+
(inputnode, dwi_reference_wf, [('dwi_file', 'inputnode.dwi_file')]),
162+
(gradient_table, dwi_reference_wf, [('b0_ixs', 'inputnode.b0_ixs')]),
163+
])
164+
165+
# REPORTING
166+
ds_report_summary = pe.Node(
167+
DerivativesDataSink(desc='summary', keep_dtype=True),
168+
name='ds_report_summary', run_without_submitting=True,
169+
mem_gb=DEFAULT_MEMORY_MIN_GB
170+
)
171+
172+
return workflow
173+
174+
175+
def _get_wf_name(dwi_fname):
176+
"""
177+
Derive the workflow name for supplied dwi file.
178+
>>> _get_wf_name('/completely/made/up/path/sub-01_dwi.nii.gz')
179+
'dwi_preproc_wf'
180+
>>> _get_wf_name('/completely/made/up/path/sub-01_run-1_dwi.nii.gz')
181+
'dwi_preproc_run_1_wf'
182+
"""
183+
from nipype.utils.filemanip import split_filename
184+
fname = split_filename(dwi_fname)[1]
185+
fname_nosub = '_'.join(fname.split("_")[1:])
186+
name = "dwi_preproc_" + fname_nosub.replace(
187+
".", "_").replace(" ", "").replace("-", "_").replace("_dwi", "_wf")
188+
189+
return name

0 commit comments

Comments
 (0)