Skip to content

Commit

Permalink
move files to slow
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 31, 2024
1 parent 883cb05 commit 65c70c2
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 108 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
run: |
cd demos/openneuro/
make data_ds000114_mriqc
make data_ds000114_fmriprep
- name: Prepare test data unix
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tests_octave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ jobs:
unzip download
mv moae_fmriprep fmriprep
- name: Get data for testing QA
run: |
cd demos/openneuro/
make data_ds000114_mriqc
make data_ds000114_fmriprep
- name: Prepare test data
run: |
cd tests
Expand Down
13 changes: 10 additions & 3 deletions docs/source/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ workflows
.. autofunction:: src.workflows.bidsCheckVoxelSize
.. autofunction:: src.workflows.bidsCopyInputFolder
.. autofunction:: src.workflows.bidsInverseNormalize
.. autofunction:: src.workflows.bidsQAbidspm
.. autofunction:: src.workflows.bidsRename
.. autofunction:: src.workflows.bidsReport

Expand All @@ -42,6 +41,13 @@ roi
.. autofunction:: src.workflows.roi.bidsCreateROI
.. autofunction:: src.workflows.roi.bidsRoiBasedGLM

QA
--
.. autofunction:: src.workflows.QA.bidsQA
.. autofunction:: src.workflows.QA.bidsQAbidspm
.. autofunction:: src.workflows.QA.bidsQAmriqc
.. autofunction:: src.workflows.QA.bidsQApreproc

lesion
------
.. autofunction:: src.workflows.lesion.bidsLesionAbnormalitiesDetection
Expand Down Expand Up @@ -103,7 +109,6 @@ stats
.. autofunction:: src.batches.stats.setBatchSubjectLevelContrasts
.. autofunction:: src.batches.stats.setBatchSubjectLevelGLMSpec
.. autofunction:: src.batches.stats.setBatchSubjectLevelResults
.. autofunction:: src.batches.stats.setBatchTwoSampleTTest

preproc
-------
Expand Down Expand Up @@ -157,7 +162,6 @@ QA
.. autofunction:: src.QA.computeFDandRMS
.. autofunction:: src.QA.computeRobustOutliers
.. autofunction:: src.QA.createDesignMatrix
.. autofunction:: src.QA.mriqcQA
.. autofunction:: src.QA.plotConfounds
.. autofunction:: src.QA.plotEvents
.. autofunction:: src.QA.plotRoiTimeCourse
Expand Down Expand Up @@ -204,6 +208,9 @@ bidspm
data
----

__pycache__
-----------

cli
===
.. autofunction:: src.cli.baseInputParser
Expand Down
19 changes: 17 additions & 2 deletions src/workflows/QA/bidsQA.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
function bidsQA(opt, varargin)
function filename = bidsQA(opt, varargin)
%
% Run QA on a BIDS dataset.
%
% Find outliers in MRIQC output
% or to view number of outlier timepoints
% (for a given metric and threshold) in each functional run
%
%
% USAGE::
%
% figurePath = bidsQA(opt, varargin);
%
% :param opt: Options chosen for the analysis.
% See :func:`checkOptions`.
% :type opt: structure
%

% (C) Copyright 2024 Remi Gau

filename = '';

dsDesc = bids.util.jsondecode(fullfile(opt.dir.input, 'dataset_description.json'));

switch dsDesc.DatasetType
Expand All @@ -31,7 +46,7 @@ function bidsQA(opt, varargin)
bidsQAmriqc(opt, 'bold');

elseif any(ismember({'fMRIPrep', 'bidspm'}, pipelines))
bidsQApreproc(opt, varargin{:});
filename = bidsQApreproc(opt, varargin{:});
end
end
end
8 changes: 4 additions & 4 deletions src/workflows/QA/bidsQAmriqc.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function mriqcQA(opt, suffix)
function bidsQAmriqc(opt, suffix)
%
% uses the report from MRIQC (bold and T1) identify outliers using
% robust statistics (interquartile range).
Expand All @@ -8,7 +8,7 @@ function mriqcQA(opt, suffix)
%
% USAGE::
%
% mriqcQA(opt, suffix);
% bidsQAmriqc(opt, suffix);
%
% :type opt: structure
% :param opt: Options chosen for the analysis.
Expand All @@ -18,8 +18,8 @@ function mriqcQA(opt, suffix)
%
% opt.dir.mriqc = '/home/remi/gin/dataset/derivatives/mriqc';
%
% mriqcQA(opt, 'T1w');
% mriqcQA(opt, 'bold');
% bidsQAmriqc(opt, 'T1w');
% bidsQAmriqc(opt, 'bold');
%
% Dependencies (in case you want to use it as standalone):
%
Expand Down
36 changes: 33 additions & 3 deletions src/workflows/QA/bidsQApreproc.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
function bidsQApreproc(opt, varargin)
function filename = bidsQApreproc(opt, varargin)
%
% Use confounds preprocessed datasets to estimate
% the number of timepoints with values superior to threshold.
%
% Plots the proportion of timepoints per run
% (to identify runs with that goes above a limit).
%
% USAGE::
%
% figurePath = bidsQApreproc(opt, 'metric', metric, 'threshold', threshold);
%
% :param opt: Options chosen for the analysis.
% See :func:`checkOptions`.
% :type opt: structure
%
% :param metric: default = 'framewise_displacement'
% :type metric: char
%
% :param threshold: default = 0.2
% :param threshold: numeric
%
% plots the proportion of timepoints per run
% (to identify runs with that goes above a limit)

