Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
588c7ef
[FSL] Updated BEDPOSTX and XFibres
oesteban Sep 10, 2014
3f677eb
fixed gradient nonlinearities implementation
oesteban Sep 10, 2014
834571c
fixed errors
oesteban Sep 11, 2014
0f1c179
fixed bug
oesteban Sep 11, 2014
68ab056
fixed XFibres
oesteban Sep 11, 2014
449452f
fix doctest of BEDPOSTX
oesteban Sep 11, 2014
dc1a4cd
tested new XFibres. new parallel workflow
oesteban Sep 11, 2014
0de90cf
preparing new workflow for parallel processing
oesteban Sep 11, 2014
9336dee
new split and merge interfaces
oesteban Sep 12, 2014
6c01665
added test and some missing files in last commit
oesteban Sep 12, 2014
f177e3f
new parallel bedpostx finished :)
oesteban Sep 12, 2014
2afca1b
new naming conventions
oesteban Oct 6, 2014
6e8c5ae
Merge branch 'master' into enh/UpdateBEDPOSTX
oesteban Oct 6, 2014
1f00894
bedpostx_parallel avoid computation of dyads uncertainty available
oesteban Oct 6, 2014
5ee0ffb
Interface Merge for large files
oesteban Oct 6, 2014
3974692
Merge branch 'enh/UpdateBEDPOSTX' of github.com:oesteban/nipype into …
oesteban Oct 6, 2014
a3a420e
fix missing comma
oesteban Oct 6, 2014
5fef712
added computation of mean f samples in bedpostx
oesteban Oct 7, 2014
edb7faf
fix missing connections
oesteban Oct 7, 2014
983cee1
fixed several bugs. tested in practice
oesteban Oct 7, 2014
310160d
Merge remote-tracking branch 'upstream/master' into fix/bedpostx
satra Oct 7, 2014
a1636f8
Merge remote-tracking branch 'upstream/master' into fix/bedpostx
satra Oct 7, 2014
c8e82c0
fix: clean up bedpostx and xfibres implementations
satra Oct 8, 2014
fbf5db1
Merge remote-tracking branch 'upstream/master' into fix/bedpostx
satra Oct 8, 2014
400050b
tst: cleaned auto tests and imports
satra Oct 8, 2014
12e7608
tst: fixed all failing tests
satra Oct 8, 2014
fce9b33
resolved conflicts
satra Oct 8, 2014
0a79223
Merge branch 'satra-fix/bedpostx' into enh/UpdateBEDPOSTX
oesteban Oct 8, 2014
f43ea3b
make check-before-commit
oesteban Oct 8, 2014
6b69b33
Merge remote-tracking branch 'upstream/master' into fix/bedpostx
satra Oct 8, 2014
23b27d9
Merge branch 'master' into fix/bedpostx
satra Oct 15, 2014
983a5ee
fix: added tests to suppress auto generation
satra Oct 15, 2014
59b6a82
fix: resolved conflict
satra Oct 15, 2014
20c5052
Merge branch 'satra-fix/bedpostx2' into enh/UpdateBEDPOSTX
oesteban Oct 16, 2014
acf5380
Merge branch 'master' into enh/UpdateBEDPOSTX
oesteban Oct 16, 2014
13c7cfa
Merge with upstream master, make specs, make check-before-commit
oesteban Oct 16, 2014
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed XFibres
  • Loading branch information
oesteban committed Sep 11, 2014
commit 68ab056b971321fe2caeca3b89283c592924cde4
51 changes: 14 additions & 37 deletions nipype/interfaces/fsl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ def _overload_extension(self, value, name=None):


