From 7fe3e7f4f2cffc6b26ee4e0047a5d7a63d7e6158 Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Mon, 8 Mar 2021 15:39:45 +0100 Subject: [PATCH 1/3] remove code which is in common to CPP_SPM that we keep there --- src/batches/setBatch3Dto4D.m | 52 ------------------------------------ tests/test_setBatch3Dto4D.m | 27 ------------------- 2 files changed, 79 deletions(-) delete mode 100644 src/batches/setBatch3Dto4D.m delete mode 100644 tests/test_setBatch3Dto4D.m diff --git a/src/batches/setBatch3Dto4D.m b/src/batches/setBatch3Dto4D.m deleted file mode 100644 index 90e761b..0000000 --- a/src/batches/setBatch3Dto4D.m +++ /dev/null @@ -1,52 +0,0 @@ -% (C) Copyright 2020 CPP BIDS SPM-pipeline developers - -function matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT, outputName, dataType) - % - % Set the batch for 3D to 4D conversion - % - % USAGE:: - % - % matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT, [outputName], [dataType]) - % - % :param matlabbatch: - % :type matlabbatch: structure - % :param volumesList: List of volumes to be converted in a single 4D brain - % :type volumesList: array - % :param outputName: The string that will be used to save the 4D brain - % :type outputName: string - % :param dataType: It identifies the data format conversion - % :type dataType: integer - % :param RT: It identifies the TR in seconds of the volumes - % to be written in the 4D file header - % :type RT: float - % - % :returns: - :matlabbatch: (structure) The matlabbatch ready to run the spm job - % - % ``dataType``: - % - % - 0: SAME - % - 2: UINT8 - unsigned char - % - 4: INT16 - signed short - % - 8: INT32 - signed int - % - 16: FLOAT32 - single prec. float - % - 64: FLOAT64 - double prec. float - % - - if nargin < 5 || isempty(dataType) - dataType = 0; - end - - if nargin < 4 || isempty(outputName) - outputName = deblank(volumesList(1, :)); - [pth, filename, ext] = spm_fileparts(outputName); - outputName = fullfile(pth, [filename, '_4D', ext]); - end - - printBatchName('3D to 4D conversion'); - - matlabbatch{end + 1}.spm.util.cat.vols = volumesList; - matlabbatch{end}.spm.util.cat.name = outputName; - matlabbatch{end}.spm.util.cat.dtype = dataType; - matlabbatch{end}.spm.util.cat.RT = RT; - -end diff --git a/tests/test_setBatch3Dto4D.m b/tests/test_setBatch3Dto4D.m deleted file mode 100644 index 6a169d3..0000000 --- a/tests/test_setBatch3Dto4D.m +++ /dev/null @@ -1,27 +0,0 @@ -function test_suite = test_setBatch3Dto4D %#ok<*STOUT> - 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_setBatch3Dto4DBasic() - - volumesList = [ ... - fullfile(pwd, 'sub-01_task-rest_bold.nii,1'); ... - fullfile(pwd, 'sub-01_task-rest_bold.nii,2')]; - - RT = 2; - - matlabbatch = []; - matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT); - - expectedBatch{1}.spm.util.cat.vols = volumesList; - expectedBatch{1}.spm.util.cat.name = fullfile(pwd, 'sub-01_task-rest_bold_4D.nii'); - expectedBatch{1}.spm.util.cat.dtype = 0; - expectedBatch{1}.spm.util.cat.RT = 2; - - assertEqual(matlabbatch, expectedBatch); - -end From 8a007d8d85a718a29fd359f8718fe37985abbc1e Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Mon, 8 Mar 2021 15:39:59 +0100 Subject: [PATCH 2/3] add test to check options --- tests/test_checkOptionsSource.m | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/test_checkOptionsSource.m diff --git a/tests/test_checkOptionsSource.m b/tests/test_checkOptionsSource.m new file mode 100644 index 0000000..1d0f69a --- /dev/null +++ b/tests/test_checkOptionsSource.m @@ -0,0 +1,51 @@ +function test_suite = test_checkOptionsSource %#ok<*STOUT> + 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_checkOptionsSourceBasic() + + optSource.nbDummies = 0; + optSource = checkOptionsSource(optSource); + + expectedOptionsSource = defaultOptionsSource(); + expectedOptionsSource.nbDummies = 0; + + assertEqual(optSource, expectedOptionsSource); + +end + +function test_checkOptionsSourceDoNotOverwrite() + + optSource.dataType = 666; + optSource.someExtraField = 'test'; + optSource.nbDummies = 42; + + optSource = checkOptionsSource(optSource); + + assertEqual(optSource.dataType, 666); + assertEqual(optSource.someExtraField, 'test'); + assertEqual(optSource.nbDummies, 42); + +end + +function expectedOptionsSource = defaultOptionsSource() + + expectedOptionsSource.sourceDir = ''; + + expectedOptionsSource.dataDir = ''; + + expectedOptionsSource.sequenceToIgnore = {}; + + expectedOptionsSource.dataType = 0; + + expectedOptionsSource.zip = 0; + + expectedOptionsSource.nbDummies = 0; + + expectedOptionsSource.sequenceRmDummies = {}; + +end From b2d36a47666a85fee224b8e172a195957e27ae40 Mon Sep 17 00:00:00 2001 From: marcobarilari Date: Mon, 8 Mar 2021 15:55:47 +0100 Subject: [PATCH 3/3] add setBatch3Dto4D to make it a stand alone repo --- src/batches/setBatch3Dto4D.m | 52 ++++++++++++++++++++++++++++++++++++ tests/test_setBatch3Dto4D.m | 27 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/batches/setBatch3Dto4D.m create mode 100644 tests/test_setBatch3Dto4D.m diff --git a/src/batches/setBatch3Dto4D.m b/src/batches/setBatch3Dto4D.m new file mode 100644 index 0000000..90e761b --- /dev/null +++ b/src/batches/setBatch3Dto4D.m @@ -0,0 +1,52 @@ +% (C) Copyright 2020 CPP BIDS SPM-pipeline developers + +function matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT, outputName, dataType) + % + % Set the batch for 3D to 4D conversion + % + % USAGE:: + % + % matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT, [outputName], [dataType]) + % + % :param matlabbatch: + % :type matlabbatch: structure + % :param volumesList: List of volumes to be converted in a single 4D brain + % :type volumesList: array + % :param outputName: The string that will be used to save the 4D brain + % :type outputName: string + % :param dataType: It identifies the data format conversion + % :type dataType: integer + % :param RT: It identifies the TR in seconds of the volumes + % to be written in the 4D file header + % :type RT: float + % + % :returns: - :matlabbatch: (structure) The matlabbatch ready to run the spm job + % + % ``dataType``: + % + % - 0: SAME + % - 2: UINT8 - unsigned char + % - 4: INT16 - signed short + % - 8: INT32 - signed int + % - 16: FLOAT32 - single prec. float + % - 64: FLOAT64 - double prec. float + % + + if nargin < 5 || isempty(dataType) + dataType = 0; + end + + if nargin < 4 || isempty(outputName) + outputName = deblank(volumesList(1, :)); + [pth, filename, ext] = spm_fileparts(outputName); + outputName = fullfile(pth, [filename, '_4D', ext]); + end + + printBatchName('3D to 4D conversion'); + + matlabbatch{end + 1}.spm.util.cat.vols = volumesList; + matlabbatch{end}.spm.util.cat.name = outputName; + matlabbatch{end}.spm.util.cat.dtype = dataType; + matlabbatch{end}.spm.util.cat.RT = RT; + +end diff --git a/tests/test_setBatch3Dto4D.m b/tests/test_setBatch3Dto4D.m new file mode 100644 index 0000000..6a169d3 --- /dev/null +++ b/tests/test_setBatch3Dto4D.m @@ -0,0 +1,27 @@ +function test_suite = test_setBatch3Dto4D %#ok<*STOUT> + 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_setBatch3Dto4DBasic() + + volumesList = [ ... + fullfile(pwd, 'sub-01_task-rest_bold.nii,1'); ... + fullfile(pwd, 'sub-01_task-rest_bold.nii,2')]; + + RT = 2; + + matlabbatch = []; + matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT); + + expectedBatch{1}.spm.util.cat.vols = volumesList; + expectedBatch{1}.spm.util.cat.name = fullfile(pwd, 'sub-01_task-rest_bold_4D.nii'); + expectedBatch{1}.spm.util.cat.dtype = 0; + expectedBatch{1}.spm.util.cat.RT = 2; + + assertEqual(matlabbatch, expectedBatch); + +end