diff --git a/demos/sourceDataProcessing/batchSource.m b/demos/sourceDataProcessing/batchSource.m index 8b4f3b88..0be72c84 100644 --- a/demos/sourceDataProcessing/batchSource.m +++ b/demos/sourceDataProcessing/batchSource.m @@ -16,3 +16,9 @@ % Single volumes to 4D volumes conversion + remove n dummies convert3Dto4D(optSource); + +% Deface anatomical volumes in a raw folder +% defaceAnat(optSource); COMING SOON + +% GZip the volumes in a raw folder +bidsGZipRawFolder(optSource, 0) \ No newline at end of file diff --git a/demos/sourceDataProcessing/getOptionSource.m b/demos/sourceDataProcessing/getOptionSource.m index 84555cab..0b064a65 100644 --- a/demos/sourceDataProcessing/getOptionSource.m +++ b/demos/sourceDataProcessing/getOptionSource.m @@ -17,6 +17,8 @@ % Set the folder where sequences folders exist optSource.sourceDir = '/Users/barilari/Desktop/DICOM_UCL_leuven/renamed/sub-pilot001/ses-002/MRI'; + + optSource.dataDir = '/Users/barilari/Desktop/DICOM_UCL_leuven/raw'; % List of the sequences that you want to skip (folder name pattern) optSource.sequenceToIgnore = {'AAHead_Scout', ... diff --git a/src/batches/setBatch3Dto4D.m b/src/batches/setBatch3Dto4D.m index 1756091d..69693595 100644 --- a/src/batches/setBatch3Dto4D.m +++ b/src/batches/setBatch3Dto4D.m @@ -4,7 +4,7 @@ % % Set the batch for 3D to 4D conversion % - % USAGE:: matlabbatch = setBatch3Dto4D(volumesList, outputName, dataType, RT) + % USAGE:: % % matlabbatch = setBatch3Dto4D(volumesList, outputName, dataType, RT) % diff --git a/src/batches/setBatchGZip.m b/src/batches/setBatchGZip.m new file mode 100644 index 00000000..104cbac8 --- /dev/null +++ b/src/batches/setBatchGZip.m @@ -0,0 +1,22 @@ +% (C) Copyright 2020 CPP BIDS SPM-pipeline developers + +function matlabbatch = setBatchGZip(unzippedNiifiles, keepUnzippedNii) + % + % Set the batch for GZip the 4D volumes + % + % USAGE:: + % + % matlabbatch = setBatchGZip(unzippedNiifiles, keepUnzippedNii) + % + % :param unzippedNiifiles: List of volumes to be gzipped + % :type unzippedNiifiles: array + % :param keepUnzippedNii: Boolean to decide to delete the unzipped files + % :type keepUnzippedNii: boolean + % + % :returns: - :matlabbatch: (struct) The matlabbath ready to run the spm job + + matlabbatch{1}.cfg_basicio.file_dir.file_ops.cfg_gzip_files.files = unzippedNiifiles; + matlabbatch{1}.cfg_basicio.file_dir.file_ops.cfg_gzip_files.outdir = {''}; + matlabbatch{1}.cfg_basicio.file_dir.file_ops.cfg_gzip_files.keep = keepUnzippedNii; + +end diff --git a/src/defaults/checkOptionsSource.m b/src/defaults/checkOptionsSource.m index f6891759..e1db9187 100644 --- a/src/defaults/checkOptionsSource.m +++ b/src/defaults/checkOptionsSource.m @@ -12,6 +12,16 @@ % to run the batch workflow for source processing % % :returns: - :optSource: (struc) The structure with any unset fields with the deaufalt values + % + % OPTIONS (with their defaults): + % - ``optSource.sourceDir = ''`` - The directory where the source data are located. + % - ``optSource.dataDir = ''`` - The directory where the raw data to apply changes are located. + % - ``optSource.sequenceToIgnore = {}`` - The list of sequence(s) to ignore. + % - ``optSource.dataType = 0`` - Data format conversion (0 is reccomended). + % - ``optSource.zip = 0`` - Boolean to enable gzip of the new 4D file in ``convert3Dto4D``. + % - ``optSource.nbDummies = 0`` - Number of volumes to discard ad dummies in ``convert3Dto4D``. + % - ``optSource.sequenceRmDummies = {}`` - The list of sequence(s) where to discarding the + % dummies. fieldsToSet = setDefaultOptionSource(); @@ -19,13 +29,19 @@ if isempty(optSource.sourceDir) || ~isdir(optSource.sourceDir) - error('The source folder does not exist, try again.'); + warning('The source folder is not provided or does not exist.'); + + end + + if isempty(optSource.dataDir) || ~isdir(optSource.dataDir) + + warning('The raw folder is not provided or does not exist.'); end if isempty(optSource.sequenceToIgnore) - warning('No sequence to ignore provided, I will convert all the images that I can found'); + warning('No sequence-to-ignore provided, I will convert all the images that I can found'); end @@ -36,6 +52,9 @@ % The directory where the source data are located fieldsToSet.sourceDir = ''; + + % The directory where the raw data to apply changes are located + fieldsToSet.dataDir = ''; % The list of sequence(s) to ignore fieldsToSet.sequenceToIgnore = {}; diff --git a/src/workflows/bidsGZipRawFolder.m b/src/workflows/bidsGZipRawFolder.m new file mode 100644 index 00000000..490b710c --- /dev/null +++ b/src/workflows/bidsGZipRawFolder.m @@ -0,0 +1,39 @@ +% (C) Copyright 2020 CPP BIDS SPM-pipeline developers + +function bidsGZipRawFolder(optSource, keepUnzippedNii) + + % + % GZip the nii files in a ``raw`` bids folders from the. It will do it independently of the task. + % + % USAGE:: + % + % bidsGZipRawFolder(optSource ... + % [, keepUnzippedNii = false]) + % + % :param optSource: The structure that contains the options set by the user to run the batch + % workflow for source processing + % :type opt: structure + % :param keepUnzippedNii: will keep the original ``.nii`` if set to ``true``. Default is false + % :type keepUnzippedNii: boolean + + %% input variables default values + + + if nargin < 2 || isempty(keepUnzippedNii) + % delete the original unzipped .nii + keepUnzippedNii = false; + end + + tic; + + printWorklowName('GZip data'); + + rawDir = optSource.dataDir; + + unzippedNiifiles = cellstr(spm_select('FPListRec', rawDir, '^.*.nii$')); + + matlabbatch = setBatchGZip(unzippedNiifiles, keepUnzippedNii); + + spm_jobman('run', matlabbatch); + + toc; diff --git a/tests/test_checkOptionsSource.m b/tests/test_checkOptionsSource.m new file mode 100644 index 00000000..48fa1e74 --- /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 \ No newline at end of file