1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
# -*- coding: utf-8 -*-
"""The bru2nii module provides basic functions for dicom conversion
"""
import os
from .base import (
CommandLine,
CommandLineInputSpec,
traits,
TraitedSpec,
isdefined,
File,
Directory,
)
class Bru2InputSpec(CommandLineInputSpec):
input_dir = Directory(
desc="Input Directory", exists=True, mandatory=True, position=-1, argstr="%s"
)
actual_size = traits.Bool(
argstr="-a",
desc="Keep actual size - otherwise x10 scale so animals match human.",
)
force_conversion = traits.Bool(
argstr="-f",
desc="Force conversion of localizers images (multiple slice " "orientations).",
)
compress = traits.Bool(argstr="-z", desc='gz compress images (".nii.gz").')
append_protocol_name = traits.Bool(
argstr="-p", desc="Append protocol name to output filename."
)
output_filename = traits.Str(
argstr="-o %s",
desc='Output filename (".nii" will be appended, or ".nii.gz" if the "-z" compress option is selected)',
genfile=True,
)
class Bru2OutputSpec(TraitedSpec):
nii_file = File(exists=True)
class Bru2(CommandLine):
"""Uses bru2nii's Bru2 to convert Bruker files
Examples
========
>>> from nipype.interfaces.bru2nii import Bru2
>>> converter = Bru2()
>>> converter.inputs.input_dir = "brukerdir"
>>> converter.cmdline # doctest: +ELLIPSIS
'Bru2 -o .../data/brukerdir brukerdir'
"""
input_spec = Bru2InputSpec
output_spec = Bru2OutputSpec
_cmd = "Bru2"
def _list_outputs(self):
outputs = self._outputs().get()
if isdefined(self.inputs.output_filename):
output_filename1 = os.path.abspath(self.inputs.output_filename)
else:
output_filename1 = self._gen_filename("output_filename")
if self.inputs.compress:
outputs["nii_file"] = output_filename1 + ".nii.gz"
else:
outputs["nii_file"] = output_filename1 + ".nii"
return outputs
def _gen_filename(self, name):
if name == "output_filename":
outfile = os.path.join(
os.getcwd(), os.path.basename(os.path.normpath(self.inputs.input_dir))
)
return outfile
|