Skip to content

Commit

Permalink
several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 29, 2024
1 parent ffc5837 commit 5f5f4f9
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 42 deletions.
16 changes: 11 additions & 5 deletions docs/source/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ stats
.. autofunction:: src.batches.stats.setBatchContrasts
.. autofunction:: src.batches.stats.setBatchEstimateModel
.. autofunction:: src.batches.stats.setBatchFactorialDesign
.. autofunction:: src.batches.stats.setBatchFactorialDesignGlobalCalcAndNorm
.. autofunction:: src.batches.stats.setBatchFactorialDesignImplicitMasking
.. autofunction:: src.batches.stats.setBatchFatorialDesignGlobalCalcAndNorm
.. autofunction:: src.batches.stats.setBatchGoodnessOfFit
.. autofunction:: src.batches.stats.setBatchGroupLevelContrasts
.. autofunction:: src.batches.stats.setBatchGroupLevelResults
Expand Down Expand Up @@ -173,6 +173,7 @@ bids
.. autofunction:: src.bids.getAnatFilename
.. autofunction:: src.bids.getAndCheckRepetitionTime
.. autofunction:: src.bids.getAndCheckSliceOrder
.. autofunction:: src.bids.getAvailableGroups
.. autofunction:: src.bids.getBoldFilename
.. autofunction:: src.bids.getInfo
.. autofunction:: src.bids.getMeanFuncFilename
Expand All @@ -188,7 +189,6 @@ bids
bids_model
==========
.. autofunction:: src.bids_model.checkContrast
.. autofunction:: src.bids_model.checkGroupBy
.. autofunction:: src.bids_model.createDefaultStatsModel
.. autofunction:: src.bids_model.createModelFamilies
.. autofunction:: src.bids_model.getContrastsFromParentNode
Expand All @@ -198,6 +198,12 @@ bids_model
.. autofunction:: src.bids_model.getDummyContrastsList
.. autofunction:: src.bids_model.getInclusiveMask

bidspm
======

data
----

cli
===
.. autofunction:: src.cli.baseInputParser
Expand All @@ -220,6 +226,7 @@ cli

constants
=========
.. autofunction:: src.constants.bidsAppsActions
.. autofunction:: src.constants.lowLevelActions

defaults
Expand Down Expand Up @@ -262,7 +269,6 @@ messages
.. autofunction:: src.messages.errorHandling
.. autofunction:: src.messages.logger
.. autofunction:: src.messages.noRoiFound
.. autofunction:: src.messages.noSPMmat
.. autofunction:: src.messages.notImplemented
.. autofunction:: src.messages.printAvailableContrasts
.. autofunction:: src.messages.printBatchName
Expand Down Expand Up @@ -339,7 +345,6 @@ subject_level
.. autofunction:: src.stats.subject_level.getSessionForRegressorNb
.. autofunction:: src.stats.subject_level.newContrast
.. autofunction:: src.stats.subject_level.orderAndPadCounfoundMatFile
.. autofunction:: src.stats.subject_level.removeIntercept
.. autofunction:: src.stats.subject_level.reorderCounfounds
.. autofunction:: src.stats.subject_level.sanitizeConfounds
.. autofunction:: src.stats.subject_level.saveRoiGlmSummaryTable
Expand All @@ -354,10 +359,10 @@ group_level
.. autofunction:: src.stats.group_level.computeCumulativeFwhm
.. autofunction:: src.stats.group_level.findSubjectConImage
.. autofunction:: src.stats.group_level.getRFXdir
.. autofunction:: src.stats.group_level.groupLevelGlmType

utils
-----
.. autofunction:: src.stats.utils.checkSpmMat
.. autofunction:: src.stats.utils.createGlmDirName
.. autofunction:: src.stats.utils.designMatrixFigureName
.. autofunction:: src.stats.utils.endsWithRunNumber
Expand All @@ -366,6 +371,7 @@ utils
.. autofunction:: src.stats.utils.getRegressorIdx
.. autofunction:: src.stats.utils.labelActivations
.. autofunction:: src.stats.utils.labelSpmSessWithBidsSesAndRun
.. autofunction:: src.stats.utils.removeIntercept
.. autofunction:: src.stats.utils.returnContrastImageFile
.. autofunction:: src.stats.utils.returnNumberScrubbedTimePoints
.. autofunction:: src.stats.utils.validateContrasts
Expand Down
10 changes: 2 additions & 8 deletions src/batches/stats/setBatchGroupLevelContrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,8 @@

case 'two_sample_t_test'

designMatrix = removeIntercept(designMatrix);

if any(ismember(designMatrix, fieldnames(participants)))
% TODO will this ignore the contrasts define at other levels
% and not passed through the filter ?
edge = bm.get_edge('Destination', nodeName);
contrastsList = edge.Filter.contrast;
end
edge = bm.get_edge('Destination', nodeName);
contrastsList = edge.Filter.contrast;

for j = 1:numel(contrastsList)

