Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions demos/MoAE/moae_01_bids_app.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
opt.results(1).montage.slices = -4:2:16;
opt.results(1).nidm = true();

opt.results(2).nodeName = 'run_level';
opt.results(2).name = {'listening_inf_baseline'};
opt.results(2).p = 0.01;
opt.results(2).k = 10;
opt.results(2).MC = 'none';
opt.results(2).csv = true;
opt.results(2).atlas = 'AAL';

cpp_spm(bids_dir, output_dir, 'subject', ...
'participant_label', {subject_label}, ...
'action', 'stats', ...
Expand Down
10 changes: 5 additions & 5 deletions src/defaults/checkOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@

% validate content of opt.results

defaultContrast = defaultResultsStructure();
defaultResults = defaultResultsStructure();

fields = fieldnames(defaultContrast);
fields = fieldnames(defaultResults);

if ~isfield(opt, 'results')
opt.results = defaultContrast;
opt.results = defaultResults;
return
end

Expand All @@ -226,12 +226,12 @@
end

% add missing fields
thisResult = setFields(thisResult, defaultContrast);
thisResult = setFields(thisResult, defaultResults);

% fill in empty fields
for i = 1:numel(fields)
if isempty(thisResult.(fields{i}))
thisResult.(fields{i}) = defaultContrast.(fields{i});
thisResult.(fields{i}) = defaultResults.(fields{i});
end
end

Expand Down
27 changes: 14 additions & 13 deletions src/defaults/defaultResultsStructure.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
function contrast = defaultResultsStructure()
function result = defaultResultsStructure()
%
% (C) Copyright 2019 CPP_SPM developers

contrast = defaultContrastsStructure;
result = defaultContrastsStructure;

contrast.png = true();
result.png = true();

contrast.csv = true();
result.csv = true();
result.atlas = 'Neuromorphometrics';

contrast.threshSpm = false();
result.threshSpm = false();

contrast.binary = false();
result.binary = false();

contrast.montage = struct('do', false(), ...
'slices', [], ...
'orientation', 'axial', ...
'background', fullfile(spm('dir'), ...
'canonical', ...
'avg152T1.nii'));
result.montage = struct('do', false(), ...
'slices', [], ...
'orientation', 'axial', ...
'background', fullfile(spm('dir'), ...
'canonical', ...
'avg152T1.nii'));

contrast.nidm = true();
result.nidm = true();

end
33 changes: 25 additions & 8 deletions src/utils/labelActivations.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
function tsvFile = labelActivations(varargin)
%
% Adds MNI labels to a csv output file from SPM
% Adds MNI labels to a csv output file from SPM and saves it as SPM.
%
% Can choose which atlas to use.
%
% USAGE::
%
% tsvFile = labelActivations(csvFile)
% tsvFile = labelActivations(csvFile, 'atlas', 'Neuromorphometrics')
%
% :param csvFile:
% :type csvFile: path
% :type csvFile: path
%
% :param atlas: Any of ``{'Neuromorphometrics', 'AAL'}``.
% Defaults to ``'Neuromorphometrics'``
% :type atlas: char
%
% :returns: - :tsvFile: (path)
%
Expand All @@ -18,10 +24,21 @@
args = inputParser;

addRequired(args, 'csvFile', @ischar);
addParameter(args, 'atlas', 'Neuromorphometrics', @ischar);

parse(args, varargin{:});

csvFile = args.Results.csvFile;
atlas = args.Results.atlas;

atlasName = 'Neuromorphometrics';
if ~strcmp(atlas, 'Neuromorphometrics')
copyAtlasToSpmDir(atlas, 'verbose', false);
switch atlas
case 'AAL'
atlasName = 'AAL3v1_1mm';
end
end

%% renaming headers to have only one row
% combine 1rst and 2nd row
Expand Down Expand Up @@ -61,13 +78,13 @@
end

%% add MNI label
% L = spm_atlas('list');
xA = spm_atlas('load', 'Neuromorphometrics');
spm_atlas('list', 'installed', '-refresh');
xA = spm_atlas('load', atlasName);

for i = 1:numel(newCSV.x)
newCSV.neuromorphometric_label{i} = spm_atlas('query', xA, [newCSV.x(i), ...
newCSV.y(i), ...
newCSV.z(i)]');
newCSV.([atlas '_label']){i} = spm_atlas('query', xA, [newCSV.x(i), ...
newCSV.y(i), ...
newCSV.z(i)]');
end

tsvFile = bids.internal.file_utils(csvFile, 'ext', '.tsv');
Expand Down
2 changes: 1 addition & 1 deletion src/workflows/stats/bidsResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function renameOutputResults(results)

for iFile = 1:size(csvFiles, 1)
source = deblank(csvFiles(iFile, :));
labelActivations(source);
labelActivations(source, 'atlas', result.atlas);
end

end
Expand Down
2 changes: 1 addition & 1 deletion tests/dummyData/tsv_files/moae_results_table.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set_p set_c cluster_p_FWE_corr_ cluster_p_FDR_corr_ cluster_equivk cluster_p_unc_ peak_p_FWE_corr_ peak_p_FDR_corr_ peak_T peak_equivZ peak_p_unc_ x y z neuromorphometric_label
set_p set_c cluster_p_FWE_corr_ cluster_p_FDR_corr_ cluster_equivk cluster_p_unc_ peak_p_FWE_corr_ peak_p_FDR_corr_ peak_T peak_equivZ peak_p_unc_ x y z Neuromorphometrics_label
0.000 4 0.000 0.000 218 0.000 0.000 0.000 12.15 Inf 0.000 57 -22 11 Right PT planum temporale
n/a n/a n/a n/a n/a n/a 0.000 0.000 11.38 Inf 0.000 66 -13 -4 Right STG superior temporal gyrus
n/a n/a n/a n/a n/a n/a 0.000 0.003 7.02 6.05 0.000 60 -37 5 Right MTG middle temporal gyrus
Expand Down
9 changes: 9 additions & 0 deletions tests/dummyData/tsv_files/moae_results_table_aal.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set_p set_c cluster_p_FWE_corr_ cluster_p_FDR_corr_ cluster_equivk cluster_p_unc_ peak_p_FWE_corr_ peak_p_FDR_corr_ peak_T peak_equivZ peak_p_unc_ x y z AAL_label
0.000 4 0.000 0.000 218 0.000 0.000 0.000 12.15 Inf 0.000 57 -22 11 Temporal_Sup_R
n/a n/a n/a n/a n/a n/a 0.000 0.000 11.38 Inf 0.000 66 -13 -4 Temporal_Sup_R
n/a n/a n/a n/a n/a n/a 0.000 0.003 7.02 6.05 0.000 60 -37 5 Temporal_Mid_R
n/a n/a 0.000 0.000 401 0.000 0.000 0.000 12.11 Inf 0.000 -63 -28 11 Temporal_Sup_L
n/a n/a n/a n/a n/a n/a 0.000 0.000 11.31 Inf 0.000 -45 -34 11 Temporal_Sup_L
n/a n/a n/a n/a n/a n/a 0.000 0.000 10.10 7.84 0.000 -66 -10 -1 Temporal_Mid_L
n/a n/a 0.001 0.016 5 0.012 0.005 0.161 5.86 5.24 0.000 69 -25 -4 Temporal_Mid_R
n/a n/a 0.015 0.219 1 0.219 0.032 0.684 5.40 4.90 0.000 51 5 -7 Insula_R
9 changes: 9 additions & 0 deletions tests/dummyData/tsv_files/moae_results_table_neuromorpho.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set_p set_c cluster_p_FWE_corr_ cluster_p_FDR_corr_ cluster_equivk cluster_p_unc_ peak_p_FWE_corr_ peak_p_FDR_corr_ peak_T peak_equivZ peak_p_unc_ x y z Neuromorphometrics_label
0.000 4 0.000 0.000 218 0.000 0.000 0.000 12.15 Inf 0.000 57 -22 11 Right PT planum temporale
n/a n/a n/a n/a n/a n/a 0.000 0.000 11.38 Inf 0.000 66 -13 -4 Right STG superior temporal gyrus
n/a n/a n/a n/a n/a n/a 0.000 0.003 7.02 6.05 0.000 60 -37 5 Right MTG middle temporal gyrus
n/a n/a 0.000 0.000 401 0.000 0.000 0.000 12.11 Inf 0.000 -63 -28 11 Left PT planum temporale
n/a n/a n/a n/a n/a n/a 0.000 0.000 11.31 Inf 0.000 -45 -34 11 Left PT planum temporale
n/a n/a n/a n/a n/a n/a 0.000 0.000 10.10 7.84 0.000 -66 -10 -1 Left STG superior temporal gyrus
n/a n/a 0.001 0.016 5 0.012 0.005 0.161 5.86 5.24 0.000 69 -25 -4 Right MTG middle temporal gyrus
n/a n/a 0.015 0.219 1 0.219 0.032 0.684 5.40 4.90 0.000 51 5 -7 Right PP planum polare
1 change: 1 addition & 0 deletions tests/tests_defaults/test_defaultResultsStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function test_defaultResultsStructure_basic()
expected.png = true();

expected.csv = true();
expected.atlas = 'Neuromorphometrics';

expected.threshSpm = false();

Expand Down
23 changes: 22 additions & 1 deletion tests/tests_unit/test_labelActivations.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
initTestSuite;
end

function test_labelActivations_aal()

if isGithubCi()
return
end

csvFile = fullfile(getDummyDataDir(), 'tsv_files', 'moae_results_table.csv');

tsvFile = labelActivations(csvFile, 'atlas', 'AAL');

assertEqual(exist(tsvFile, 'file'), 2);

expectedFile = fullfile(getDummyDataDir(), 'tsv_files', 'moae_results_table_aal.tsv');
expectedContent = bids.util.tsvread(expectedFile);

content = bids.util.tsvread(tsvFile);

assertEqual(content, expectedContent);

end

function test_labelActivations_basic()

csvFile = fullfile(getDummyDataDir(), 'tsv_files', 'moae_results_table.csv');
Expand All @@ -15,7 +36,7 @@ function test_labelActivations_basic()

assertEqual(exist(tsvFile, 'file'), 2);

expectedFile = fullfile(getDummyDataDir(), 'tsv_files', 'moae_results_table.tsv');
expectedFile = fullfile(getDummyDataDir(), 'tsv_files', 'moae_results_table_neuromorpho.tsv');
expectedContent = bids.util.tsvread(expectedFile);

content = bids.util.tsvread(tsvFile);
Expand Down