Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
585512e
add test for zipping batch
Remi-Gau Dec 25, 2020
5debf44
add template for batch
Remi-Gau Dec 25, 2020
0820e8f
add test for convert 3D to 4D
Remi-Gau Dec 25, 2020
7feedf1
add test image calculator batch
Remi-Gau Dec 25, 2020
00bd76c
refactor batch skull stripping
Remi-Gau Dec 25, 2020
5a16f7a
add test batch mean mask and anat
Remi-Gau Dec 26, 2020
280cc4d
fix tests specify contrast and create default model
Remi-Gau Dec 26, 2020
f6c1873
add test set batch mean mask and anat
Remi-Gau Dec 26, 2020
1cc0b90
improve doc subject level functions
Remi-Gau Dec 26, 2020
864bbf0
readd spm.mat and update .travis.yml
Remi-Gau Dec 26, 2020
7f8ed58
stop tracking dummy data
Remi-Gau Dec 26, 2020
241efad
ignore dummy data set
Remi-Gau Dec 26, 2020
6dd2572
update createDefaultModel
Remi-Gau Dec 26, 2020
8d43f91
refactor setBatchMeanAnat
Remi-Gau Dec 26, 2020
af66a1f
fix test setBatchMeanAnat
Remi-Gau Dec 26, 2020
907d749
update argin batcSTC
Remi-Gau Dec 26, 2020
2586e2a
update tests smoothing batches
Remi-Gau Dec 26, 2020
d847ea9
update argin order and help section of setBatch functions
Remi-Gau Dec 26, 2020
f14758a
refactor model and contrast specification
Remi-Gau Dec 26, 2020
ffe5872
fix tests after changing order argin
Remi-Gau Dec 26, 2020
6b499af
improve test set batch subject level contrast
Remi-Gau Dec 26, 2020
bc81df5
add test for batch for factorial design
Remi-Gau Dec 26, 2020
17d3c2f
fix test set batch smooth con image
Remi-Gau Dec 26, 2020
5a4ef51
add test coregistration fmap to functional
Remi-Gau Dec 26, 2020
e7fbe84
add test for setBatchComputeVDM
Remi-Gau Dec 26, 2020
3b62a5f
temporarily move test set batch coreg fmap to manual tests
Remi-Gau Dec 26, 2020
fd9d12d
add smoke test for setBatchCreateVDMs
Remi-Gau Dec 26, 2020
2d88252
move test to manualTest folder
Remi-Gau Dec 26, 2020
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
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ demos/MoAE/output/*
demos/spm*/raw
demos/spm*/source

# test folder
# test folder and dummy data
tests/sub-01/*
tests/group/*
tests/models/*.json
tests/dummyData/derivatives/cpp_spm/sub-*/*/*/*.nii
tests/dummyData/derivatives/cpp_spm/sub-*/*/*/*.tsv
tests/dummyData/derivatives/cpp_spm/sub-*/*/*/*.txt
tests/dummyData/derivatives/cpp_spm/sub-*/*/*/*.json
tests/dummyData/derivatives/cpp_spm/sub-*/stats/*/*/*.nii

