|
| 1 | + |
| 2 | +"""The bru2nii module provides basic functions for dicom conversion |
| 3 | +
|
| 4 | + Change directory to provide relative paths for doctests |
| 5 | + >>> import os |
| 6 | + >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) |
| 7 | + >>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data')) |
| 8 | + >>> os.chdir(datadir) |
| 9 | +""" |
| 10 | + |
| 11 | +from nipype.interfaces.base import (CommandLine, CommandLineInputSpec, traits, TraitedSpec, isdefined, File, Directory) |
| 12 | +import os |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +class Bru2InputSpec(CommandLineInputSpec): |
| 17 | + input_dir = Directory(desc = "Input Directory", exists=True, mandatory=True, position=-1, argstr="%s") |
| 18 | + actual_size = traits.Bool(argstr='-a', desc="Keep actual size - otherwise x10 scale so animals match human.") |
| 19 | + force_conversion = traits.Bool(argstr='-f', desc="Force conversion of localizers images (multiple slice orientations).") |
| 20 | + append_protocol_name = traits.Bool(argstr='-p', desc="Append protocol name to output filename.") |
| 21 | + output_filename = traits.Str(argstr="-o %s", desc="Output filename ('.nii' will be appended)", genfile=True) |
| 22 | + |
| 23 | +class Bru2OutputSpec(TraitedSpec): |
| 24 | + nii_file = File(exists=True) |
| 25 | + |
| 26 | +class Bru2(CommandLine): |
| 27 | + """Uses bru2nii's Bru2 to convert Bruker files |
| 28 | +
|
| 29 | + Examples |
| 30 | + ======== |
| 31 | +
|
| 32 | + >>> from nipype.interfaces.bru2nii import Bru2 |
| 33 | + >>> converter = Bru2() |
| 34 | + >>> converter.inputs.input_dir = "brukerdir" |
| 35 | + >>> converter.cmdline # doctest: +ELLIPSIS |
| 36 | + 'Bru2 -o .../nipype/nipype/testing/data/brukerdir brukerdir' |
| 37 | + """ |
| 38 | + input_spec = Bru2InputSpec |
| 39 | + output_spec = Bru2OutputSpec |
| 40 | + _cmd = "Bru2" |
| 41 | + |
| 42 | + def _list_outputs(self): |
| 43 | + outputs = self._outputs().get() |
| 44 | + if isdefined(self.inputs.output_filename): |
| 45 | + output_filename1 = self.inputs.output_filename |
| 46 | + else: |
| 47 | + output_filename1 = self._gen_filename('output_filename') |
| 48 | + outputs["nii_file"] = output_filename1+".nii" |
| 49 | + return outputs |
| 50 | + |
| 51 | + def _gen_filename(self, name): |
| 52 | + if name == 'output_filename': |
| 53 | + outfile = os.path.join(os.getcwd(),os.path.basename(os.path.normpath(self.inputs.input_dir))) |
| 54 | + return outfile |
0 commit comments