Expand Down
4 changes: 2 additions & 2 deletions src/batches/stats/setBatchSubjectLevelContrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

printBatchName('subject level contrasts specification', opt);

spmMatFile = fullfile(getFFXdir(subLabel, opt), 'SPM.mat');
if ~checkSpmMat(dir, opt)
if ~checkSpmMat(getFFXdir(subLabel, opt), opt)
return
end
spmMatFile = fullfile(getFFXdir(subLabel, opt), 'SPM.mat');

load(spmMatFile, 'SPM');

Expand Down
2 changes: 1 addition & 1 deletion src/batches/stats/setBatchSubjectLevelGLMSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
matlabbatch{end + 1}.spm.stats.fmri_design = fmri_spec;

else
node = model.get_root_node();
node = bm.get_root_node();

fmri_spec.mask = {getInclusiveMask(opt, node.Name, BIDS, subLabel)};
matlabbatch{end + 1}.spm.stats.fmri_spec = fmri_spec;
Expand Down
5 changes: 5 additions & 0 deletions src/bids/getAvailableGroups.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
function availableGroups = getAvailableGroups(opt, groupColumnHdr)

% (C) Copyright 2024 bidspm developers
if isempty(groupColumnHdr)
availableGroups = {};
return
end

tsvFile = fullfile(opt.dir.raw, 'participants.tsv');

assert(exist(tsvFile, 'file') == 2);
Expand Down
2 changes: 1 addition & 1 deletion src/bids_model/getContrastsList.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
% TODO relax those assumptions

% assumptions
assert(model.validateGroupBy(node.Name participants));
assert(model.validateGroupBy(node.Name, participants));
assert(node.Model.X == 1);

contrastsList = getContrastsFromParentNode(model, node);
Expand Down
2 changes: 1 addition & 1 deletion src/bids_model/getContrastsListForFactorialDesign.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
% if no specific dummy contrasts mentioned also include all contrasts from previous levels
% or if contrasts are mentioned we grab them
if ~isfield(node.DummyContrasts, 'Contrasts') || isfield(node, 'Contrasts')
tmp = getContrastsList(bm, nodeName, columns);
tmp = getContrastsList(bm, nodeName, participants);
for i = 1:numel(tmp)
contrastsList{end + 1} = tmp{i}.Name;
end
Expand Down
2 changes: 1 addition & 1 deletion src/stats/subject_level/specifyContrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
return
end

if isempty(model.Edges)
if isempty(bm.Edges)
bm = bm.get_edges_from_nodes();
end

Expand Down
6 changes: 3 additions & 3 deletions src/workflows/roi/bidsRoiBasedGLM.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
if ~checkSpmMat(outputDir, opt, strict)
continue
end
spmFile = fullfile(outputDir, 'SPM.mat');
load(spmFile, 'SPM');
spmMatFile = fullfile(outputDir, 'SPM.mat');
load(spmMatFile, 'SPM');
model = mardo(SPM);

eventSpec = getEventSpecificationRoiGlm(spmFile, opt.model.file);
eventSpec = getEventSpecificationRoiGlm(spmMatFile, opt.model.file);

subTempDir = fullfile(tempDir, ['sub-' subLabel]);
spm_mkdir(subTempDir);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_batches/preproc/test_setBatchGenerateT1map.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function test_setBatchGenerateT1map_warning()
BIDS = getLayout(opt);

matlabbatch = {};
opt.verbosity = 2;
opt.verbosity = 1;
assertWarning(@() setBatchGenerateT1map(matlabbatch, BIDS, opt, subLabel), ...
'setBatchGenerateT1map:missingNonBIDSMetadata');

Expand Down
14 changes: 7 additions & 7 deletions tests/tests_bids/test_fileFilterForBold.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function test_fileFilterForBold_events()

opt.bidsFilterFile.bold = struct('modality', 'func', 'suffix', 'bold');
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 6;
opt.space = {'IXI549Space'};
Expand All @@ -38,7 +38,7 @@ function test_fileFilterForBold_events_aroma()
opt.bidsFilterFile.bold = struct('modality', 'func', ...
'suffix', 'bold', ...
'desc', {'smoothAROMAnonaggr'});
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 6;
opt.space = {'MNI152NLin6Asym'};
Expand All @@ -61,7 +61,7 @@ function test_fileFilterForBold_events_aroma()
function test_fileFilterForBold_confounds()

opt.bidsFilterFile.bold = struct('modality', 'func', 'suffix', 'bold');
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 6;
opt.space = {'IXI549Space'};
Expand All @@ -84,7 +84,7 @@ function test_fileFilterForBold_confounds()
function test_fileFilterForBold_basic()

opt.bidsFilterFile.bold = struct('modality', 'func', 'suffix', 'bold');
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 6;
opt.space = {'IXI549Space'};
Expand All @@ -111,7 +111,7 @@ function test_fileFilterForBold_desc()
opt.bidsFilterFile.bold = struct('modality', 'func', ...
'suffix', 'bold', ...
'desc', {'smoothAROMAnonaggr'});
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 6;
opt.space = {'MNI152NLin6Asym'};
Expand All @@ -138,7 +138,7 @@ function test_fileFilterForBold_desc()
function test_fileFilterForBold_no_smooth()

