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
6 changes: 6 additions & 0 deletions demos/sourceDataProcessing/batchSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions demos/sourceDataProcessing/getOptionSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -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', ...
Expand Down
2 changes: 1 addition & 1 deletion src/batches/setBatch3Dto4D.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
%
Expand Down
22 changes: 22 additions & 0 deletions src/batches/setBatchGZip.m
Original file line number Diff line number Diff line change
@@ -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
23 changes: 21 additions & 2 deletions src/defaults/checkOptionsSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@
% 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();

optSource = setDefaultFields(optSource, fieldsToSet);

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

Expand All @@ -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 = {};
Expand Down
39 changes: 39 additions & 0 deletions src/workflows/bidsGZipRawFolder.m
Original file line number Diff line number Diff line change
@@ -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;
51 changes: 51 additions & 0 deletions tests/test_checkOptionsSource.m
Original file line number Diff line number Diff line change
@@ -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