Skip to content

Commit

Permalink
[ENH] Allow templates other than MNI152NLin2009cAsym
Browse files Browse the repository at this point in the history
This is possible leveraging TemplateFlow. This PR closes nipreps#11, although
it does not implement the feature of allowing setting more than just one
spatial normalization target.

Modified ds054's build in CircleCI to test against ``MNI152Lin``.
  • Loading branch information
oesteban committed Jan 18, 2019
1 parent 4bbd45f commit ce52233
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -418,7 +418,7 @@ jobs:
poldracklab/smriprep:latest \
/tmp/data/ds054 /tmp/ds054/derivatives participant \
-w /tmp/ds054/work --fs-no-reconall --sloppy --write-graph \
--mem-gb 4 --ncpus 2 --omp-nthreads 2 -vv \
--template MNI152Lin --mem-gb 4 --ncpus 2 --omp-nthreads 2 -vv \
--fs-license-file /tmp/fslicense/license.txt
- save_cache:
key: ds054-anat-v2-{{ .Branch }}-{{ epoch }}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,5 +1,5 @@
templateflow>=0.0.3
git+https://github.com/oesteban/niworkflows.git@c7432ec841706fbb4d9573567320529a09f4d156#niworkflows-0.5.3
git+https://github.com/oesteban/niworkflows.git@236dc42b2f49054da88ed232b75e5cd5ff718426#niworkflows-0.5.3
grabbit==0.2.3
pybids==0.6.5
indexed_gzip>=0.8.8
2 changes: 1 addition & 1 deletion smriprep/__about__.py
Expand Up @@ -62,7 +62,7 @@

LINKS_REQUIRES = [
'git+https://github.com/oesteban/niworkflows.git@'
'c7432ec841706fbb4d9573567320529a09f4d156#niworkflows-0.5.3',
'236dc42b2f49054da88ed232b75e5cd5ff718426#niworkflows-0.5.3',
]

TESTS_REQUIRES = [
Expand Down
17 changes: 12 additions & 5 deletions smriprep/interfaces/reports.py
Expand Up @@ -14,15 +14,16 @@

from nipype.interfaces.base import (
traits, TraitedSpec, BaseInterfaceInputSpec,
File, Directory, InputMultiPath, Str, isdefined,
File, Directory, InputMultiObject, Str, isdefined,
SimpleInterface)
from nipype.interfaces import freesurfer as fs


SUBJECT_TEMPLATE = """\t<ul class="elem-desc">
\t\t<li>Subject ID: {subject_id}</li>
\t\t<li>Structural images: {n_t1s:d} T1-weighted {t2w}</li>
\t\t<li>Resampling targets: {fs_spaces}
\t\t<li>Surface spaces: {fs_spaces}</li>
{template}\
\t\t<li>FreeSurfer reconstruction: {freesurfer_status}</li>
\t</ul>
"""
Expand Down Expand Up @@ -52,12 +53,12 @@ def _run_interface(self, runtime):


class SubjectSummaryInputSpec(BaseInterfaceInputSpec):
t1w = InputMultiPath(File(exists=True), desc='T1w structural images')
t2w = InputMultiPath(File(exists=True), desc='T2w structural images')
t1w = InputMultiObject(File(exists=True), desc='T1w structural images')
t2w = InputMultiObject(File(exists=True), desc='T2w structural images')
subjects_dir = Directory(desc='FreeSurfer subjects directory')
subject_id = Str(desc='Subject ID')
fs_spaces = traits.List(desc='Target spaces')
template = traits.Enum('MNI152NLin2009cAsym', desc='Template space')
template = InputMultiObject(Str, desc='Template space')


class SubjectSummaryOutputSpec(SummaryOutputSpec):
Expand All @@ -76,6 +77,11 @@ def _run_interface(self, runtime):
return super(SubjectSummary, self)._run_interface(runtime)

def _generate_segment(self):
if isdefined(self.inputs.template):
template = "\t\t<li>Volume standard spaces: {}</li>\n".format(
', '.join(self.inputs.template) if isinstance(self.inputs.template, list)
else self.inputs.template)

if not isdefined(self.inputs.subjects_dir):
freesurfer_status = 'Not run'
else:
Expand All @@ -95,6 +101,7 @@ def _generate_segment(self):
return SUBJECT_TEMPLATE.format(subject_id=self.inputs.subject_id,
n_t1s=len(self.inputs.t1w),
t2w=t2w_seg,
template=template,
fs_spaces=', '.join(self.inputs.fs_spaces),
freesurfer_status=freesurfer_status)

Expand Down
3 changes: 3 additions & 0 deletions smriprep/workflows/anatomical.py
Expand Up @@ -316,6 +316,9 @@ def init_anat_preproc_wf(skull_strip_template, fs_spaces, template, debug,
)

# TODO isolate the spatial normalization workflow #############
if isinstance(template, list):
template = template[0]

ref_img = get_template(template, 'res-01_T1w.nii.gz')

t1_2_mni.inputs.template = template
Expand Down

0 comments on commit ce52233

Please sign in to comment.