Skip to content

Commit bcfcde9

Browse files
authored
[FIX] report proper fold number in labelfold.tsv (#989)
* demonstrate bug * fix
1 parent ebb474d commit bcfcde9

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/stats/utils/getRegressorIdx.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
function [cdtName, regIdx, status] = getRegressorIdx(cdtName, SPM)
22
%
3-
% Gets from the SPM structure the regressors index
4-
% corresponding to the a condition convolved with the
5-
% canonical HRF. This can also look for non convolved conditions to identify a confound regressor.
3+
% Gets from the SPM structure the regressors index corresponding
4+
% to the a condition convolved with the canonical HRF.
5+
% This can also look for non convolved conditions
6+
% to identify a confound regressor.
67
%
78
% Throws a warning if there is no regressor for that condition.
89
%

src/workflows/stats/bidsConcatBetaTmaps.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function bidsConcatBetaTmaps(opt, deleteTmaps)
4444

4545
ffxDir = getFFXdir(subLabel, opt);
4646

47-
load(fullfile(ffxDir, 'SPM.mat'));
47+
load(fullfile(ffxDir, 'SPM.mat'), 'SPM');
4848

4949
model = BidsModel('file', opt.model.file);
5050

@@ -86,7 +86,7 @@ function bidsConcatBetaTmaps(opt, deleteTmaps)
8686
for iSess = 1:numel(SPM.Sess)
8787
tmp(iSess) = ismember(betasIndices, SPM.Sess(iSess).col); %#ok<*AGROW>
8888
end
89-
runs(iContrast, 1) = find(any(tmp, 2));
89+
runs(iContrast, 1) = find(any(tmp, 1));
9090
clear tmp;
9191

9292
parts = strsplit(SPM.xX.name{betasIndices}, ' ');

tests/tests_workflows/test_bidsConcatBetaTmaps.m

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,55 @@ function test_bidsConcatBetaTmapsBasic()
1919
opt.model.file = spm_file(opt.model.file, 'filename', 'model-vismotionMVPA_smdl.json');
2020
opt.model.bm = BidsModel('file', opt.model.file);
2121

22+
tmpDir = tempname;
23+
copyfile(opt.dir.stats, tmpDir);
24+
25+
opt.dir.stats = tmpDir;
26+
27+
% update content of FFX dir to mock 2 sessions
28+
targetDir = fullfile(opt.dir.stats, ...
29+
['sub-' subLabel], ...
30+
'task-vismotion_space-IXI549Space_FWHM-6');
31+
32+
prefixes = {'beta', 'spmT'};
33+
for iPrefix = 1:numel(prefixes)
34+
files = spm_select('FPList', targetDir, ['^' prefixes{iPrefix} '.*nii']);
35+
for i = 1:size(files, 1)
36+
number = sprintf('%04.0f', i + size(files, 1));
37+
newFile = spm_file(files(i, :), ...
38+
'filename', ...
39+
['beta_' number '.nii']);
40+
copyfile(files(i, :), newFile);
41+
end
42+
end
43+
44+
load(fullfile(targetDir, 'SPM.mat'), 'SPM');
45+
46+
names = SPM.xX.name; %#ok<*NODEF>
47+
for i = 1:numel(SPM.xX.name)
48+
new_name = strrep(names{i}, 'Sn(1)', 'Sn(2)');
49+
names{end + 1} = new_name; %#ok<AGROW>
50+
end
51+
SPM.xX.name = names;
52+
53+
SPM.Sess(2).col = SPM.Sess(1).col + numel(SPM.Sess(1).col);
54+
55+
save(fullfile(targetDir, 'SPM.mat'), 'SPM');
56+
57+
%% act
2258
bidsConcatBetaTmaps(opt);
2359

60+
%% assert
2461
ffxDir = getFFXdir(subLabel, opt);
2562
content = bids.util.tsvread(fullfile(ffxDir, ...
2663
'sub-01_task-vismotion_space-IXI549Space_labelfold.tsv'));
2764

28-
expectedContent = struct('labels', {{'VisMot*bf(1)'; 'VisStat*bf(1)'}}, 'folds', [1; 1]);
65+
expectedContent = struct('labels', {{'VisMot*bf(1)'; ...
66+
'VisMot*bf(1)'; ...
67+
'VisStat*bf(1)'; ...
68+
'VisStat*bf(1)'}}, ...
69+
'folds', [1; 2; 1; 2]);
2970

3071
assertEqual(content, expectedContent);
3172

32-
delete(fullfile(ffxDir, 'sub-01_task-vismotion_space-IXI549Space_labelfold.tsv'));
33-
3473
end

0 commit comments

Comments
 (0)