opt.bidsFilterFile.bold = struct('modality', 'func', 'suffix', 'bold');
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 0;
opt.space = {'IXI549Space'};
Expand All @@ -163,7 +163,7 @@ function test_fileFilterForBold_no_smooth()
function test_fileFilterForBold_stc()

opt.bidsFilterFile.bold = struct('modality', 'func', 'suffix', 'bold');
opt.verbosity = 2;
opt.verbosity = 0;
opt.taskName = 'foo';
opt.fwhm.func = 0;
opt.space = {'IXI549Space'};
Expand Down
8 changes: 4 additions & 4 deletions tests/tests_bids_model/test_getOptionsFromModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function test_getOptionsFromModel_no_model()
opt.pipeline.type = 'stats';
opt.model.file = '';
opt.tolerant = true;
opt.verbosity = 3;
opt.verbosity = 1;
opt.pipeline.isBms = false;

assertExceptionThrown(@() getOptionsFromModel(opt), 'getOptionsFromModel:modelFileMissing');
Expand Down Expand Up @@ -79,7 +79,7 @@ function test_getOptionsFromModel_task()

%%
opt.taskName = {'foo'};
opt.verbosity = 2;
opt.verbosity = 1;
opt.tolerant = true;

assertWarning(@() getOptionsFromModel(opt), 'getOptionsFromModel:modelOverridesOptions');
Expand All @@ -104,7 +104,7 @@ function test_getOptionsFromModel_subject()

%%
opt.subjects = '02';
opt.verbosity = 2;
opt.verbosity = 1;

assertWarning(@() getOptionsFromModel(opt), 'getOptionsFromModel:modelOverridesOptions');

Expand Down Expand Up @@ -147,7 +147,7 @@ function test_getOptionsFromModel_query()

%%
opt.query.acq = 'foo';
opt.verbosity = 2;
opt.verbosity = 1;

assertWarning(@() getOptionsFromModel(opt), 'getOptionsFromModel:modelOverridesOptions');

Expand Down
6 changes: 3 additions & 3 deletions tests/tests_bids_model/test_validateGroupBy.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function test_validateGroupBy_subject()
assertWarning(@()bm.validateGroupBy(nodeName), 'BidsModel:notImplemented');
end

function test_checkGroupBy_dataset()
function test_validateGroupBy_dataset()

opt = setOptions('vismotion', {'01' 'ctrl01'}, 'pipelineType', 'stats');

Expand All @@ -62,7 +62,7 @@ function test_checkGroupBy_dataset()

end

function test_checkGroupBy_dataset_group_from_participant()
function test_validateGroupBy_dataset_group_from_participant()

opt = setOptions('vismotion', {'01' 'ctrl01'}, 'pipelineType', 'stats');

Expand All @@ -71,6 +71,6 @@ function test_checkGroupBy_dataset_group_from_participant()
nodeName = bm.Nodes{3}.Name;

bm.Nodes{3}.GroupBy = {'contrast', 'diagnostic'};
bm.validateGroupBy(nodeName, {'diagnostic'});
bm.validateGroupBy(nodeName, struct('diagnostic', {{'foo', 'bar'}}));

end
2 changes: 1 addition & 1 deletion tests/tests_slow/tests_workflows/stats/test_bidsResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function test_bidsResults_no_results()
skipIfOctave('mixed-string-concat warning thrown');

opt = setOptions('vismotion', '', 'pipelineType', 'stats');
opt.verbosity = 2;
opt.verbosity = 1;

opt = rmfield(opt, 'results');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function test_renameSegmentParameter_basic()
'index_dependencies', false);

opt.dryRun = false;
opt.verbosity = 2;
opt.verbosity = 0;

segParamFiles = spm_select('FPListRec', tmpDir, '^.*_T1w_seg8.mat$');
assertEqual(size(segParamFiles, 1), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function test_renameUnwarpParameter_basic()
'index_dependencies', false);

opt.dryRun = false;
opt.verbosity = 2;
opt.verbosity = 0;

unwarpParamFiles = spm_select('FPListRec', tmpDir, '^.*_bold_uw.mat$');
assertEqual(size(unwarpParamFiles, 1), 1);
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_stats/unit_tests/test_getInclusiveMask.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function test_getInclusiveMask_too_many()

opt = setOptions('vismotion', '01', 'useTempDir', true);

opt.verbosity = 2;
opt.verbosity = 1;

opt.model.bm = BidsModel('file', opt.model.file);

Expand Down Expand Up @@ -63,7 +63,7 @@ function test_getInclusiveMask_no_image()

opt = setOptions('vismotion', '01');

opt.verbosity = 2;
opt.verbosity = 1;

opt.model.bm = BidsModel('file', opt.model.file);

Expand Down

0 comments on commit 5f5f4f9

Please sign in to comment.