# ignore content of the build folder of the doc
docs/build/*

# ignore virtual env
cpp_bids_spm/*
cpp_spm/*

# visual studio code stuff
Expand Down
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ jobs:
- mkdir $output_folder
- curl http://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.bids.zip --output $output_folder'MoAEpilot.zip'
- unzip $output_folder'MoAEpilot.zip' -d $output_folder


# generate dummy data
- cd tests
- sh createDummyDataSet.sh
- cd ..

script:
- octave $OCTFLAGS --eval "runTests"
- cat test_report.log | grep 0
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = 'CPP BIDS SPM'
copyright = '2020, the CPP BIDS SPM pipeline dev team'
author = 'the CPP BIDS SPM pipeline dev team'
project = 'CPP SPM'
copyright = '2020, the CPP SPM pipeline dev team'
author = 'the CPP SPM pipeline dev team'

# The full version, including alpha/beta/rc tags
release = 'v0.1.0'
Expand Down
63 changes: 63 additions & 0 deletions manualTests/test_setBatchCoregistrationFmap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function test_suite = test_setBatchCoregistrationFmap %#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_setBatchCoregistrationFmapBasic()

subID = '01';

opt.taskName = 'vismotion';
opt.derivativesDir = fullfile(fileparts(mfilename('fullpath')), 'dummyData');

opt = checkOptions(opt);

[~, opt, BIDS] = getData(opt);

matlabbatch = [];
matlabbatch = setBatchCoregistrationFmap(matlabbatch, BIDS, opt, subID);

directory = fullfile(opt.derivativesDir, ...
'sub-01', ...
'ses-01');
ref = fullfile(directory, ...
'func', ...
'mean_sub-01_ses-01_task-vismotion_run-1_bold.nii');

expectedbatch = [];

src = fullfile(directory, ...
'fmap', ...
'sub-01_ses-01_run-2_magnitude1.nii');
other = {fullfile(directory, ...
'fmap', ...
'sub-01_ses-01_run-2_magnitude2.nii'); ...
fullfile(directory, ...
'fmap', ...
'sub-01_ses-01_run-2_phasediff.nii')};
expectedbatch{end + 1}.spm.spatial.coreg.estimate.ref = { ref };
expectedbatch{end}.spm.spatial.coreg.estimate.source = { src };
expectedbatch{end}.spm.spatial.coreg.estimate.other = other;

directory = fullfile(opt.derivativesDir, ...
'sub-01', ...
'ses-02');
src = fullfile(directory, ...
'fmap', ...
'sub-01_ses-02_run-2_magnitude1.nii');
other = {fullfile(directory, ...
'fmap', ...
'sub-01_ses-02_run-2_magnitude2.nii'); ...
fullfile(directory, ...
'fmap', ...
'sub-01_ses-02_run-2_phasediff.nii')};
expectedbatch{end + 1}.spm.spatial.coreg.estimate.ref = { ref };
expectedbatch{end}.spm.spatial.coreg.estimate.source = { src };
expectedbatch{end}.spm.spatial.coreg.estimate.other = other;

assertEqual(matlabbatch, expectedbatch);

end
30 changes: 30 additions & 0 deletions manualTests/test_setBatchCreateVDMs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function test_suite = test_setBatchCreateVDMs %#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_setBatchCreateVDMsBasic()

subID = '01';

opt.taskName = 'vismotion';
opt.derivativesDir = fullfile(fileparts(mfilename('fullpath')), 'dummyData');
opt.taskName = 'vismotion';

opt = checkOptions(opt);

[~, opt, BIDS] = getData(opt);

matlabbatch = [];
matlabbatch = setBatchCreateVDMs(matlabbatch, BIDS, opt, subID);

% matlabbatch{1}.spm.tools.fieldmap.calculatevdm.subj

% expectedBatch = returnExpectedBatch(refImage);
%
% assertEqual(matlabbatch, expectedBatch);

end
44 changes: 33 additions & 11 deletions src/batches/setBatch3Dto4D.m
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
% (C) Copyright 2020 CPP BIDS SPM-pipeline developers

function matlabbatch = setBatch3Dto4D(volumesList, outputName, dataType, RT)
function matlabbatch = setBatch3Dto4D(matlabbatch, volumesList, RT, outputName, dataType)
%
% Set the batch for 3D to 4D conversion
%
% USAGE::
%
% matlabbatch = setBatch3Dto4D(volumesList, outputName, dataType, RT)
% 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: Obligatory argument. The string that will be used to save the 4D brain
% :param outputName: The string that will be used to save the 4D brain
% :type outputName: string
% :param dataType: Obligatory argument. It identifies the data format conversion
% :param dataType: It identifies the data format conversion
% :type dataType: integer
% :param RT: Obligatory argument. It identifies the TR in secof the volumes to be written in the
% 4D file header
% :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

fprintf(1, 'PREPARING: 3D to 4D conversion\n');
printBatchName('3D to 4D conversion');

matlabbatch{1}.spm.util.cat.vols = volumesList;
matlabbatch{1}.spm.util.cat.name = outputName;
matlabbatch{1}.spm.util.cat.dtype = dataType;
matlabbatch{1}.spm.util.cat.RT = RT;
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
4 changes: 2 additions & 2 deletions src/batches/setBatchComputeVDM.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%
% USAGE::
%
% [argout1, argout2] = templateFunction(argin1, [argin2 == default,] [argin3])
% matlabbatch = setBatchComputeVDM(matlabbatch, fmapType, refImage)
%
% :param matlabbatch: list of SPM batches
% :type matlabbatch: structure
Expand All @@ -28,7 +28,7 @@
matlabbatch{end}.spm.tools.fieldmap.calculatevdm.subj(1).data.presubphasemag.magnitude = '';

case 'phase&mag'
matlabbatch{end}.spm.tools.fieldmap.calculatevdm.subj(1).data.phasemag.shortphase = '';
matlabbatch{end + 1}.spm.tools.fieldmap.calculatevdm.subj(1).data.phasemag.shortphase = '';
matlabbatch{end}.spm.tools.fieldmap.calculatevdm.subj(1).data.phasemag.shortmag = '';
matlabbatch{end}.spm.tools.fieldmap.calculatevdm.subj(1).data.phasemag.longphase = '';
matlabbatch{end}.spm.tools.fieldmap.calculatevdm.subj(1).data.phasemag.longmag = '';
Expand Down
27 changes: 27 additions & 0 deletions src/batches/setBatchContrasts.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developers

function matlabbatch = setBatchContrasts(matlabbatch, spmMatFile, consess)
%
% Short description of what the function does goes here.
%
% USAGE::
%
% matlabbatch = setBatchContrasts(matlabbatch, spmMatFile, consess)
%
% :param matlabbatch:
% :type matlabbatch: structure
% :param spmMatFile:
% :type spmMatFile: string
% :param consess:
% :type consess: cell
%
% :returns: - :matlabbatch: (structure)
%

printBatchName('contrasts specification');

matlabbatch{end + 1}.spm.stats.con.spmmat = spmMatFile;
matlabbatch{end}.spm.stats.con.consess = consess;
matlabbatch{end}.spm.stats.con.delete = 1;

end
133 changes: 67 additions & 66 deletions src/batches/setBatchCoregistrationFmap.m
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
% (C) Copyright 2020 CPP BIDS SPM-pipeline developers

function matlabbatch = setBatchCoregistrationFmap(BIDS, opt, subID)
%
% Set the batch for the coregistration of field maps
%
% USAGE::
%
% [argout1, argout2] = templateFunction(argin1, [argin2 == default,] [argin3])
%
% :param BIDS: BIDS layout returned by ``getData``.
% :type BIDS: structure
% :param opt: structure or json filename containing the options. See
% ``checkOptions()`` and ``loadAndCheckOptions()``.
% :type opt: structure
% :param subID: subject ID
% :type subID: string
%
% :returns: - :matlabbatch: (structure) The matlabbatch ready to run the spm job
%

% TODO
% assumes all the fieldmap relate to the current task
% - use the "for" metadata field
% - implement for 'phase12', 'fieldmap', 'epi'

printBatchName('coregister fieldmaps data to functional');

% Create rough mean of the 1rst run to improve SNR for coregistration
% TODO use the slice timed EPI if STC was used ?
[sessions, nbSessions] = getInfo(BIDS, subID, opt, 'Sessions');
runs = getInfo(BIDS, subID, opt, 'Runs', sessions{1});
[fileName, subFuncDataDir] = getBoldFilename(BIDS, subID, sessions{1}, runs{1}, opt);

spmup_basics(fullfile(subFuncDataDir, fileName), 'mean');

refImage = fullfile(subFuncDataDir, ['mean_', fileName]);

matlabbatch = [];

for iSes = 1:nbSessions

runs = bids.query(BIDS, 'runs', ...
'modality', 'fmap', ...
'sub', subID, ...
'ses', sessions{iSes});

for iRun = 1:numel(runs)

% TODO
% - Move to getInfo
fmapFiles = bids.query(BIDS, 'data', ...
'modality', 'fmap', ...
'sub', subID, ...
'ses', sessions{iSes}, ...
'run', runs{iRun});

srcImage = strrep(fmapFiles{1}, 'phasediff', 'magnitude1');

otherImages = cell(2, 1);
otherImages{1} = strrep(fmapFiles{1}, 'phasediff', 'magnitude2');
otherImages{2} = fmapFiles{1};

matlabbatch = setBatchCoregistration(matlabbatch, refImage, srcImage, otherImages);

function matlabbatch = setBatchCoregistrationFmap(matlabbatch, BIDS, opt, subID)
%
% Set the batch for the coregistration of field maps
%
% USAGE::
%
% matlabbatch = setBatchCoregistrationFmap(matlabbatch, BIDS, opt, subID)
%
% :param BIDS: BIDS layout returned by ``getData``.
% :type BIDS: structure
% :param opt: structure or json filename containing the options. See
% ``checkOptions()`` and ``loadAndCheckOptions()``.
% :type opt: structure
% :param subID: subject ID
% :type subID: string
%
% :returns: - :matlabbatch: (structure) The matlabbatch ready to run the spm job
%

% TODO
% - implement for 'phase12', 'fieldmap', 'epi'

printBatchName('coregister fieldmaps data to functional');

% Use a rough mean of the 1rst run to improve SNR for coregistration
% created by spmup
[sessions, nbSessions] = getInfo(BIDS, subID, opt, 'Sessions');
runs = getInfo(BIDS, subID, opt, 'Runs', sessions{1});
[fileName, subFuncDataDir] = getBoldFilename(BIDS, subID, sessions{1}, runs{1}, opt);
refImage = validationInputFile(subFuncDataDir, fileName, 'mean_');

for iSes = 1:nbSessions

runs = bids.query(BIDS, 'runs', ...
'modality', 'fmap', ...
'sub', subID, ...
'ses', sessions{iSes});

for iRun = 1:numel(runs)

metadata = bids.query(BIDS, 'metadata', ...
'modality', 'fmap', ...
'sub', subID, ...
'ses', sessions{iSes}, ...
'run', runs{iRun});

if strfind(metadata.IntendedFor, opt.taskName)

fmapFiles = bids.query(BIDS, 'data', ...
'modality', 'fmap', ...
'sub', subID, ...
'ses', sessions{iSes}, ...
'run', runs{iRun});

srcImage = strrep(fmapFiles{1}, 'phasediff', 'magnitude1');

otherImages = cell(2, 1);
otherImages{1} = strrep(fmapFiles{1}, 'phasediff', 'magnitude2');
otherImages{2} = fmapFiles{1};

matlabbatch = setBatchCoregistration(matlabbatch, refImage, srcImage, otherImages);

end

end

end

end


end
Loading