|
| 1 | +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 2 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 3 | +# -*- coding: utf-8 -*- |
| 4 | + |
| 5 | +""" |
| 6 | + Change directory to provide relative paths for doctests |
| 7 | + >>> import os |
| 8 | + >>> filepath = os.path.dirname(os.path.realpath(__file__ )) |
| 9 | + >>> datadir = os.path.realpath(os.path.join(filepath, |
| 10 | + ... '../../testing/data')) |
| 11 | + >>> os.chdir(datadir) |
| 12 | +
|
| 13 | +""" |
| 14 | +import os |
| 15 | +import os.path as op |
| 16 | + |
| 17 | +from base import MRTrix3BaseInputSpec, MRTrix3Base |
| 18 | +from nipype.interfaces.base import ( |
| 19 | + CommandLineInputSpec, CommandLine, traits, TraitedSpec, File) |
| 20 | + |
| 21 | +from nipype.utils.filemanip import split_filename |
| 22 | +from nipype.interfaces.traits_extension import isdefined |
| 23 | + |
| 24 | + |
| 25 | +class LabelConfigInputSpec(CommandLineInputSpec): |
| 26 | + in_file = File(exists=True, argstr='%s', mandatory=True, position=-3, |
| 27 | + desc='input anatomical image') |
| 28 | + in_config = File(exists=True, argstr='%s', position=-2, |
| 29 | + desc='connectome configuration file') |
| 30 | + out_file = File( |
| 31 | + 'parcellation.mif', argstr='%s', mandatory=True, position=-1, |
| 32 | + usedefault=True, desc='output file after processing') |
| 33 | + |
| 34 | + lut_basic = File(argstr='-lut_basic %s', desc='get information from ' |
| 35 | + 'a basic lookup table consisting of index / name pairs') |
| 36 | + lut_fs = File(argstr='-lut_freesurfer %s', desc='get information from ' |
| 37 | + 'a FreeSurfer lookup table(typically "FreeSurferColorLUT' |
| 38 | + '.txt")') |
| 39 | + lut_aal = File(argstr='-lut_aal %s', desc='get information from the AAL ' |
| 40 | + 'lookup table (typically "ROI_MNI_V4.txt")') |
| 41 | + lut_itksnap = File(argstr='-lut_itksnap %s', desc='get information from an' |
| 42 | + ' ITK - SNAP lookup table(this includes the IIT atlas ' |
| 43 | + 'file "LUT_GM.txt")') |
| 44 | + spine = File(argstr='-spine %s', desc='provide a manually-defined ' |
| 45 | + 'segmentation of the base of the spine where the streamlines' |
| 46 | + ' terminate, so that this can become a node in the connection' |
| 47 | + ' matrix.') |
| 48 | + nthreads = traits.Int( |
| 49 | + argstr='-nthreads %d', desc='number of threads. if zero, the number' |
| 50 | + ' of available cpus will be used') |
| 51 | + |
| 52 | + |
| 53 | +class LabelConfigOutputSpec(TraitedSpec): |
| 54 | + out_file = File(exists=True, desc='the output response file') |
| 55 | + |
| 56 | + |
| 57 | +class LabelConfig(MRTrix3Base): |
| 58 | + |
| 59 | + """ |
| 60 | + Generate anatomical information necessary for Anatomically |
| 61 | + Constrained Tractography (ACT). |
| 62 | +
|
| 63 | + Example |
| 64 | + ------- |
| 65 | +
|
| 66 | + >>> import nipype.interfaces.mrtrix3 as mrt |
| 67 | + >>> labels = mrt.LabelConfig() |
| 68 | + >>> labels.inputs.in_file = 'aparc+aseg.nii.gz' |
| 69 | + >>> labels.inputs.in_config = 'mrtrix3_labelconfig.txt' |
| 70 | + >>> labels.cmdline # doctest: +ELLIPSIS |
| 71 | + 'labelconfig aparc+aseg.nii.gz mrtrix3_labelconfig.txt parcellation.mif' |
| 72 | + >>> labels.run() # doctest: +SKIP |
| 73 | + """ |
| 74 | + |
| 75 | + _cmd = 'labelconfig:' |
| 76 | + input_spec = LabelConfigInputSpec |
| 77 | + output_spec = LabelConfigOutputSpec |
| 78 | + |
| 79 | + def _parse_inputs(self, skip=None): |
| 80 | + if skip is None: |
| 81 | + skip = [] |
| 82 | + |
| 83 | + if not isdefined(self.inputs.in_config): |
| 84 | + from distutils.spawn import find_executable |
| 85 | + path = op.dirname(find_executable(self._cmd)) |
| 86 | + self.inputs.in_config = op.abspath( |
| 87 | + op.join(path, '../src/dwi/tractography/connectomics/' |
| 88 | + 'example_configs/fs_default.txt')) |
| 89 | + return super(LabelConfig, self)._parse_inputs(skip=skip) |
| 90 | + |
| 91 | + def _list_outputs(self): |
| 92 | + outputs = self.output_spec().get() |
| 93 | + outputs['out_file'] = op.abspath(self.inputs.out_file) |
| 94 | + return outputs |
0 commit comments