Skip to content

Commit 6b7bda4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into update_petsurfer
2 parents 75f0ba0 + d2f4953 commit 6b7bda4

File tree

7 files changed

+66
-29
lines changed

7 files changed

+66
-29
lines changed

.zenodo.json

+5
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,11 @@
911911
"name": "Wu, Jianxiao",
912912
"orcid": "0000-0002-4866-272X",
913913
},
914+
{
915+
"affiliation": "Lund University",
916+
"name": "Anijärv, Toomas Erik",
917+
"orcid": "0000-0002-3650-4230",
918+
},
914919
],
915920
"keywords": [
916921
"neuroimaging",

nipype/interfaces/mrtrix3/tests/test_auto_Generate5tt.py

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def test_Generate5tt_inputs():
3737
),
3838
in_file=dict(
3939
argstr="%s",
40-
extensions=None,
4140
mandatory=True,
4241
position=-2,
4342
),

nipype/interfaces/mrtrix3/tests/test_auto_MRTransform.py

-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ def test_MRTransform_inputs():
1212
),
1313
debug=dict(
1414
argstr="-debug",
15-
position=1,
1615
),
1716
environ=dict(
1817
nohash=True,
1918
usedefault=True,
2019
),
2120
flip_x=dict(
2221
argstr="-flipx",
23-
position=1,
2422
),
2523
grad_file=dict(
2624
argstr="-grad %s",
@@ -45,12 +43,10 @@ def test_MRTransform_inputs():
4543
),
4644
invert=dict(
4745
argstr="-inverse",
48-
position=1,
4946
),
5047
linear_transform=dict(
5148
argstr="-linear %s",
5249
extensions=None,
53-
position=1,
5450
),
5551
nthreads=dict(
5652
argstr="-nthreads %d",
@@ -71,26 +67,21 @@ def test_MRTransform_inputs():
7167
),
7268
quiet=dict(
7369
argstr="-quiet",
74-
position=1,
7570
),
7671
reference_image=dict(
7772
argstr="-reference %s",
7873
extensions=None,
79-
position=1,
8074
),
8175
replace_transform=dict(
8276
argstr="-replace",
83-
position=1,
8477
),
8578
template_image=dict(
8679
argstr="-template %s",
8780
extensions=None,
88-
position=1,
8981
),
9082
transformation_file=dict(
9183
argstr="-transform %s",
9284
extensions=None,
93-
position=1,
9485
),
9586
)
9687
inputs = MRTransform.input_spec()

