Skip to content

Commit

Permalink
Merge pull request #166 from rwblair/issue165
Browse files Browse the repository at this point in the history
[WIP] update mni template being used in anatomical and epi workflows to mni…
  • Loading branch information
oesteban committed Nov 22, 2016
2 parents b6eb02b + 23695b8 commit 00530d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 261 deletions.
3 changes: 1 addition & 2 deletions fmriprep/viz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
The fmriprep reporting engine for visual assessment
"""

from fmriprep.viz.pdf_compose import generate_report
from fmriprep.viz.pipeline_reports import (anatomical_overlay, parcel_overlay,
stripped_brain_overlay, generate_report_workflow)
stripped_brain_overlay)
58 changes: 0 additions & 58 deletions fmriprep/viz/pdf_compose.py

This file was deleted.

187 changes: 0 additions & 187 deletions fmriprep/viz/pipeline_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
@author: craigmoodie
"""

import os.path as op

from nipype.interfaces.fsl import MeanImage
from nipype.interfaces.utility import Function
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from nipype.pipeline.engine import Workflow, Node

from fmriprep.viz.pdf_compose import generate_report



def anatomical_overlay(in_file, overlay_file, out_file):
import os.path
import matplotlib as mpl
Expand Down Expand Up @@ -64,178 +52,3 @@ def stripped_brain_overlay(in_file, overlay_file, out_file):
# mask_display.display_mode = "yx"
mask_display
return os.path.abspath(out_file)


def generate_report_workflow():

report_workflow = Workflow(name="report_workflow")

inputnode = pe.Node(niu.IdentityInterface(
fields=['fmap_mag', 'fmap_mag_brain', 'raw_epi', 'stripped_epi',
'corrected_epi_mean', 'sbref', 'sbref_brain', 'sbref_brain',
'sbref_t1', 'corrected_sbref', 't1', 't1_brain', 't1_2_mni',
'parcels_t1', 'parcels_native', 'fieldmap', 't1_segmentation',
't1_wm_seg']),
name='inputnode'
)
outputnode = pe.Node(niu.IdentityInterface(fields=['wm_seg']),
name='outputnode')

# Condensing 4D Stacks into 3D mean
fmap_mag_mean = Node(MeanImage(), name="Fieldmap_mean")
fmap_mag_mean.inputs.output_type = "NIFTI_GZ"
fmap_mag_mean.inputs.dimension = 'T'

stripped_epi_mean = Node(MeanImage(), name="Stripped_EPI_mean")
stripped_epi_mean.inputs.output_type = "NIFTI_GZ"
stripped_epi_mean.inputs.dimension = 'T'

# This isn't working!!!
raw_epi_mean = Node(MeanImage(), name="Raw_EPI_mean")
raw_epi_mean.inputs.output_type = "NIFTI_GZ"
raw_epi_mean.inputs.dimension = 'T'
fmap_overlay = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=parcel_overlay
),
name="Fieldmap_to_SBRef_Overlay"
)
fmap_overlay.inputs.out_file = "Fieldmap_to_SBRef_Overlay.png"

fmap_mag_BET = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=stripped_brain_overlay
),
name="Fieldmap_Mag_BET"
)
fmap_mag_BET.inputs.out_file = "Fieldmap_Mag_BET.png"

EPI_BET_report = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=stripped_brain_overlay
),
name="EPI_Skullstrip_Overlay"
)
EPI_BET_report.inputs.out_file = "EPI_Skullstrip_Overlay.png"

sbref_unwarp_overlay = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=anatomical_overlay
),
name="SBRef_Unwarping_Overlay"
)
sbref_unwarp_overlay.inputs.out_file = "SBRef_Unwarping_Overlay.png"

epi_unwarp_overlay = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=anatomical_overlay
),
name="EPI_Unwarping_Overlay"
)
epi_unwarp_overlay.inputs.out_file = "EPI_Unwarping_Overlay.png"

SBRef_BET = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=stripped_brain_overlay
),
name="SBRef_BET"
)
SBRef_BET.inputs.out_file = "SBRef_BET_Overlay.png"

epi_2_sbref = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=anatomical_overlay
),
name="Functional_to_SBRef_Overlay"
)
epi_2_sbref.inputs.out_file = "Functional_to_SBRef_Overlay.png"

