Skip to content

[RTM] Accept T2w images in recon-all #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fmriprep/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BIDSDataGrabberOutputSpec(TraitedSpec):
func = OutputMultiPath(desc='output functional images')
sbref = OutputMultiPath(desc='output sbrefs')
t1w = OutputMultiPath(desc='output T1w images')
t2w = OutputMultiPath(desc='output T2w images')


class BIDSDataGrabber(SimpleInterface):
Expand All @@ -76,7 +77,7 @@ def _run_interface(self, runtime):
raise FileNotFoundError('No functional images found for subject sub-{}'.format(
self.inputs.subject_id))

for imtype in ['fmap', 'sbref']:
for imtype in ['t2w', 'fmap', 'sbref']:
self._results[imtype] = bids_dict[imtype]
if not bids_dict[imtype]:
LOGGER.warn('No \'{}\' images found for sub-{}'.format(
Expand Down
7 changes: 5 additions & 2 deletions fmriprep/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from bids.grabbids import BIDSLayout

INPUTS_SPEC = {'fieldmaps': [], 'func': [], 't1': [], 'sbref': []}
INPUTS_SPEC = {'fieldmaps': [], 'func': [], 't1': [], 'sbref': [], 't2w': []}

def _first(inlist):
if not isinstance(inlist, (list, tuple)):
Expand Down Expand Up @@ -74,7 +74,8 @@ def collect_bids_data(dataset, subject, task=None, session=None, run=None):
'fmap': {'modality': 'fmap', 'extensions': ['nii', 'nii.gz']},
'epi': {'modality': 'func', 'type': 'bold', 'extensions': ['nii', 'nii.gz']},
'sbref': {'modality': 'func', 'type': 'sbref', 'extensions': ['nii', 'nii.gz']},
't1w': {'type': 'T1w', 'extensions': ['nii', 'nii.gz']}
't1w': {'type': 'T1w', 'extensions': ['nii', 'nii.gz']},
't2w': {'type': 'T2w', 'extensions': ['nii', 'nii.gz']},
}

if task:
Expand All @@ -94,6 +95,8 @@ def collect_bids_data(dataset, subject, task=None, session=None, run=None):
imaging_data['sbref'] = sbref_files
epi_files = [x.filename for x in layout.get(**queries['epi'])]
imaging_data['func'] = epi_files
t2_files = [x.filename for x in layout.get(**queries['t2w'])]
imaging_data['t2w'] = t2_files

'''
loop_on = ['session', 'run', 'acquisition', 'task']
Expand Down
43 changes: 27 additions & 16 deletions fmriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):

workflow = pe.Workflow(name=name)

inputnode = pe.Node(niu.IdentityInterface(fields=['t1w', 'subjects_dir']), name='inputnode')
inputnode = pe.Node(niu.IdentityInterface(fields=['t1w', 't2w', 'subjects_dir']), name='inputnode')
outputnode = pe.Node(niu.IdentityInterface(
fields=['t1_seg', 't1_tpms', 'bias_corrected_t1', 't1_brain', 't1_mask',
't1_2_mni', 't1_2_mni_forward_transform',
Expand Down Expand Up @@ -81,35 +81,40 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):
if settings['freesurfer']:
nthreads = settings['nthreads']

def detect_inputs(t1w_list, default_flags=''):
def detect_inputs(t1w_list, t2w_list=[]):
import os
from nipype.interfaces.base import isdefined
from nipype.utils.filemanip import filename_to_list
from nipype.interfaces.traits_extension import Undefined
import nibabel as nib
t1w_list = filename_to_list(t1w_list)
t2w_list = filename_to_list(t2w_list) if isdefined(t2w_list) else []
t1w_ref = nib.load(t1w_list[0])
hires = max(t1w_ref.header.get_zooms()) < 1
# Use high resolution preprocessing if voxel size < 1.0mm
# Tolerance of 0.05mm requires that rounds down to 0.9mm or lower
hires = max(t1w_ref.header.get_zooms()) < 1 - 0.05
t1w_outs = [t1w_list.pop(0)]
for t1w in t1w_list:
img = nib.load(t1w)
if all((img.shape == t1w_ref.shape,
img.header.get_zooms() == t1w_ref.header.get_zooms())):
t1w_outs.append(t1w)

autorecon1_flags = [default_flags]
reconall_flags = [default_flags]
if hires:
autorecon1_flags.append('-hires')
reconall_flags.append('-hires')
return (t1w_outs, ' '.join(autorecon1_flags),
' '.join(reconall_flags))
t2w = Undefined
if t2w_list and max(nib.load(t2w_list[0]).header.get_zooms()) < 1.2:
t2w = t2w_list[0]

# https://surfer.nmr.mgh.harvard.edu/fswiki/SubmillimeterRecon
mris_inflate = '-n 50' if hires else Undefined
return (t1w_outs, t2w, isdefined(t2w), hires, mris_inflate)

recon_config = pe.Node(
niu.Function(
function=detect_inputs,
input_names=['t1w_list', 'default_flags'],
output_names=['t1w', 'autorecon1_flags', 'reconall_flags']),
input_names=['t1w_list', 't2w_list'],
output_names=['t1w', 't2w', 'use_T2', 'hires', 'mris_inflate']),
name='ReconConfig',
run_without_submitting=True)
recon_config.inputs.default_flags = '-noskullstrip'

def bidsinfo(in_file):
from fmriprep.interfaces.bids import BIDS_NAME
Expand All @@ -128,6 +133,7 @@ def bidsinfo(in_file):
autorecon1 = pe.Node(
freesurfer.ReconAll(
directive='autorecon1',
flags='-noskullstrip',
openmp=nthreads,
parallel=True),
name='Reconstruction')
Expand Down Expand Up @@ -166,6 +172,7 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):

reconall = pe.Node(
ReconAllRPT(
flags='-noskullstrip',
openmp=nthreads,
parallel=True,
out_report='reconall.svg',
Expand Down Expand Up @@ -252,18 +259,22 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):

if settings['freesurfer']:
workflow.connect([
(inputnode, recon_config, [('t1w', 't1w_list')]),
(inputnode, recon_config, [('t1w', 't1w_list'),
('t2w', 't2w_list')]),
(inputnode, bids_info, [(('t1w', fix_multi_T1w_source_name), 'in_file')]),
(inputnode, autorecon1, [('subjects_dir', 'subjects_dir')]),
(recon_config, autorecon1, [('t1w', 'T1_files'),
('autorecon1_flags', 'flags')]),
('t2w', 'T2_file'),
('hires', 'hires'),
# First run only (recon-all saves expert options)
('mris_inflate', 'mris_inflate')]),
(bids_info, autorecon1, [('subject_id', 'subject_id')]),
(autorecon1, injector, [('subjects_dir', 'subjects_dir'),
('subject_id', 'subject_id')]),
(asw, injector, [('outputnode.out_file', 'skullstripped')]),
(injector, reconall, [('subjects_dir', 'subjects_dir'),
('subject_id', 'subject_id')]),
(recon_config, reconall, [('reconall_flags', 'flags')]),
(recon_config, reconall, [('use_T2', 'use_T2')]),
(inputnode, recon_report, [
(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(reconall, recon_report, [('out_report', 'in_file')]),
Expand Down
6 changes: 4 additions & 2 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def basic_fmap_sbref_wf(subject_data, settings, name='fMRI_prep'):
t1_to_epi_transforms = pe.Node(fsl.ConvertXFM(concat_xfm=True), name='T1ToEPITransforms')

workflow.connect([
(bidssrc, t1w_pre, [('t1w', 'inputnode.t1w')]),
(bidssrc, t1w_pre, [('t1w', 'inputnode.t1w'),
('t2w', 'inputnode.t2w')]),
(bidssrc, fmap_est, [('fmap', 'inputnode.input_images')]),
(bidssrc, sbref_pre, [('sbref', 'inputnode.sbref')]),
(bidssrc, sbref_t1, [('sbref', 'inputnode.name_source'),
Expand Down Expand Up @@ -225,7 +226,8 @@ def basic_wf(subject_data, settings, name='fMRI_prep'):
epi_mni_trans_wf = epi_mni_transformation(settings=settings)

workflow.connect([
(bidssrc, t1w_pre, [('t1w', 'inputnode.t1w')]),
(bidssrc, t1w_pre, [('t1w', 'inputnode.t1w'),
('t2w', 'inputnode.t2w')]),
(bidssrc, epi_2_t1, [('t1w', 'inputnode.t1w')]),
(hmcwf, epi_2_t1, [('inputnode.epi', 'inputnode.name_source'),
('outputnode.epi_mean', 'inputnode.ref_epi'),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/nipy/nipype.git@cfca7cce966ccd83ed3921667844466e8b9bc8b1#egg=nipype
git+https://github.com/nipy/nipype.git@07a75a64ae917b4ed0839d3b5a79bd63ebed9964#egg=nipype
git+https://github.com/poldracklab/niworkflows.git@f3e11159ba8ddc8c850edc3bd1bf62d7286322d4#egg=niworkflows