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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/bids-matlab"]
path = lib/bids-matlab
url = https://github.com/cpp-lln-lab/bids-matlab.git
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ before_install:
- make -C spm12/src PLATFORM=octave distclean
- make -C spm12/src PLATFORM=octave
- make -C spm12/src PLATFORM=octave install
# get data
- mkdir demo/output
- curl http://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.bids.zip --output demo/output/MoAEpilot.zip
- unzip demo/output/MoAEpilot.zip -d demo/output/


script:
- octave $OCTFLAGS --eval "runTests"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [Assumption](#assumption)
- [Setting up](#setting-up)
- [getOptions](#getoptions)
- [spm_my_defaults](#spm_my_defaults)
- [model JSON files](#model-json-files)
- [Order of the analysis](#order-of-the-analysis)
- [Docker](#docker)
Expand Down Expand Up @@ -126,8 +127,20 @@ Set the task to analyze in the BIDS data set
The directory where your files are located on your computer: make sure you have a copy of the data set as this pipeline will change it.
`opt.derivativesDir = '/Data/auditoryBIDS/derivatives'`

#### spm_my_defaults


Some more SPM options can be set in the `spm_my_defaults.m`.

- Use of FAST and not AR1 for auto-correlation modelisation

Using FAST does not seem to affect results on time series with "normal" TRs but
improves results when using sequences: it is therefore used by default in this
pipeline.

> Olszowy, W., Aston, J., Rua, C. et al. Accurate autocorrelation modeling
> substantially improves fMRI reliability. Nat Commun 10, 1220 (2019).
> https://doi.org/10.1038/s41467-019-09230-w

### model JSON files
This files allow you to specify which contrasts to run and follow the BIDS statistical model extension and as implement by [fitlins](https://fitlins.readthedocs.io/en/latest/model.html)
Expand Down
2 changes: 2 additions & 0 deletions batch.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

% __ ____ ____ _ _ _
% / _)( _ \( _ \ | | / \ | )
% ( (_ )___/ )___/ | |_ / _ \ | \
Expand Down
6 changes: 4 additions & 2 deletions demo/batch_download_run.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 Remi Gau

% This script will download the dataset from the FIL for the block design SPM
% tutorial and will run the basic preprocessing, FFX and contrasts on it.
% Results might be a bit different from those in the manual as some
Expand Down Expand Up @@ -67,7 +69,7 @@
%% Get data
% fprintf('%-40s:', 'Downloading dataset...');
% urlwrite(URL, 'MoAEpilot.zip');
unzip('MoAEpilot.zip', fullfile(WD, 'output'));
% unzip('MoAEpilot.zip', fullfile(WD, 'output'));

%% Check dependencies
% If toolboxes are not in the MATLAB Directory and needed to be added to
Expand All @@ -84,7 +86,7 @@
%% Run batches
isMVPA = 0;

bidsCopyRawFolder(opt, 1);
% bidsCopyRawFolder(opt, 1);
bidsSTC(opt);
bidsSpatialPrepro(opt);
bidsSmoothing(FWHM, opt);
Expand Down
23 changes: 3 additions & 20 deletions getOption.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
function opt = getOption()
% __ ____ ____ _ _ _
% / _)( _ \( _ \ | | / \ | )
% ( (_ )___/ )___/ | |_ / _ \ | \
% \__)(__) (__) |___||_/ \_||__)
%
% Thank you for using the CPP lap pipeline - version 0.0.3.
%
% Current list of contributors includes
% Mohamed Rezk
% Rémi Gau
% Olivier Collignon
% Ane Gurtubay
% Marco Barilari
%
% Please cite using the following DOI:
% https://doi.org/10.5281/zenodo.3554332
%
% For bug report, suggestions for improvements or contributions see our github repo:
% https://github.com/cpp-lln-lab/CPP_BIDS_SPM_pipeline
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function opt = getOption()
% opt = getOption()
% returns a structure that contains the options chosen by the user to run
% slice timing correction, pre-processing, FFX, RFX.

Expand Down
1 change: 1 addition & 0 deletions lib/bids-matlab
Submodule bids-matlab added at dd04a3
14 changes: 10 additions & 4 deletions miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# styly guide (https://florianschanda.github.io/miss_hit/style_checker.html)
line_length: 100
regex_function_name: "[a-z]+(_*([a-zA-Z0-9]){1}[A-Za-z]+)*" # almost anything goes in the root folder
suppress_rule: "copyright_notice"
exclude_dir: "lib"
copyright_entity: "JH"
copyright_entity: "DSS"
copyright_entity: "Agah Karakuzu"
copyright_entity: "Olivier Collignon"
copyright_entity: "Mohamed Rezk"
copyright_entity: "Remi Gau"
copyright_entity: "CPP BIDS SPM-pipeline developpers"

# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
metric "cnest": limit 4
metric "file_length": limit 300
metric "cyc": limit 15
metric "parameters": limit 4
metric "file_length": limit 400
metric "cyc": limit 12
metric "parameters": limit 6
2 changes: 2 additions & 0 deletions runTests.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

warning('OFF');

addpath(fullfile(pwd, 'spm12'));
Expand Down
2 changes: 2 additions & 0 deletions spm_my_defaults.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function spm_my_defaults
% This is where we set the defautls we want to use.
% These will overide the spm defaults.
Expand Down
2 changes: 2 additions & 0 deletions src/concatBetaImgTmaps.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function concatBetaImgTmaps(funcFWHM, opt, deleteIndBeta, deleteIndTmaps)
% concatBetaImgTmaps(funcFWHM, opt, deleteIndBeta, deleteIndTmaps)
%
Expand Down
3 changes: 3 additions & 0 deletions src/convertOnsetTsvToMat.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function fullpathOnsetFileName = convertOnsetTsvToMat(opt, tsvFile, isMVPA)
%% Converts a tsv file to an onset file suitable for SPM ffx analysis
% The scripts extracts the conditions' names, onsets, and durations, and
Expand All @@ -12,6 +14,7 @@
'This onset tsv file deos not exist:', ...
tsvFile);
error(errorStruct);

end

% Read the tsv file
Expand Down
10 changes: 9 additions & 1 deletion src/createAndReturnOnsetFile.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function onsetFileName = createAndReturnOnsetFile(opt, subID, funcFWHM, boldFileName, isMVPA)
% onsetFileName = createAndReturnOnsetFile(opt, boldFileName, prefix, isMVPA)
%
% gets the tsv onset file based on the bold file name (removes any prefix)
%
% convert the tsv files to a mat file to be used by SPM

replacePrefixBy = '';
prefix = getPrefix('FFX', opt, funcFWHM);
if strcmp(opt.space, 'T1w')
prefix = getPrefix('FFX_space-T1w', opt, funcFWHM);
end

if strcmp(prefix, 'r')
prefix = 'rsub-';
replacePrefixBy = 'sub-';
end

[funcDataDir, boldFileName] = spm_fileparts(boldFileName{1});

tsvFile = strrep(boldFileName, '_bold', '_events.tsv');
tsvFile = strrep(tsvFile, prefix, '');
tsvFile = strrep(tsvFile, prefix, replacePrefixBy);
tsvFile = fullfile(funcDataDir, tsvFile);

onsetFileName = convertOnsetTsvToMat(opt, tsvFile, isMVPA);
Expand Down
2 changes: 2 additions & 0 deletions src/deleteResidualImages.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2020 CPP BIDS SPM-pipeline developpers

function deleteResidualImages(ffxDir)
delete(fullfile(ffxDir, 'Res_*.nii'));
end
2 changes: 2 additions & 0 deletions src/getBoldFilename.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2020 CPP BIDS SPM-pipeline developpers

function [fileName, subFuncDataDir] = getBoldFilename(varargin)
% [fileName, subFuncDataDir] = getBoldFilename(BIDS, opt, subID, sessionID, runID)

Expand Down
2 changes: 2 additions & 0 deletions src/getBoldFilenameForFFX.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function [boldFileName, prefix] = getBoldFilenameForFFX(varargin)
% [boldFileName, prefix] = getFunctionalFiles(BIDS, opt, subID, funcFWHM, iSes, iRun)
%
Expand Down
45 changes: 3 additions & 42 deletions src/getData.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function [group, opt, BIDS] = getData(opt, BIDSdir, type)
% getData checks that all the options specified by the user in getOptions
% and fills the blank for any that might have been missed out.
Expand Down Expand Up @@ -112,7 +114,7 @@
case 'T1w'
metadata = spm_BIDS(BIDS, 'metadata', ...
'sub', subjects{1}, ...
'type', [type]);
'type', type);
end

if iscell(metadata)
Expand All @@ -122,44 +124,3 @@
end

end

function group = getSpecificSubjects(opt, group, iGroup, subjects)

% if no group or subject was specified we take all of them
if numel(opt.groups) == 1 && ...
strcmp(group(iGroup).name, '') && ...
isempty(opt.subjects{iGroup})

group(iGroup).subNumber = subjects;

% if subject ID were directly specified by users we take those
elseif strcmp(group(iGroup).name, '') && iscellstr(opt.subjects)

group(iGroup).subNumber = opt.subjects;

% if group was specified we figure out which subjects to take
elseif ~isempty(opt.subjects{iGroup})

idx = opt.subjects{iGroup};

% else we take all subjects of that group
elseif isempty(opt.subjects{iGroup})

% count how many subjects in that group
idx = sum(~cellfun(@isempty, strfind(subjects, group(iGroup).name)));
idx = 1:idx;

else

error('Not sure what to do.');

end

% if only indices were specified we get the subject from that group with that
if exist('idx', 'var')
pattern = [group(iGroup).name '%0' num2str(opt.zeropad) '.0f_'];
temp = strsplit(sprintf(pattern, idx), '_');
group(iGroup).subNumber = temp(1:end - 1);
end

end
2 changes: 2 additions & 0 deletions src/getFFXdir.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function ffxDir = getFFXdir(subID, funcFWFM, opt, isMVPA)
% ffxDir = getFFXdir(subID, funcFWFM, opt, isMVPA)
%
Expand Down
25 changes: 25 additions & 0 deletions src/getFuncVoxelDims.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function [voxDim, opt] = getFuncVoxelDims(opt, subFuncDataDir, prefix, fileName)
% [voxDim, opt] = getFuncVoxelDims(opt, subFuncDataDir, prefix, fileName)
%
%

% get native resolution to reuse it at normalisation;
if ~isempty(opt.funcVoxelDims) % If voxel dimensions is defined in the opt
voxDim = opt.funcVoxelDims; % Get the dimension values
else
% SPM Doesnt deal with nii.gz and all our nii should be unzipped
% at this stage
hdr = spm_vol(fullfile(subFuncDataDir, [prefix, fileName]));
voxDim = diag(hdr(1).mat);
% Voxel dimensions are not pure integers before reslicing, therefore
% round the dimensions of the functional files to the 1st decimal point
voxDim = abs(voxDim(1:3)');
voxDim = round(voxDim * 10) / 10;
% Add it to opt.funcVoxelDims to have the same value for
% all subjects and sessions
opt.funcVoxelDims = voxDim;
end

end
17 changes: 17 additions & 0 deletions src/getGrpLevelContrastToCompute.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function [grpLvlCon, iStep] = getGrpLevelContrastToCompute(opt, isMVPA)

model = spm_jsonread(opt.model.univariate.file);
if isMVPA
model = spm_jsonread(opt.model.multivariate.file);
end

for iStep = 1:length(model.Steps)
if strcmp(model.Steps{iStep}.Level, 'dataset')
grpLvlCon = model.Steps{iStep}.AutoContrasts;
break
end
end

end
2 changes: 2 additions & 0 deletions src/getInfo.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function varargout = getInfo(BIDS, subID, opt, info, varargin)
% for a given BIDS data set, subject identity, and info type,
% if info = Sessions, this returns name of the sessions and their number
Expand Down
2 changes: 2 additions & 0 deletions src/getPrefix.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function [prefix, motionRegressorPrefix] = getPrefix(step, opt, funcFWHM)
% generates prefix to append to file name to look for

Expand Down
2 changes: 2 additions & 0 deletions src/getRFXdir.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function rfxDir = getRFXdir(opt, funcFWHM, conFWHM, contrastName)
% rfxDir = getRFXdir(opt, funcFWHM, conFWHM, iStep, iCon)
%
Expand Down
7 changes: 7 additions & 0 deletions src/getRealignParamFile.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function realignParamFile = getRealignParamFile(opt, fullpathBoldFileName, funcFWHM)

[prefix, motionRegressorPrefix] = getPrefix('FFX', opt, funcFWHM);
if strcmp(opt.space, 'T1w')
[prefix, motionRegressorPrefix] = getPrefix('FFX_space-T1w', opt, funcFWHM);
end

if strcmp(prefix, 'r')
prefix = 'rsub-';
motionRegressorPrefix = 'sub-';
end

[funcDataDir, boldFileName] = spm_fileparts(fullpathBoldFileName{1});

realignParamFile = strrep(boldFileName, prefix, motionRegressorPrefix);
Expand Down
2 changes: 2 additions & 0 deletions src/getSliceOrder.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% (C) Copyright 2019 CPP BIDS SPM-pipeline developpers

function sliceOrder = getSliceOrder(opt, verbose)
% get the slice order information from the BIDS data set or from getOption
%
Expand Down
Loading