class FSLXCommandInputSpec(FSLCommandInputSpec):
out_dir = Directory('.', mandatory=True, desc='output directory',
usedefault=True, position=1, argstr='%s')
dwi = File(exists=True, argstr='--data=%s', mandatory=True,
desc='diffusion weighted image data file')
mask = File(exists=True, argstr='--mask=%s', mandatory=True,
Expand Down Expand Up @@ -307,39 +305,39 @@ class FSLXCommandInputSpec(FSLCommandInputSpec):
f0_ard = traits.Bool(argstr='--f0 --ardf0', xor=_xor_inputs3 + ['all_ard'],
desc=('Noise floor model: add to the model an '
'unattenuated signal compartment f0'))
force_dir = traits.Bool(False, argstr='--forcedir', usedefault=True,
force_dir = traits.Bool(True, argstr='--forcedir', usedefault=True,
desc=('use the actual directory name given '
'(do not add + to make a new directory)'))


class FSLXCommandOutputSpec(TraitedSpec):
merged_thsamples = OutputMultiPath(File(exists=True), desc=('Samples from '
merged_thsamples = OutputMultiPath(File(), desc=('Samples from '
'the distribution on theta'))
merged_phsamples = OutputMultiPath(File(exists=True), desc=('Samples from '
merged_phsamples = OutputMultiPath(File(), desc=('Samples from '
'the distribution on phi'))
merged_fsamples = OutputMultiPath(File(exists=True),
merged_fsamples = OutputMultiPath(File(),
desc=('Samples from the distribution on '
'anisotropic volume fraction.'))

mean_thsamples = OutputMultiPath(File(exists=True), desc=('Mean of '
mean_thsamples = OutputMultiPath(File(), desc=('Mean of '
'distribution on theta'))
mean_phsamples = OutputMultiPath(File(exists=True), desc=('Mean of '
mean_phsamples = OutputMultiPath(File(), desc=('Mean of '
'distribution on phi'))
mean_fsamples = OutputMultiPath(File(exists=True), desc=('Mean of '
mean_fsamples = OutputMultiPath(File(), desc=('Mean of '
'distribution on f anisotropy'))

mean_dsamples = File(exists=True, desc='Mean of distribution on '
mean_dsamples = File(desc='Mean of distribution on '
'diffusivity d')
mean_S0samples = File(exists=True, desc='Mean of distribution on T2w'
mean_S0samples = File(desc='Mean of distribution on T2w'
'baseline signal intensity S0')
mean_tausamples = File(exists=True, desc='Mean of distribution on '
mean_tausamples = File(desc='Mean of distribution on '
'tau samples (only with rician noise)')

dyads = OutputMultiPath(File(exists=True), desc=('Mean of PDD distribution'
dyads = OutputMultiPath(File(), desc=('Mean of PDD distribution'
' in vector form.'))
dyads_disp = OutputMultiPath(File(exists=True), desc=('Uncertainty on the '
dyads_disp = OutputMultiPath(File(), desc=('Uncertainty on the '
' estimated fiber orientation'))
fsamples = OutputMultiPath(File(exists=True), desc=('Samples from the '
fsamples = OutputMultiPath(File(), desc=('Samples from the '
'distribution on anisotropic volume fraction'))


Expand All @@ -351,28 +349,7 @@ class FSLXCommand(FSLCommand):
output_spec = FSLXCommandOutputSpec

def _run_interface(self, runtime):
subjectdir = os.path.abspath(self.inputs.out_dir)
out_dir = subjectdir + '.bedpostX'

if isdefined(self.inputs.force_dir) and self.inputs.force_dir:
out_dir = os.path.abspath(self.inputs.out_dir)
self._out_dir = out_dir

if not os.path.exists(out_dir):
os.makedirs(out_dir)

_, _, ext = split_filename(self.inputs.mask)
copyfile(self.inputs.mask,
os.path.join(subjectdir,
'nodif_brain_mask' + ext))
_, _, ext = split_filename(self.inputs.dwi)
copyfile(self.inputs.dwi,
os.path.join(subjectdir, 'data' + ext))
copyfile(self.inputs.bvals,
os.path.join(subjectdir, 'bvals'))
copyfile(self.inputs.bvecs,
os.path.join(subjectdir, 'bvecs'))

self._out_dir = os.getcwd()
runtime = super(FSLXCommand, self)._run_interface(runtime)
if runtime.stderr:
self.raise_exception(runtime)
Expand Down
27 changes: 27 additions & 0 deletions nipype/interfaces/fsl/dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def _list_outputs(self):


class BEDPOSTXInputSpec(FSLXCommandInputSpec):
out_dir = Directory('.', mandatory=True, desc='output directory',
usedefault=True, position=1, argstr='%s')
gradnonlin = traits.Bool(False, argstr='-g', desc=('consider gradient '
'nonlinearities, default off'))

Expand Down Expand Up @@ -137,6 +139,31 @@ class BEDPOSTX(FSLXCommand):
output_spec = FSLXCommandOutputSpec
_can_resume = True

def _run_interface(self, runtime):
subjectdir = os.path.abspath(self.inputs.out_dir)
out_dir = subjectdir + '.bedpostX'

if isdefined(self.inputs.force_dir) and self.inputs.force_dir:
out_dir = os.path.abspath(self.inputs.out_dir)
self._out_dir = out_dir

if not os.path.exists(out_dir):
os.makedirs(out_dir)

_, _, ext = split_filename(self.inputs.mask)
copyfile(self.inputs.mask,
os.path.join(subjectdir,
'nodif_brain_mask' + ext))
_, _, ext = split_filename(self.inputs.dwi)
copyfile(self.inputs.dwi,
os.path.join(subjectdir, 'data' + ext))
copyfile(self.inputs.bvals,
os.path.join(subjectdir, 'bvals'))
copyfile(self.inputs.bvecs,
os.path.join(subjectdir, 'bvecs'))

return super(BEDPOSTX, self)._run_interface(runtime)


class XFibresInputSpec(FSLXCommandInputSpec):
gradnonlin = File(exists=True, argstr='--gradnonlin=%s',
Expand Down
5 changes: 0 additions & 5 deletions nipype/interfaces/fsl/tests/test_auto_FSLXCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ def test_FSLXCommand_inputs():
non_linear=dict(argstr='--nonlinear',
xor=('no_spat', 'non_linear', 'cnlinear'),
),
out_dir=dict(argstr='%s',
mandatory=True,
position=1,
usedefault=True,
),
output_type=dict(),
rician=dict(argstr='--rician',
),
Expand Down
5 changes: 0 additions & 5 deletions nipype/interfaces/fsl/tests/test_auto_XFibres.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ def test_XFibres_inputs():
non_linear=dict(argstr='--nonlinear',
xor=('no_spat', 'non_linear', 'cnlinear'),
),
out_dir=dict(argstr='%s',
mandatory=True,
position=1,
usedefault=True,
),
output_type=dict(),
rician=dict(argstr='--rician',
),
Expand Down
199 changes: 45 additions & 154 deletions nipype/workflows/dmri/fsl/dti.py
Original file line number Diff line number Diff line change
@@ -1,189 +1,80 @@
# coding: utf-8

import nipype.pipeline.engine as pe
import nipype.interfaces.utility as util
import nipype.interfaces.fsl as fsl
from nipype.interfaces import utility as niu
from nipype.interfaces import fsl
import os

#backwards compatibility
from epi import create_eddy_correct_pipeline


def transpose(samples_over_fibres):
import numpy as np
a = np.array(samples_over_fibres)
if len(a.shape) == 1:
a = a.reshape(-1, 1)
return a.T.tolist()
return np.squeeze(a.T).tolist()


def create_bedpostx_pipeline(name="bedpostx"):
"""Creates a pipeline that does the same as bedpostx script from FSL -
def create_bedpostx_pipeline(name='bedpostx', params={}):
"""
Creates a pipeline that does the same as bedpostx script from FSL -
calculates diffusion model parameters (distributions not MLE) voxelwise for
the whole volume (by splitting it slicewise).

Example
-------

>>> nipype_bedpostx = create_bedpostx_pipeline("nipype_bedpostx")
>>> nipype_bedpostx.inputs.inputnode.dwi = 'diffusion.nii'
>>> nipype_bedpostx.inputs.inputnode.mask = 'mask.nii'
>>> nipype_bedpostx.inputs.inputnode.bvecs = 'bvecs'
>>> nipype_bedpostx.inputs.inputnode.bvals = 'bvals'
>>> nipype_bedpostx.inputs.xfibres.n_fibres = 2
>>> nipype_bedpostx.inputs.xfibres.fudge = 1
>>> nipype_bedpostx.inputs.xfibres.burn_in = 1000
>>> nipype_bedpostx.inputs.xfibres.n_jumps = 1250
>>> nipype_bedpostx.inputs.xfibres.sample_every = 25
>>> nipype_bedpostx.run() # doctest: +SKIP
>>> from nipype.workflows.dmri.fsl.dti import create_bedpostx_pipeline
>>> params = dict(n_fibres = 2, fudge = 1, burn_in = 1000,
... n_jumps = 1250, sample_every = 25)
>>> bpwf = create_bedpostx_pipeline('nipype_bedpostx', params)
>>> bpwf.inputs.inputnode.dwi = 'diffusion.nii'
>>> bpwf.inputs.inputnode.mask = 'mask.nii'
>>> bpwf.inputs.inputnode.bvecs = 'bvecs'
>>> bpwf.inputs.inputnode.bvals = 'bvals'
>>> bpwf.run() # doctest: +SKIP

Inputs::

inputnode.dwi
inputnode.mask
inputnode.bvecs
inputnode.bvals

Outputs::

outputnode.thsamples
outputnode.phsamples
outputnode.fsamples
outputnode.mean_thsamples
outputnode.mean_phsamples
outputnode.mean_fsamples
outputnode.dyads
outputnode.dyads_dispersion
outputnode wraps all XFibres outputs

"""

inputnode = pe.Node(
interface=util.IdentityInterface(fields=["dwi", "mask"]),
name="inputnode")
inputnode = pe.Node(niu.IdentityInterface(fields=['dwi', 'mask',
'bvecs', 'bvals']), name='inputnode')

mask_dwi = pe.Node(interface=fsl.ImageMaths(op_string="-mas"),
name="mask_dwi")
slice_dwi = pe.Node(interface=fsl.Split(dimension="z"), name="slice_dwi")
slice_mask = pe.Node(interface=fsl.Split(dimension="z"),
name="slice_mask")
slice_dwi = pe.Node(fsl.Split(dimension='z'), name='slice_dwi')
slice_msk = pe.Node(fsl.Split(dimension='z'), name='slice_msk')
mask_dwi = pe.MapNode(fsl.ImageMaths(op_string='-mas'),
iterfield=['in_file', 'in_file2'], name='mask_dwi')

preproc = pe.Workflow(name="preproc")

preproc.connect([(inputnode, mask_dwi, [('dwi', 'in_file')]),
(inputnode, mask_dwi, [('mask', 'in_file2')]),
(mask_dwi, slice_dwi, [('out_file', 'in_file')]),
(inputnode, slice_mask, [('mask', 'in_file')])
])

xfibres = pe.MapNode(interface=fsl.OldXFibres(), name="xfibres",
xfib_if = fsl.XFibres(**params)
xfibres = pe.MapNode(xfib_if, name='xfibres',
iterfield=['dwi', 'mask'])

# Normal set of parameters
xfibres.inputs.n_fibres = 2
xfibres.inputs.fudge = 1
xfibres.inputs.burn_in = 1000
xfibres.inputs.n_jumps = 1250
xfibres.inputs.sample_every = 25
xfibres.inputs.model = 1
xfibres.inputs.non_linear = True
xfibres.inputs.update_proposal_every = 24

inputnode = pe.Node(interface=util.IdentityInterface(fields=["thsamples",
"phsamples",
"fsamples",
"dyads",
"mean_dsamples",
"mask"]),
name="inputnode")

merge_thsamples = pe.MapNode(fsl.Merge(dimension="z"),
name="merge_thsamples", iterfield=['in_files'])
merge_phsamples = pe.MapNode(fsl.Merge(dimension="z"),
name="merge_phsamples", iterfield=['in_files'])
merge_fsamples = pe.MapNode(fsl.Merge(dimension="z"),
name="merge_fsamples", iterfield=['in_files'])

merge_mean_dsamples = pe.Node(fsl.Merge(dimension="z"),
name="merge_mean_dsamples")

mean_thsamples = pe.MapNode(fsl.ImageMaths(op_string="-Tmean"),
name="mean_thsamples", iterfield=['in_file'])
mean_phsamples = pe.MapNode(fsl.ImageMaths(op_string="-Tmean"),
name="mean_phsamples", iterfield=['in_file'])
mean_fsamples = pe.MapNode(fsl.ImageMaths(op_string="-Tmean"),
name="mean_fsamples", iterfield=['in_file'])
make_dyads = pe.MapNode(fsl.MakeDyadicVectors(), name="make_dyads",
iterfield=['theta_vol', 'phi_vol'])

postproc = pe.Workflow(name="postproc")

postproc.connect(
[(inputnode, merge_thsamples, [(('thsamples', transpose), 'in_files')]),
(inputnode, merge_phsamples, [((
'phsamples', transpose), 'in_files')]),
(inputnode, merge_fsamples, [((
'fsamples', transpose), 'in_files')]),
(inputnode, merge_mean_dsamples, [
('mean_dsamples', 'in_files')]),

(merge_thsamples, mean_thsamples, [
('merged_file', 'in_file')]),
(merge_phsamples, mean_phsamples, [
('merged_file', 'in_file')]),
(merge_fsamples, mean_fsamples, [
('merged_file', 'in_file')]),
(merge_thsamples, make_dyads, [
('merged_file', 'theta_vol')]),
(merge_phsamples, make_dyads, [
('merged_file', 'phi_vol')]),
(inputnode, make_dyads, [('mask', 'mask')]),
])

inputnode = pe.Node(interface=util.IdentityInterface(fields=["dwi",
"mask",
"bvecs",
"bvals"]),
name="inputnode")

bedpostx = pe.Workflow(name=name)
bedpostx.connect([(inputnode, preproc, [('mask', 'inputnode.mask')]),
(inputnode, preproc, [('dwi', 'inputnode.dwi')]),

(preproc, xfibres, [('slice_dwi.out_files', 'dwi'),
('slice_mask.out_files', 'mask')]),
(inputnode, xfibres, [('bvals', 'bvals')]),
(inputnode, xfibres, [('bvecs', 'bvecs')]),

(inputnode, postproc, [('mask', 'inputnode.mask')]),
(xfibres, postproc, [
('thsamples', 'inputnode.thsamples'),
('phsamples',
'inputnode.phsamples'),
('fsamples', 'inputnode.fsamples'),
('dyads', 'inputnode.dyads'),
('mean_dsamples', 'inputnode.mean_dsamples')]),
out_fields = xfib_if.output_spec().get().keys()

outputnode = pe.Node(niu.IdentityInterface(fields=out_fields),
name='outputnode')

wf = pe.Workflow(name=name)
wf.connect([
(inputnode, slice_dwi, [('dwi', 'in_file')]),
(inputnode, slice_msk, [('mask', 'in_file')]),
(slice_dwi, mask_dwi, [('out_files', 'in_file')]),
(slice_msk, mask_dwi, [('out_files', 'in_file2')]),
(slice_dwi, xfibres, [('out_files', 'dwi')]),
(mask_dwi, xfibres, [('out_file', 'mask')]),
(inputnode, xfibres, [('bvecs', 'bvecs'),
('bvals', 'bvals')]),
(xfibres, outputnode, [((f, transpose), f) for f in out_fields])
])

outputnode = pe.Node(
interface=util.IdentityInterface(fields=["thsamples",
"phsamples",
"fsamples",
"mean_thsamples",
"mean_phsamples",
"mean_fsamples",
"dyads",
"dyads_dispersion"]),
name="outputnode")
bedpostx.connect(
[(postproc, outputnode, [("merge_thsamples.merged_file", "thsamples"),
("merge_phsamples.merged_file",
"phsamples"),
("merge_fsamples.merged_file",
"fsamples"),
("mean_thsamples.out_file",
"mean_thsamples"),
("mean_phsamples.out_file",
"mean_phsamples"),
("mean_fsamples.out_file",
"mean_fsamples"),
("make_dyads.dyads", "dyads"),
("make_dyads.dispersion", "dyads_dispersion")])
])
return bedpostx

return wf