% (C) Copyright 2024 bidspm developers

Expand Down Expand Up @@ -81,6 +95,9 @@ function bidsQApreproc(opt, varargin)

plotFigure(df, metric, threshold);

output_path = fullfile(opt.dir.output, 'reports');
filename = printFigure(output_path, metric);

end

function plotFigure(df, metric, threshold)
Expand Down Expand Up @@ -128,3 +145,16 @@ function plotFigure(df, metric, threshold)
'fontsize', 8, 'tickdir', 'out');

end

function filename = printFigure(outputPath, metric)
bids.util.mkdir(outputPath);

filename = regexprep(['outliers_', metric, '.png'], ' - ', '_');
filename = regexprep(filename, ' ', '-');
filename = regexprep(filename, '[\(\)]', '');
filename = fullfile(outputPath, filename);

print(filename, '-dpng');
fprintf('Figure saved:\n\t%s\n', filename);

end
100 changes: 100 additions & 0 deletions tests/tests_slow/tests_workflows/QA/test_bidsQA.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
function test_suite = test_bidsQA %#ok<*STOUT>

% (C) Copyright 2024 bidspm developers

try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end

function test_bidsQA_raw()

% markTestAs('slow');
%
% opt = setOptions('vislocalizer');
%
% expectedOutput = fullfile(opt.dir.output, ...
% 'reports', ...
% 'bidspm-raw_split_by-task.png');
%
% if exist(expectedOutput, 'file')
% delete(expectedOutput)
% end
%
% bidsQA(opt)
%
% assertEqual(exist(expectedOutput, 'file'), 2)

end

function test_bidsQA_mriqc()

% markTestAs('slow');
%
% if ispc()
% moxunit_throw_test_skipped_exception('requires datalad setup');
% end
%
% ds000114mriqc = spm_file(fullfile(getTestDir(), ...
% '..', 'demos', 'openneuro', ...
% 'inputs', 'ds000114-mriqc'), 'cpath');
%
% opt.dir.input = ds000114mriqc;
%
% bidsQA(opt);

end

function test_bidsQA_bidspm()

markTestAs('slow');

if ispc()
moxunit_throw_test_skipped_exception('requires datalad setup');
end

opt = setOptions('vislocalizer');

opt.dir.input = opt.dir.preproc;

opt.dir.output = '';
opt.dir.derivatives = tempName();

opt = checkOptions(opt);

threshold = 0.0001;
metric = 'rot_x';

filename = bidsQA(opt, 'metric', metric, 'threshold', threshold);

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

end

function test_bidsQA_fmriprep()

markTestAs('slow');

ds000114fmriprep = spm_file(fullfile(getTestDir(), ...
'..', 'demos', 'openneuro', ...
'inputs', 'ds000114-fmriprep'), 'cpath');

opt.dir.input = ds000114fmriprep;
opt.dir.preproc = ds000114fmriprep;
opt.dir.derivatives = tempName();
opt.pipeline.type = 'preproc';
opt.verbosity = 0;

opt.taskName = {'overtverbgeneration', 'linebisection'};

opt = checkOptions(opt);

opt.subjects = {'01', '02', '03', '10'};

filename = bidsQA(opt);

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

end
80 changes: 0 additions & 80 deletions tests/tests_workflows/QA/test_bidsQA.m

This file was deleted.

16 changes: 0 additions & 16 deletions tests/tests_workflows/QA/test_bidsQAmriqc.m

This file was deleted.

0 comments on commit 65c70c2

Please sign in to comment.