sbref_2_t1 = Node(
Function(
input_names=["in_file", "overlay_file", "out_file"],
output_names=["out_file"],
function=anatomical_overlay
),
name="SBRef_to_T1_Overlay"
)
sbref_2_t1.inputs.out_file = "SBRef_to_T1_Overlay.png"

# final_pdf = Node(
# Function(
# input_names=[
# "output_file", "first_plot", "second_plot", "third_plot",
# "fourth_plot", "fifth_plot", "sixth_plot", "seventh_plot",
# "eighth_plot"
# ],
# output_names=["output_file"],
# function=generate_report
# ),
# name="Final_pdf"
# )
# final_pdf.inputs.output_file = "Preprocessing_Quality_Report.pdf"


report_workflow.connect([
(inputnode, fmap_mag_mean, [("fmap_mag", "in_file")]),
(inputnode, fmap_overlay, [("fieldmap", "in_file")]),
(inputnode, fmap_overlay, [("sbref", "overlay_file")]),
(inputnode, fmap_mag_BET, [("fmap_mag_brain", "in_file")]),
(fmap_mag_mean, fmap_mag_BET, [("out_file", "overlay_file")]),
(inputnode, raw_epi_mean, [("raw_epi", "in_file")]),
(inputnode, stripped_epi_mean, [("stripped_epi", "in_file")]),
(stripped_epi_mean, EPI_BET_report, [("out_file", "in_file")]),
(raw_epi_mean, EPI_BET_report, [("out_file", "overlay_file")]),
(inputnode, sbref_unwarp_overlay, [("corrected_sbref", "in_file")]),
(inputnode, sbref_unwarp_overlay, [("sbref", "overlay_file")]),
(inputnode, SBRef_BET, [("sbref_brain", "in_file")]),
(inputnode, SBRef_BET, [("sbref", "overlay_file")]),
# (inputnode, parcels_2_EPI, [("parcels_native", "in_file")]),
# (inputnode, parcels_2_EPI, [("corrected_epi_mean", "overlay_file")]),
# (inputnode, parcels_2_T1, [("parcels_t1", "in_file")]),
# (inputnode, parcels_2_T1, [("t1", "overlay_file")]),
# (inputnode, parcels_2_sbref, [("parcels_native", "in_file")]),
# prob should use corrected sbref brain mask
# (inputnode, parcels_2_sbref, [("corrected_sbref", "overlay_file")]),
(inputnode, epi_2_sbref, [("corrected_epi_mean", "in_file")]),
(inputnode, epi_2_sbref, [("corrected_sbref", "overlay_file")]),
(inputnode, sbref_2_t1, [("sbref", "in_file")]),
(inputnode, sbref_2_t1, [("t1_wm_seg", "overlay_file")]),
(inputnode, epi_unwarp_overlay, [("corrected_epi_mean", "in_file")]),
(raw_epi_mean, epi_unwarp_overlay, [("out_file", "overlay_file")]),
# (inputnode, T1_2_MNI, [("t1_mni", "in_file")]),
# replace sbref to mni and epi to mni with sbref and epi unwarping,
# also replace epi to t1 with parcel to sbref
# (fmap_overlay, final_pdf, [("out_file", "first_plot")]),
# (EPI_BET_report, final_pdf, [("out_file", "second_plot")]),
# (SBRef_BET, final_pdf, [("out_file", "third_plot")]),
# (sbref_unwarp_overlay, final_pdf, [("out_file", "fifth_plot")]),
# (epi_unwarp_overlay, final_pdf, [("out_file", "sixth_plot")]),
# (epi_2_sbref, final_pdf, [("out_file", "seventh_plot")]),
# # (t1_2_mni, final_pdf, [("out_file", "t1_2_mni_plot")]),
# (sbref_2_t1, final_pdf, [("out_file", "eighth_plot")]),
# # (T1_2_MNI, final_pdf, [("out_file", "ninth_plot")]),
# # (parcels_2_T1, final_pdf, [("out_file", "tenth_plot")]),
# # (parcels_2_EPI, final_pdf, [("out_file", "eleventh_plot")]),
# # (parcels_2_sbref, final_pdf, [("out_file", "twelfth_plot")]),
])

return report_workflow


