Skip to content

[ENH] added interface for dcm2niix #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 27, 2016
Merged

[ENH] added interface for dcm2niix #1435

merged 25 commits into from
Apr 27, 2016

Conversation

mgxd
Copy link
Member

@mgxd mgxd commented Apr 15, 2016

support for @neurolabusc's dcm2niix converter - compatible upto 4.12.16 version

@@ -180,3 +180,127 @@ def _gen_filename(self, name):
f.close()
return config_file
return None

## dcm2niix update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

@satra
Copy link
Member

satra commented Apr 19, 2016

@mgxd - could you again merge with current upstream master? and also run make check-before-commit

@DimitriPapadopoulos
Copy link
Contributor

Some initial comments:

  • Under "Examples" the generated cmdline contains options -b and -m which are not available in versions of dcm2niix distributed by NeuroDebian on Ubuntu 14.04 for example. This doesn't seem to bother dcm2niix which seems to be skipping unknown options. No BIDS file is created though so in that case it's not part of the output. Not sure how to handle this.
  • Also I would change Uses MRICRON's dcm2niix to Uses Chris Rorden's dcm2niix or at least Uses MRIcroGL's dcm2niix.

@mgxd
Copy link
Member Author

mgxd commented Apr 20, 2016

@DimitriPapadopoulos Thanks for the comments.

  • If bids option is empty (or doesn't exist), it shouldn't be returned (there's a check for an empty list). Since we'll be transitioning to bids format across all our datasets, it's a useful feature to include.
  • Changed MRIcron's dcm2niix to Chris Rorden's dcm2niix

Let me know if you catch anything else!

@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Apr 20, 2016

I'm not sure it can work in case DICOM file names are not passed as absolute paths.

I'm in a directory with hundreds of DICOM files:

$ cd /foo/bar
$ ls
[...]
20140614163106701.MR.dic
[...]
20140614163106761.MR.dic
[...]
$ 

Then:

>>> from nipype.interfaces.dcm2nii import Dcm2niix
>>> converter = Dcm2niix()
>>> converter.inputs.source_names = ['20140614163106701.MR.dic', '20140614163106761.MR.dic']
>>> converter.inputs.compress = 'i'
>>> converter.inputs.output_dir = '.'
>>> converter.cmdline
'dcm2niix -b y -z i -m n -f %q -o . -s n -v n 20140614163106701.MR.dic'
>>> 

However dcm2niix doesn't seem to be processing paths relative to the current directory:

$dcm2niix -b y -z i -m n -f %q -o . -s n -v n 20140614163106701.MR.dic
Chris Rorden's dcm2niiX version 9Sept2015 (64-bit)
Version 9Sept2015 (64-bit)
Error: unable to find any DICOM images in 
Conversion required 0.000067 seconds.
$ 

unlike dcm2nii:

$ dcm2nii -a y -c y -b config.ini -v y -d y -e y -g y -i n -n y -o . -p y -x n -f n 20140614163106701.MR.dic
Chris Rorden's dcm2nii :: 4AUGUST2014 (Debian) 64bit BSD License
reading preferences file config.ini
0 files in working directory /volatile/070000160913/TEST
Data will be exported to ./
Validating 552 potential DICOM images.
Found 551 DICOM images.
Converting 202/551  volumes: 202
20140614161725601.MR.dic->20140614_154657EPIfacess004a001.nii
[...]
$ 

What about os.path.join(os.getcwd(), ...) at least for file names?

@DimitriPapadopoulos
Copy link
Contributor

From my test directory with 2 DICOM sequences, Dcm2nii and Dcm2niix create 2 NIfTI files.

With Dcm2nii default output file names used to be:

20140614_154657EPIfacess004a001.nii
20140614_154657EPIstopsignals005a001.nii

With Dcm2niix default output file names are:

EP.nii.gz
EPA.nii.gz

I understand the default has changed between dcm2nii and dcm2niix but would it be worth changing the default output format of Dcm2niix from %q to something more like Dcm2nii? Or is Nipype supposed to be as transparent as possible?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 72.489% when pulling 62ca473 on mgxd:master into 60f7630 on nipy:master.

@mgxd
Copy link
Member Author

mgxd commented Apr 20, 2016

@DimitriPapadopoulos

  • When converting a single image, the -s flag should change to 'y'. I was able to successfully convert one of my dicoms:

dcm2niix -b y -z i -m n -f %q -o . -s y -v n 996000-3-1.dcm
Compression will be faster with /usr/local/bin/pigz
Chris Rorden's dcm2niiX version 12Apr2016 (64-bit)
Version 12Apr2016 (64-bit)
Convert 1 DICOM as ./EP (108x108x65x1)
Conversion required 0.240000 seconds.

I've updated the doctest to include the single file flag.
EDIT: It seems the doctest fails with this flag.

  • As for default naming - I have no problem making the output look more like dcm2nii's. I've changed the default from %q to %t%p (time and protocol).

def _run_interface(self, runtime):
new_runtime = super(Dcm2niix, self)._run_interface(runtime)
(self.output_files,
self.bvecs, self.bvals, self.bids) = self._parse_stdout(new_runtime.stdout)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this with and without the bids option?

@DimitriPapadopoulos
Copy link
Contributor

@mgxd
I'm not certain about changeset 3603523:
Unless I'm mistaken it merely modifies the example and switches from the initial use case (converting a directory) that (still) doesn't work to a different use case (converting a single image) that works.
I would have expected the documentation to stay as is and the code to be modified so that the initial example does work (perhaps by adding os.path.join(os.getcwd(), ...) somewhere in the code).

Indeed in single file mode dcm2niix is able to handle relative pathnames:

$ dcm2niix -b y -z i -m n -f %q -o . -s y -v n seminoma.dic
Chris Rorden's dcm2niiX version 9Sept2015 (64-bit)
Version 9Sept2015 (64-bit)
Convert 1 DICOM as ./EP (64x64x40x1)
Conversion required 0.027342 seconds.
$ 

but it cannot convert directories identified by a relative pathname:

$ dcm2niix -b y -z i -m n -f %q -o . -s n -v n seminoma.dic
Chris Rorden's dcm2niiX version 9Sept2015 (64-bit)
Version 9Sept2015 (64-bit)
Error: unable to find any DICOM images in 
Conversion required 0.000075 seconds.
$ 

unlike dcm2nii:

$ dcm2nii -a y -c y -v y -d y -e y -g y -i n -n y -o . -p y -x n -f n seminoma.dic
Chris Rorden's dcm2nii :: 4AUGUST2014 (Debian) 64bit BSD License
0 files in working directory /volatile/000045835265/TEST
Data will be exported to ./
Validating 397 potential DICOM images.
Found 393 DICOM images.
Converting 191/393  volumes: 191
[...]
$ 

I believe Dcm2niix should accept relative pathames outside of single file mode, perhaps by adding os.path.join(os.getcwd(), ...) to the Dcm2niix code (not to the example code). Then the initial example would work.

@neurolabusc
Copy link

@DimitriPapadopoulos
I fixed the relative paths in the 22Apr2016 version of dcm2niix. The fix works on OSX and Linux, not sure about Windows (not sure if '.' is current working directory in Windows).
https://github.com/neurolabusc/dcm2niix

@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Apr 22, 2016

@mgxd

  • Since Chris confirms the relative path issue has been fixed in recent versions of dcm2niix, perhaps it's not worth working around it in nypipe. By the time a new version of nipype is officially released, I guess the recent version of dcm2niix might have made it to NeuroDebian.
  • Also I'm not totally convinced about changing the default NIfTI output file name after all. I was just asking a question about consistency between Dcm2nii and Dcm2niix, not firmly suggesting Dcm2niix should not follow the default behaviour of dcm2niix. Perhaps this should be best discussed and handled at the dcm2nii-dcm2niix level.

Perhaps 3603523 should be reverted then. What do you think? Sorry about that.

@mgxd
Copy link
Member Author

mgxd commented Apr 22, 2016

@DimitriPapadopoulos

  • I agree - since it has been patched in the latest dcm2niix, I'd rather not add a change to this interface and then have to undo it. @satra what do you think?
  • I actually like the new naming better, more information as a default isn't a bad idea. I arbitrarily set the default to sequence anyways.

Thanks for the constant updates @neurolabusc!

@satra
Copy link
Member

satra commented Apr 22, 2016

@mgxd - the one thing i would suggest is going back to the single file example in the doctest


class Dcm2niixInputSpec(CommandLineInputSpec):
source_names = InputMultiPath(File(exists=True), argstr="%s", position=-1,
copyfile=False, mandatory=True, xor=['source_dir'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc missing for all inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know dcm2nii didn't have any either. but that should be fixed as well.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 72.477% when pulling 252a6d6 on mgxd:master into 9121042 on nipy:master.

output_dir = Directory(exists=True, argstr='-o %s', genfile=True,
desc="Output directory")
bids_format = traits.Bool(True, argstr='-b', usedefault=True,
desc="BIDS sidecar")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps change to: Create a BIDS sidecar file

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 72.477% when pulling 269ca84 on mgxd:master into 9bc6c8b on nipy:master.

@satra satra merged commit aeecd2f into nipy:master Apr 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants