Skip to content

Commit a01275f

Browse files
authored
Merge pull request #1992 from satra/fix/compcor
Fix/compcor
2 parents e48c9c8 + 85b5692 commit a01275f

File tree

9 files changed

+277
-248
lines changed

9 files changed

+277
-248
lines changed

doc/documentation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Previous versions: `0.12.0 <http://nipype.readthedocs.io/en/0.12.0/>`_ `0.11.0
2929
:maxdepth: 2
3030

3131
users/index
32-
32+
3333
.. toctree::
3434
:maxdepth: 1
3535

doc/users/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Execution
145145
crashfiles allow interactive debugging and rerunning of nodes, while text
146146
crashfiles allow portability across machines and shorter load time.
147147
(possible values: ``pklz`` and ``txt``; default value: ``pklz``)
148-
148+
149149
Example
150150
~~~~~~~
151151

nipype/algorithms/confounds.py

Lines changed: 217 additions & 200 deletions
Large diffs are not rendered by default.

nipype/algorithms/tests/test_auto_ACompCor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
def test_ACompCor_inputs():
77
input_map = dict(components_file=dict(usedefault=True,
88
),
9-
header=dict(),
9+
header_prefix=dict(),
1010
ignore_exception=dict(nohash=True,
1111
usedefault=True,
1212
),
13-
mask_file=dict(),
13+
mask_files=dict(),
14+
mask_index=dict(requires=['mask_files'],
15+
xor=['merge_method'],
16+
),
17+
merge_method=dict(requires=['mask_files'],
18+
xor=['mask_index'],
19+
),
1420
num_components=dict(usedefault=True,
1521
),
1622
realigned_file=dict(mandatory=True,

nipype/algorithms/tests/test_auto_TCompCor.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
def test_TCompCor_inputs():
77
input_map = dict(components_file=dict(usedefault=True,
88
),
9-
header=dict(),
9+
header_prefix=dict(),
1010
ignore_exception=dict(nohash=True,
1111
usedefault=True,
1212
),
13-
mask_file=dict(),
13+
mask_files=dict(),
14+
mask_index=dict(requires=['mask_files'],
15+
xor=['merge_method'],
16+
),
17+
merge_method=dict(requires=['mask_files'],
18+
xor=['mask_index'],
19+
),
1420
num_components=dict(usedefault=True,
1521
),
1622
percentile_threshold=dict(usedefault=True,
@@ -30,22 +36,8 @@ def test_TCompCor_inputs():
3036

3137

3238
def test_TCompCor_outputs():
33-
output_map = dict(components_file=dict(usedefault=True,
34-
),
35-
header=dict(),
36-
high_variance_mask=dict(),
37-
ignore_exception=dict(nohash=True,
38-
usedefault=True,
39-
),
40-
mask_file=dict(),
41-
num_components=dict(usedefault=True,
42-
),
43-
realigned_file=dict(mandatory=True,
44-
),
45-
regress_poly_degree=dict(usedefault=True,
46-
),
47-
use_regress_poly=dict(usedefault=True,
48-
),
39+
output_map = dict(components_file=dict(),
40+
high_variance_masks=dict(),
4941
)
5042
outputs = TCompCor.output_spec()
5143

nipype/algorithms/tests/test_compcor.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99
from ...testing import utils
1010
from ..confounds import CompCor, TCompCor, ACompCor
11-
from ...interfaces.base import Undefined
1211

1312

1413
class TestCompCor():
@@ -48,11 +47,13 @@ def test_compcor(self):
4847
['-0.1246655485', '-0.1235705610']]
4948

5049
self.run_cc(CompCor(realigned_file=self.realigned_file,
51-
mask_files=self.mask_files),
50+
mask_files=self.mask_files,
51+
mask_index=0),
5252
expected_components)
5353

5454
self.run_cc(ACompCor(realigned_file=self.realigned_file,
5555
mask_files=self.mask_files,
56+
mask_index=0,
5657
components_file='acc_components_file'),
5758
expected_components, 'aCompCor')
5859

@@ -64,40 +65,44 @@ def test_tcompcor(self):
6465
['0.4566907310', '0.6983205193'],
6566
['-0.7132557407', '0.1340170559'],
6667
['0.5022537643', '-0.5098322262'],
67-
['-0.1342351356', '0.1407855119']], 'tCompCor')
68+
['-0.1342351356', '0.1407855119']],
69+
'tCompCor')
6870

6971
def test_tcompcor_no_percentile(self):
7072
ccinterface = TCompCor(realigned_file=self.realigned_file)
7173
ccinterface.run()
7274

73-
mask = nb.load('mask.nii').get_data()
75+
mask = nb.load('mask_000.nii.gz').get_data()
7476
num_nonmasked_voxels = np.count_nonzero(mask)
7577
assert num_nonmasked_voxels == 1
7678

7779
def test_compcor_no_regress_poly(self):
7880
self.run_cc(CompCor(realigned_file=self.realigned_file,
79-
mask_files=self.mask_files,
80-
use_regress_poly=False), [['0.4451946442', '-0.7683311482'],
81-
['-0.4285129505', '-0.0926034137'],
82-
['0.5721540256', '0.5608764842'],
83-
['-0.5367548139', '0.0059943226'],
84-
['-0.0520809054', '0.2940637551']])
81+
mask_files=self.mask_files,
82+
mask_index=0,
83+
use_regress_poly=False),
84+
[['0.4451946442', '-0.7683311482'],
85+
['-0.4285129505', '-0.0926034137'],
86+
['0.5721540256', '0.5608764842'],
87+
['-0.5367548139', '0.0059943226'],
88+
['-0.0520809054', '0.2940637551']])
8589

8690
def test_tcompcor_asymmetric_dim(self):
8791
asymmetric_shape = (2, 3, 4, 5)
8892
asymmetric_data = utils.save_toy_nii(np.zeros(asymmetric_shape),
8993
'asymmetric.nii')
9094

9195
TCompCor(realigned_file=asymmetric_data).run()
92-
assert nb.load('mask.nii').get_data().shape == asymmetric_shape[:3]
96+
assert nb.load('mask_000.nii.gz').get_data().shape == asymmetric_shape[:3]
9397

9498
def test_compcor_bad_input_shapes(self):
9599
shape_less_than = (1, 2, 2, 5) # dim 0 is < dim 0 of self.mask_files (2)
96100
shape_more_than = (3, 3, 3, 5) # dim 0 is > dim 0 of self.mask_files (2)
97101

98102
for data_shape in (shape_less_than, shape_more_than):
99103
data_file = utils.save_toy_nii(np.zeros(data_shape), 'temp.nii')
100-
interface = CompCor(realigned_file=data_file, mask_files=self.mask_files)
104+
interface = CompCor(realigned_file=data_file,
105+
mask_files=self.mask_files[0])
101106
with pytest.raises(ValueError, message="Dimension mismatch"): interface.run()
102107

103108
def test_tcompcor_bad_input_dim(self):
@@ -112,19 +117,25 @@ def test_tcompcor_merge_intersect_masks(self):
112117
mask_files=self.mask_files,
113118
merge_method=method).run()
114119
if method == 'union':
115-
assert np.array_equal(nb.load('mask.nii').get_data(),
120+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
116121
([[[0,0],[0,0]],[[0,0],[1,0]]]))
117122
if method == 'intersect':
118-
assert np.array_equal(nb.load('mask.nii').get_data(),
123+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
119124
([[[0,0],[0,0]],[[0,1],[0,0]]]))
120125

121126
def test_tcompcor_index_mask(self):
122127
TCompCor(realigned_file=self.realigned_file,
123128
mask_files=self.mask_files,
124129
mask_index=1).run()
125-
assert np.array_equal(nb.load('mask.nii').get_data(),
130+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
126131
([[[0,0],[0,0]],[[0,1],[0,0]]]))
127132

133+
def test_tcompcor_multi_mask_no_index(self):
134+
interface = TCompCor(realigned_file=self.realigned_file,
135+
mask_files=self.mask_files)
136+
with pytest.raises(ValueError, message='more than one mask file'):
137+
interface.run()
138+
128139
def run_cc(self, ccinterface, expected_components, expected_header='CompCor'):
129140
# run
130141
ccresult = ccinterface.run()
@@ -137,12 +148,15 @@ def run_cc(self, ccinterface, expected_components, expected_header='CompCor'):
137148
assert ccinterface.inputs.num_components == 6
138149

139150
with open(ccresult.outputs.components_file, 'r') as components_file:
140-
expected_n_components = min(ccinterface.inputs.num_components, self.fake_data.shape[3])
151+
expected_n_components = min(ccinterface.inputs.num_components,
152+
self.fake_data.shape[3])
141153

142154
components_data = [line.split('\t') for line in components_file]
143155

144-
header = components_data.pop(0) # the first item will be '#', we can throw it out
145-
expected_header = [expected_header + str(i) for i in range(expected_n_components)]
156+
# the first item will be '#', we can throw it out
157+
header = components_data.pop(0)
158+
expected_header = [expected_header + '{:02d}'.format(i) for i in
159+
range(expected_n_components)]
146160
for i, heading in enumerate(header):
147161
assert expected_header[i] in heading
148162

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ class QwarpPlusMinusOutputSpec(TraitedSpec):
24172417

24182418

24192419
class QwarpPlusMinus(CommandLine):
2420-
"""A version of 3dQwarp for performing field susceptibility correction
2420+
"""A version of 3dQwarp for performing field susceptibility correction
24212421
using two images with opposing phase encoding directions.
24222422
24232423
For complete details, see the `3dQwarp Documentation.
@@ -2434,7 +2434,7 @@ class QwarpPlusMinus(CommandLine):
24342434
>>> qwarp.cmdline # doctest: +ALLOW_UNICODE
24352435
'3dQwarp -prefix Qwarp.nii.gz -plusminus -base sub-01_dir-RL_epi.nii.gz -nopadWARP -source sub-01_dir-LR_epi.nii.gz'
24362436
>>> res = warp.run() # doctest: +SKIP
2437-
2437+
24382438
"""
24392439
_cmd = '3dQwarp -prefix Qwarp.nii.gz -plusminus'
24402440
input_spec = QwarpPlusMinusInputSpec

nipype/interfaces/afni/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class FWHMx(AFNICommandBase):
695695
_cmd = '3dFWHMx'
696696
input_spec = FWHMxInputSpec
697697
output_spec = FWHMxOutputSpec
698-
698+
699699
references_ = [{'entry': BibTeX('@article{CoxReynoldsTaylor2016,'
700700
'author={R.W. Cox, R.C. Reynolds, and P.A. Taylor},'
701701
'title={AFNI and clustering: false positive rates redux},'

nipype/interfaces/fsl/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RobustFOVInputSpec(FSLCommandInputSpec):
7373
brainsize = traits.Int(desc=('size of brain in z-dimension (default '
7474
'170mm/150mm)'),
7575
argstr='-b %d')
76-
out_transform = File(desc=("Transformation matrix in_file to out_roi "
76+
out_transform = File(desc=("Transformation matrix in_file to out_roi "
7777
"output name"),
7878
argstr="-m %s",
7979
name_source=['in_file'], hash_files=False,
@@ -83,17 +83,17 @@ class RobustFOVInputSpec(FSLCommandInputSpec):
8383
class RobustFOVOutputSpec(TraitedSpec):
8484
out_roi = File(exists=True, desc="ROI volume output name")
8585
out_transform = File(exists=True,
86-
desc=("Transformation matrix in_file to out_roi "
86+
desc=("Transformation matrix in_file to out_roi "
8787
"output name"))
8888

8989

9090
class RobustFOV(FSLCommand):
9191
"""Automatically crops an image removing lower head and neck.
92-
93-
Interface is stable 5.0.0 to 5.0.9, but default brainsize changed from
92+
93+
Interface is stable 5.0.0 to 5.0.9, but default brainsize changed from
9494
150mm to 170mm.
9595
"""
96-
96+
9797
_cmd = 'robustfov'
9898
input_spec = RobustFOVInputSpec
9999
output_spec = RobustFOVOutputSpec

0 commit comments

Comments
 (0)