if __name__ == '__main__':
report_wf = generate_report_workflow()
report_wf.write_graph()
25 changes: 14 additions & 11 deletions fmriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from niworkflows.anat.mni import RobustMNINormalization
from niworkflows.anat.skullstrip import afni_wf as skullstrip_wf
from niworkflows.common import reorient as mri_reorient_wf
from niworkflows.data import get_mni_template
from niworkflows.data import get_mni_icbm152_nlin_asym_09c

from fmriprep.interfaces import (DerivativesDataSink, IntraModalMerge,
ImageDataSink)
Expand Down Expand Up @@ -67,12 +67,15 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):
name='T1_2_MNI_Registration')

# Resample the brain mask and the tissue probability maps into mni space
bmask_mni = pe.Node(ants.ApplyTransforms(
dimension=3, default_value=0, interpolation='NearestNeighbor'), name='brain_mni_warp')
bmask_mni.inputs.reference_image = op.join(get_mni_template(), 'MNI152_T1_1mm.nii.gz')
bmask_mni = pe.Node(
ants.ApplyTransforms(dimension=3, default_value=0,
interpolation='NearestNeighbor'),
name='brain_mni_warp'
)
bmask_mni.inputs.reference_image = op.join(get_mni_icbm152_nlin_asym_09c(), '1mm_T1.nii.gz')
tpms_mni = pe.MapNode(ants.ApplyTransforms(dimension=3, default_value=0, interpolation='Linear'),
iterfield=['input_image'], name='tpms_mni_warp')
tpms_mni.inputs.reference_image = op.join(get_mni_template(), 'MNI152_T1_1mm.nii.gz')
tpms_mni.inputs.reference_image = op.join(get_mni_icbm152_nlin_asym_09c(), '1mm_T1.nii.gz')


workflow.connect([
Expand Down Expand Up @@ -140,8 +143,8 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):
interpolation='NearestNeighbor'),
name='T1_2_MNI_warp'
)
seg_2_mni.inputs.reference_image = op.join(get_mni_template(),
'MNI152_T1_1mm.nii.gz')
seg_2_mni.inputs.reference_image = op.join(get_mni_icbm152_nlin_asym_09c(),
'1mm_T1.nii.gz')

t1_2_mni_overlay = pe.Node(
niu.Function(
Expand All @@ -152,15 +155,15 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):
name='T1ToMNI'
)
t1_2_mni_overlay.inputs.out_file = 't1_to_mni_overlay.svg'
t1_2_mni_overlay.inputs.overlay_file = op.join(get_mni_template(),
'MNI152_T1_1mm.nii.gz')
t1_2_mni_overlay.inputs.overlay_file = op.join(get_mni_icbm152_nlin_asym_09c(),
'1mm_T1.nii.gz')

t1_2_mni_overlay_ds = pe.Node(
ImageDataSink(base_directory=settings['output_dir']),
name='T12MNIOverlayDS'
)
t1_2_mni_overlay_ds.inputs.overlay_file = op.join(get_mni_template(),
'MNI152_T1_1mm.nii.gz')
t1_2_mni_overlay_ds.inputs.overlay_file = op.join(get_mni_icbm152_nlin_asym_09c(),
'1mm_T1.nii.gz')

datasink = pe.Node(
interface=nio.DataSink(
Expand Down
6 changes: 3 additions & 3 deletions fmriprep/workflows/epi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from nipype.interfaces import fsl
from nipype.interfaces import io as nio
from nipype.interfaces import utility as niu
from niworkflows.data import get_mni_template_ras
from niworkflows.data import get_mni_icbm152_nlin_asym_09c

from fmriprep.interfaces import (DerivativesDataSink, FormatHMCParam,
ImageDataSink)
Expand Down Expand Up @@ -330,8 +330,8 @@ def _aslist(in_value):
gen_ref = pe.Node(niu.Function(
input_names=['fixed_image', 'moving_image'], output_names=['out_file'],
function=_gen_reference), name='GenNewMNIReference')
gen_ref.inputs.fixed_image = op.join(get_mni_template_ras(),
'MNI152_T1_1mm.nii.gz')
gen_ref.inputs.fixed_image = op.join(get_mni_icbm152_nlin_asym_09c(),
'1mm_T1.nii.gz')

split = pe.Node(fsl.Split(dimension='t'), name='SplitEPI')
merge_transforms = pe.MapNode(niu.Merge(3),
Expand Down

0 comments on commit 00530d6

Please sign in to comment.