nipype/interfaces/mrtrix3/utils.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
traits,
1212
TraitedSpec,
1313
File,
14+
Directory,
1415
InputMultiPath,
1516
isdefined,
1617
)
@@ -224,13 +225,19 @@ class Generate5ttInputSpec(MRTrix3BaseInputSpec):
224225
"fsl",
225226
"gif",
226227
"freesurfer",
228+
"hsvs",
227229
argstr="%s",
228230
position=-3,
229231
mandatory=True,
230232
desc="tissue segmentation algorithm",
231233
)
232-
in_file = File(
233-
exists=True, argstr="%s", mandatory=True, position=-2, desc="input image"
234+
in_file = traits.Either(
235+
File(exists=True),
236+
Directory(exists=True),
237+
argstr="%s",
238+
mandatory=True,
239+
position=-2,
240+
desc="input image / directory",
234241
)
235242
out_file = File(argstr="%s", mandatory=True, position=-1, desc="output image")
236243

@@ -822,13 +829,11 @@ class MRTransformInputSpec(MRTrix3BaseInputSpec):
822829
)
823830
invert = traits.Bool(
824831
argstr="-inverse",
825-
position=1,
826832
desc="Invert the specified transform before using it",
827833
)
828834
linear_transform = File(
829835
exists=True,
830836
argstr="-linear %s",
831-
position=1,
832837
desc=(
833838
"Specify a linear transform to apply, in the form of a 3x4 or 4x4 ascii file. "
834839
"Note the standard reverse convention is used, "
@@ -838,38 +843,32 @@ class MRTransformInputSpec(MRTrix3BaseInputSpec):
838843
)
839844
replace_transform = traits.Bool(
840845
argstr="-replace",
841-
position=1,
842846
desc="replace the current transform by that specified, rather than applying it to the current transform",
843847
)
844848
transformation_file = File(
845849
exists=True,
846850
argstr="-transform %s",
847-
position=1,
848851
desc="The transform to apply, in the form of a 4x4 ascii file.",
849852
)
850853
template_image = File(
851854
exists=True,
852855
argstr="-template %s",
853-
position=1,
854856
desc="Reslice the input image to match the specified template image.",
855857
)
856858
reference_image = File(
857859
exists=True,
858860
argstr="-reference %s",
859-
position=1,
860861
desc="in case the transform supplied maps from the input image onto a reference image, use this option to specify the reference. Note that this implicitly sets the -replace option.",
861862
)
862863
flip_x = traits.Bool(
863864
argstr="-flipx",
864-
position=1,
865865
desc="assume the transform is supplied assuming a coordinate system with the x-axis reversed relative to the MRtrix convention (i.e. x increases from right to left). This is required to handle transform matrices produced by FSL's FLIRT command. This is only used in conjunction with the -reference option.",
866866
)
867867
quiet = traits.Bool(
868868
argstr="-quiet",
869-
position=1,
870869
desc="Do not display information messages or progress status.",
871870
)
872-
debug = traits.Bool(argstr="-debug", position=1, desc="Display debugging messages.")
871+
debug = traits.Bool(argstr="-debug", desc="Display debugging messages.")
873872

874873

875874
class MRTransformOutputSpec(TraitedSpec):

nipype/interfaces/utility/csv.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""CSV Handling utilities
44
"""
5+
import csv
56
from ..base import traits, TraitedSpec, DynamicTraitedSpec, File, BaseInterface
67
from ..io import add_traits
78

@@ -13,6 +14,7 @@ class CSVReaderInputSpec(DynamicTraitedSpec, TraitedSpec):
1314
header = traits.Bool(
1415
False, usedefault=True, desc="True if the first line is a column header"
1516
)
17+
delimiter = traits.String(",", usedefault=True, desc="Delimiter to use.")
1618

1719

1820
class CSVReader(BaseInterface):
@@ -52,14 +54,11 @@ def _append_entry(self, outputs, entry):
5254
outputs[key].append(value)
5355
return outputs
5456

55-
def _parse_line(self, line):
56-
line = line.replace("\n", "")
57-
entry = [x.strip() for x in line.split(",")]
58-
return entry
59-
6057
def _get_outfields(self):
6158
with open(self.inputs.in_file) as fid:
62-
entry = self._parse_line(fid.readline())
59+
reader = csv.reader(fid, delimiter=self.inputs.delimiter)
60+
61+
entry = next(reader)
6362
if self.inputs.header:
6463
self._outfields = tuple(entry)
6564
else:
@@ -82,10 +81,10 @@ def _list_outputs(self):
8281
for key in self._outfields:
8382
outputs[key] = [] # initialize outfields
8483
with open(self.inputs.in_file) as fid:
85-
for line in fid.readlines():
84+
reader = csv.reader(fid, delimiter=self.inputs.delimiter)
85+
for entry in reader:
8686
if self.inputs.header and isHeader: # skip header line
8787
isHeader = False
8888
continue
89-
entry = self._parse_line(line)
9089
outputs = self._append_entry(outputs, entry)
9190
return outputs

nipype/interfaces/utility/tests/test_auto_CSVReader.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
def test_CSVReader_inputs():
66
input_map = dict(
7+
delimiter=dict(
8+
usedefault=True,
9+
),
710
header=dict(
811
usedefault=True,
912
),

nipype/interfaces/utility/tests/test_csv.py

+41
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,44 @@ def test_csvReader(tmpdir):
2626
assert out.outputs.column_0 == ["foo", "bar", "baz"]
2727
assert out.outputs.column_1 == ["hello", "world", "goodbye"]
2828
assert out.outputs.column_2 == ["300.1", "5", "0.3"]
29+
30+
31+
def test_csvReader_quoted(tmpdir):
32+
header = "files,labels,erosion\n"
33+
lines = ['foo,"hello, world",300.1\n']
34+
35+
name = tmpdir.join("testfile.csv").strpath
36+
with open(name, "w") as fid:
37+
reader = utility.CSVReader()
38+
fid.writelines(lines)
39+
fid.flush()
40+
reader.inputs.in_file = name
41+
out = reader.run()
42+
43+
assert out.outputs.column_0 == ["foo"]
44+
assert out.outputs.column_1 == ["hello, world"]
45+
assert out.outputs.column_2 == ["300.1"]
46+
47+
48+
def test_csvReader_tabs(tmpdir):
49+
header = "files\tlabels\terosion\n"
50+
lines = ["foo\thello\t300.1\n", "bar\tworld\t5\n", "baz\tgoodbye\t0.3\n"]
51+
for x in range(2):
52+
name = tmpdir.join("testfile.csv").strpath
53+
with open(name, "w") as fid:
54+
reader = utility.CSVReader(delimiter="\t")
55+
if x % 2 == 0:
56+
fid.write(header)
57+
reader.inputs.header = True
58+
fid.writelines(lines)
59+
fid.flush()
60+
reader.inputs.in_file = name
61+
out = reader.run()
62+
if x % 2 == 0:
63+
assert out.outputs.files == ["foo", "bar", "baz"]
64+
assert out.outputs.labels == ["hello", "world", "goodbye"]
65+
assert out.outputs.erosion == ["300.1", "5", "0.3"]
66+
else:
67+
assert out.outputs.column_0 == ["foo", "bar", "baz"]
68+
assert out.outputs.column_1 == ["hello", "world", "goodbye"]
69+
assert out.outputs.column_2 == ["300.1", "5", "0.3"]

0 commit comments

Comments
 (0)