Skip to content

Commit 56746e1

Browse files
authored
Merge pull request #425 from CerenB/cer-bidsConcatFix
bidsConcatBetaTmaps. fix
2 parents f58b6f1 + ccf3256 commit 56746e1

File tree

5 files changed

+89
-15
lines changed

5 files changed

+89
-15
lines changed

src/workflows/bidsConcatBetaTmaps.m

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
99
% :param funcFWHM: smoothing (FWHM) applied to the the normalized EPI
1010
% :type funcFWHM: (scalar)
1111
% :param deleteIndBeta: decide to delete beta-maps
12-
% :type funcFWHM: (boolean)
12+
% :type deleteIndBeta: (boolean)
1313
% :param deleteIndTmaps: decide to delete t-maps
14-
% :type funcFWHM: (boolean)
14+
% :type deleteIndTmaps: (boolean)
1515
%
1616
% When concatenating betamaps:
1717
%
@@ -22,12 +22,21 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
2222
%
2323
% (C) Copyright 2019 CPP_SPM developers
2424

25-
if nargin < 3
26-
deleteIndBeta = 1;
27-
deleteIndTmaps = 1;
25+
[~, opt] = setUpWorkflow(opt, 'merge beta images and t-maps');
26+
27+
% TODO temporary check: will be removed on the dev branch
28+
if ~isfield(opt, 'dryRun')
29+
opt.dryRun = false;
2830
end
2931

30-
[~, opt] = setUpWorkflow(opt, 'merge beta images and t-maps');
32+
if nargin < 3
33+
deleteIndBeta = true;
34+
deleteIndTmaps = true;
35+
end
36+
if opt.dryRun
37+
deleteIndBeta = false;
38+
deleteIndTmaps = false;
39+
end
3140

3241
RT = 0;
3342

@@ -41,21 +50,25 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
4150

4251
load(fullfile(ffxDir, 'SPM.mat'));
4352

44-
contrasts = specifyContrasts(ffxDir, opt.taskName, opt);
53+
model = spm_jsonread(opt.model.file);
54+
55+
contrasts = specifyContrasts(SPM, opt.taskName, model);
4556

4657
beta_maps = cell(length(contrasts), 1);
4758
t_maps = cell(length(contrasts), 1);
4859

4960
% path to beta and t-map files.
61+
fprintf(1, '\nConcatenating the following contrasts:');
5062
for iContrast = 1:length(beta_maps)
5163

64+
fprintf(1, '\n\t%s', contrasts(iContrast).name);
5265
betasIndices = find(contrasts(iContrast).C);
5366

5467
if numel(betasIndices) > 1
5568
error('Supposed to concatenate one beta image per contrast.');
5669
end
5770

58-
% for this beta iamge we identify
71+
% for this beta image we identify
5972
% - which run it came from
6073
% - the exact condition name stored in the SPM.mat
6174
% so they can be saved in a tsv for for "label" and "fold" for MVPA
@@ -70,7 +83,6 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
7083
fileName = validationInputFile(ffxDir, fileName);
7184
beta_maps{iContrast, 1} = [fileName, ',1'];
7285

73-
% while the contrastes (t-maps) are not from the index. They were created
7486
fileName = sprintf('spmT_%04d.nii', iContrast);
7587
fileName = validationInputFile(ffxDir, fileName);
7688
t_maps{iContrast, 1} = [fileName, ',1'];
@@ -81,15 +93,17 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
8193
nameStructure = struct( ...
8294
'ext', '.tsv', ...
8395
'suffix', 'labelfold', ...
84-
'entities' struct('sub', subLabel, ...
85-
'task', opt.taskName, ...
86-
'space', opt.space));
96+
'entities', struct('sub', subLabel, ...
97+
'task', opt.taskName, ...
98+
'space', opt.space));
99+
nameStructure.use_schema = false;
87100
tsvName = bids.create_filename(nameStructure);
88101

89102
tsvContent = struct('folds', runs, 'labels', {conditions});
90103

91104
spm_save(fullfile(ffxDir, tsvName), tsvContent);
92105

106+
% TODO in the dev branch make those output filenames "BIDS derivatives" compliant
93107
% beta maps
94108
outputName = ['4D_beta_', num2str(funcFWHM), '.nii'];
95109

@@ -101,7 +115,10 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps)
101115

102116
matlabbatch = setBatch3Dto4D(matlabbatch, t_maps, RT, outputName);
103117

104-
saveAndRunWorkflow(matlabbatch, 'concat_betaImg_tMaps', opt, subLabel);
118+
% TODO temporary: remove on dev branch
119+
if ~opt.dryRun
120+
saveAndRunWorkflow(matlabbatch, 'concat_betaImg_tMaps', opt, subLabel);
121+
end
105122

106123
removeBetaImgTmaps(t_maps, deleteIndBeta, deleteIndTmaps, ffxDir);
107124

@@ -136,6 +153,7 @@ function removeBetaImgTmaps(t_maps, deleteIndBeta, deleteIndTmaps, ffxDir)
136153
delete(t_maps{iTmap}(1:end - 2));
137154
end
138155
fprintf('Done. \n\n\n ');
156+
139157
end
140158

141159
end

tests/createDummyDataSet.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ do
110110
touch $ThisDir/mask.nii
111111

112112
touch $ThisDir/spmT_0001.nii
113-
touch $ThisDir/spmT_0002.nii
113+
touch $ThisDir/spmT_0002.nii
114+
touch $ThisDir/spmT_0003.nii
115+
touch $ThisDir/spmT_0004.nii
116+
117+
touch $ThisDir/beta_0001.nii
118+
touch $ThisDir/beta_0002.nii
119+
touch $ThisDir/beta_0003.nii
120+
touch $ThisDir/beta_0004.nii
114121

115122
touch $ThisDir/con_0001.nii
116123
touch $ThisDir/con_0002.nii
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Name": "vismotion",
3+
"Description": "This model only has simple contrasts for MVPA",
4+
"Input": {
5+
"task": "vismotion"
6+
},
7+
"Steps": [
8+
{
9+
"Level": "subject",
10+
"AutoContrasts": [
11+
"trial_type.VisMot",
12+
"trial_type.VisStat"
13+
]
14+
}
15+
]
16+
}

tests/test_bidsConcatBetaTmaps.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function test_suite = test_bidsConcatBetaTmaps %#ok<*STOUT>
2+
%
3+
% (C) Copyright 2019 CPP_SPM developers
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_bidsConcatBetaTmapsBasic()
12+
13+
subLabel = '01';
14+
funcFWHM = 6;
15+
16+
opt = setOptions('vismotion', subLabel);
17+
opt.dryRun = true;
18+
19+
opt.model.file = spm_file(opt.model.file, 'filename', 'model-vismotionMVPA_smdl.json');
20+
21+
bidsConcatBetaTmaps(opt, funcFWHM);
22+
23+
ffxDir = getFFXdir(subLabel, funcFWHM, opt);
24+
content = bids.util.tsvread(fullfile(ffxDir, ...
25+
'sub-01_task-vismotion_space-MNI_labelfold.tsv'));
26+
27+
expectedContent = struct('labels', {{'VisMot*bf(1)'; 'VisStat*bf(1)'}}, 'folds', [1; 1]);
28+
29+
assertEqual(content, expectedContent);
30+
31+
delete(fullfile(ffxDir, 'sub-01_task-vismotion_space-MNI_labelfold.tsv'));
32+
33+
end

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.1.2
1+
v1.1.3

0 commit comments

Comments
 (0)