Skip to content

Commit 0dace15

Browse files
authored
Merge pull request #51 from Remi-Gau/remi_constrast-specification
[WIP] constrast specification + uni and multivaraite issues + remove dummies
2 parents 04f94a1 + c4ec3e3 commit 0dace15

File tree

189 files changed

+821
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+821
-374
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.asv
44
*.m~
55
*.nii
6+
7+
opt.mat

List_of_Contrast.m

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This set of function will read and unzip the data from a [BIDS data set](https:/
4949

5050
This has to be run for each task independently. All parameters should preferably be changed in the `getOptions.m` file.
5151

52+
It can also prepare the data to run an MVPA analysis by running a GLM for each subject on non-normalized images and get one beta image for each condition to be used in the MVPA.
53+
5254
The core functions are in the sub-function folder `subfun`
5355

5456
## Assumption
@@ -60,6 +62,9 @@ At the moment this pipeline makes some assumptions:
6062

6163
## Setting up
6264

65+
### getOptions
66+
67+
6368
All the details specific to your analysis should be set in the `getOptions.m`.
6469

6570
Set the group of subjects to analyze.
@@ -97,6 +102,58 @@ The directory where your files are located on your computer: make sure you have
97102

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

105+
### model JSON files
106+
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)
107+
108+
The model json file that describes:
109+
- out to prepare the regressors for the GLM: `Transformation`
110+
- the design matrix: `X`
111+
- the contrasts to compute: `contrasts`
112+
113+
It also allows to specify those for different levels of the analysis:
114+
- run
115+
- session
116+
- subject
117+
- dataset
118+
119+
An example of json file could look something like that.
120+
121+
```json
122+
{
123+
"Name": "Basic",
124+
"Description": "",
125+
"Input": {
126+
"task": "motionloc"
127+
},
128+
"Steps": [
129+
{
130+
"Level": "subject",
131+
"AutoContrasts": ["stim_type.motion", "stim_type.static"],
132+
"Contrasts": [
133+
{
134+
"Name": "motion_vs_static",
135+
"ConditionList": [
136+
"stim_type.motion",
137+
"stim_type.static"
138+
],
139+
"weights": [1, -1],
140+
"type": "t"
141+
}
142+
]
143+
},
144+
{
145+
"Level": "dataset",
146+
"AutoContrasts": ["stim_type.motion", "stim_type.static", "motion_vs_static"]
147+
}
148+
]
149+
}
150+
```
151+
152+
In brief this means:
153+
- at the subject level automatically compute the t contrast against baseline for the condition `motion`and `static` and compute the t-contrats for motion VS static with these given weights.
154+
- at the level of the data set (so RFX) do the t contrast of the `motion`, `static`, `motion VS static`.
155+
156+
100157
## Order of the analysis
101158

102159
1. __Remove Dummy Scans__:

batch.m

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
clear
2+
clc
3+
14
%% Run batches
25
opt = getOption();
36

@@ -7,18 +10,33 @@
710
% we add all the subfunctions that are in the sub directories
811
addpath(genpath(WD))
912

10-
% In case some toolboxes need to be added the matlab path, specify and uncomment
13+
% In case some toolboxes need to be added the matlab path, specify and uncomment
1114
% in the lines below
1215
% toolbox_path = '';
1316
% addpath(fullfile(toolbox_path)
1417

18+
checkDependencies();
19+
20+
% copy raw folder into derivatives folder
21+
BIDS_copyRawFolder(opt, 1)
22+
23+
% preprocessing
24+
BIDS_STC(opt);
25+
BIDS_SpatialPrepro(opt);
26+
BIDS_Smoothing(6, opt);
27+
28+
% subject level Univariate
29+
BIDS_FFX(1, 6, opt);
30+
BIDS_FFX(2, 6, opt);
31+
32+
% group level univariate
33+
BIDS_RFX(1, 6, 6)
34+
BIDS_RFX(2, 6, 6)
35+
36+
% subject level multivariate
37+
isMVPA=1;
38+
BIDS_FFX(1, 6, opt, isMVPA);
39+
BIDS_FFX(2, 6, opt, isMVPA);
40+
make4Dmaps(6,opt)
41+
1542

16-
%cd(WD); checkDependencies();
17-
%cd(WD); BIDS_rmDummies(opt);
18-
%cd(WD); BIDS_STC(opt);
19-
%cd(WD); BIDS_SpatialPrepro(opt);
20-
%cd(WD); BIDS_Smoothing(6, opt);
21-
%cd(WD); BIDS_FFX(1, 6, opt);
22-
%cd(WD); BIDS_FFX(2, 6, opt);
23-
%cd(WD); BIDS_RFX(1, 6, 6)
24-
%cd(WD); BIDS_RFX(2, 6, 6)

batch_download_run.m renamed to demo/batch_download_run.m

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% tutorial and will run the basic preprocessing, FFX and contrasts on it.
33
% Results might be a bit different from those in the manual as some
44
% default options are slightly different in this pipeline (e.g use of FAST
5-
% instead of AR(1))
5+
% instead of AR(1), motion regressors added)
66

77
clear
88
clc
@@ -14,38 +14,42 @@
1414
% URL of the data set to download
1515
URL = 'http://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.bids.zip';
1616

17-
WD = pwd; % the directory with this script becomes the current directory
18-
addpath(genpath(WD)) % we add all the subfunctions that are in the sub directories
17+
% directory with this script becomes the current directory
18+
WD = fileparts(mfilename('fullpath'));
19+
20+
% we add all the subfunctions that are in the sub directories
21+
addpath(genpath(fullfile(WD, '..')))
1922

2023

2124
%% Set options
2225
opt = getOption();
2326

2427
% respecify options here in case the getOption file has been modified on
2528
% the repository
26-
opt.derivativesDir = fullfile(WD, '..', 'output', 'MoAEpilot'); % the dataset will downloaded and analysed there
29+
30+
% the dataset will downloaded and analysed there
31+
opt.dataDir = fullfile(WD, 'output', 'MoAEpilot');
2732
opt.groups = {''}; % no specific group
28-
opt.subjects = {1}; % first subject
33+
opt.subjects = {[]}; % first subject
2934
opt.taskName = 'auditory'; % task to analyze
30-
opt.contrastList = {...
31-
{'listening'} ...
32-
};
3335

3436
% the following options are less important but are added to reset all
3537
% options
36-
opt.numDummies = 0;
3738
opt.STC_referenceSlice = [];
3839
opt.sliceOrder = [];
3940
opt.funcVoxelDims = [];
40-
opt.JOBS_dir = fullfile(opt.derivativesDir, 'JOBS', opt.taskName);
41+
opt.JOBS_dir = fullfile(opt.dataDir, '..', 'derivatives', 'SPM12_CPPL', 'JOBS', opt.taskName);
42+
43+
44+
% specify the model file that contains the contrasts to compute
45+
opt = rmfield(opt, 'model');
46+
opt.model.univariate.file = fullfile(WD, 'model-MoAE_smdl.json');
47+
4148

4249
%% Get data
43-
if ~exist(opt.derivativesDir, 'dir')
44-
[~,~,~] = mkdir(opt.derivativesDir);
45-
end
4650
fprintf('%-40s:', 'Downloading dataset...');
4751
urlwrite(URL, 'MoAEpilot.zip');
48-
unzip('MoAEpilot.zip', fullfile(WD, '..', 'output'));
52+
unzip('MoAEpilot.zip', fullfile(WD, 'output'));
4953

5054

5155
%% Check dependencies
@@ -62,10 +66,11 @@
6266

6367

6468
%% Run batches
65-
BIDS_rmDummies(opt);
69+
BIDS_copyRawFolder(opt, 1)
6670
BIDS_STC(opt);
6771
BIDS_SpatialPrepro(opt);
6872
BIDS_Smoothing(FWHM, opt);
69-
BIDS_FFX(1, FWHM, opt);
70-
BIDS_FFX(2, FWHM, opt);
73+
BIDS_FFX(1, FWHM, opt, 0);
74+
BIDS_FFX(2, FWHM, opt, 0);
75+
7176

demo/model-MoAE_smdl.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"Name": "Listening",
3+
"Description": "contrasts to compute for the FIL MoAE dataset",
4+
"Input": {
5+
"task": "auditory"
6+
},
7+
"Steps": [
8+
{
9+
"Level": "subject",
10+
"AutoContrasts": ["trial_type.listening"],
11+
"Contrasts": [
12+
{
13+
"Name": "listening_inf_baseline",
14+
"ConditionList": [
15+
"trial_type.listening"
16+
],
17+
"weights": [-1],
18+
"type": "t"
19+
}
20+
]
21+
}
22+
]
23+
}

getOption.m

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,29 @@
99
% group of subjects to analyze
1010
opt.groups = {''}; % {'blnd', 'ctrl'};
1111
% suject to run in each group
12-
opt.subjects = {[1:2]}; % {[1:2], [1:2]};
13-
% set the number of zeros used to pad the subject label (2 --> sub-blnd01 ; 3 --> sub-blnd001 )
14-
opt.zeropad = 2;
12+
% opt.subjects = {[4:6]}; % {[1:2], [1:2]};
13+
opt.subjects = {[]}; % {[1:2], [1:2]};
14+
1515

1616
% task to analyze
17-
opt.taskName = 'visMotion';
17+
opt.taskName = 'MotionDecoding';
18+
19+
% opt.taskName = 'visMotion';
20+
21+
% opt.taskName = 'balloonanalogrisktask';
22+
23+
24+
25+
% The directory where the data are located
26+
27+
% opt.dataDir = '/Users/mohamed/Desktop/MotionWorkshop/raw';
28+
% opt.dataDir = '/Users/mohamed/Desktop/Data/raw';
1829

19-
% The directory where the derivatives are located
20-
opt.derivativesDir = '/Users/mohamed/Desktop/MotionWorkshop/derivatives';
30+
% opt.dataDir = '/home/remi/BIDS/visMotion/raw';
31+
opt.dataDir = '/home/remi/BIDS/MotionDecoding/raw';
32+
33+
% opt.dataDir = '/home/remi/BIDS/ds001/rawdata';
2134

22-
% Specify the number of dummies that you want to be removed.
23-
opt.numDummies = 0;
24-
opt.dummyPrefix = 'dr_';
2535

2636
% Options for slice time correction
2737
% If left unspecified the slice timing will be done using the mid-volume acquisition
@@ -37,14 +47,23 @@
3747
% Voxel dimensions for resampling at normalization of functional data or leave empty [ ].
3848
opt.funcVoxelDims = [];
3949

50+
4051
% Suffix output directory for the saved jobs
41-
opt.JOBS_dir = fullfile(opt.derivativesDir, 'JOBS', opt.taskName);
52+
opt.JOBS_dir = fullfile(opt.dataDir, '..', 'derivatives', 'SPM12_CPPL', 'JOBS', opt.taskName);
53+
54+
% specify the model file that contains the contrasts to compute
55+
56+
% opt.model.univariate.file = '/Users/mohamed/Documents/GitHub/BIDS_fMRI_scripts/model-motionDecodingUnivariate_smdl.json';
57+
% opt.model.multivariate.file = '/Users/mohamed/Documents/GitHub/BIDS_fMRI_scripts/model-motionDecodingMultivariate_smdl.json';
58+
59+
% opt.model.univariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-visMotionLoc_smdl.json';
60+
61+
opt.model.univariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-motionDecodingUnivariate_smdl.json';
62+
opt.model.multivariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-motionDecodingMultivariate_smdl.json';
63+
64+
% opt.model.univariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-balloonanalogriskUnivariate_smdl.json';
65+
% opt.model.multivariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-balloonanalogriskMultivariate_smdl.json';
4266

43-
opt.contrastList = {...
44-
{'VisMot'}; ...
45-
{'VisStat'}; ...
46-
% {'VisMot-VisStatic'}; ...
47-
};
4867

4968
% Save the opt variable as a mat file to load directly in the preprocessing
5069
% scripts

getOption_template

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,44 @@ function opt = getOption()
33
% slice timing correction, pre-processing, FFX, RFX.
44

55
if nargin<1
6-
opt = [];
6+
opt = [];
77
end
88

99
% group of subjects to analyze
10-
opt.groups = {}; % {'blnd', 'ctrl'};
10+
opt.groups = {''}; % {'blnd', 'ctrl'};
1111
% suject to run in each group
12-
opt.subjects = {}; % {[1:2], [1:2]};
12+
opt.subjects = {[]}; % {[1:2], [1:2]};
13+
1314

1415
% task to analyze
15-
opt.taskName = '';
16+
opt.taskName = 'visMotion';
17+
1618

1719
% The directory where the derivatives are located
18-
opt.derivativesDir = '';
20+
opt.dataDir = '/home/remi/BIDS/visMotion/raw';
1921

20-
% Specify the number of dummies that you want to be removed.
21-
opt.numDummies = 2;
22-
opt.dummyPrefix = 'dr_';
2322

2423
% Options for slice time correction
25-
opt.STC_referenceSlice = []; % reference slice: middle acquired slice (NOTE: Middle in time of acquisition, not space)
26-
% If slice order is entered in time unit (ms) doing so, the next item (Reference Slice) will contain a reference time (in
27-
% ms) instead of the slice index of the reference slice.
24+
% If left unspecified the slice timing will be done using the mid-volume acquisition
25+
% time point as reference.
26+
% Slice order must be entered in time unit (ms) (this is the BIDS way of doing things)
27+
% instead of the slice index of the reference slice (the "SPM" way of doing things).
28+
% More info here: https://en.wikibooks.org/wiki/SPM/Slice_Timing
29+
opt.sliceOrder = [];
30+
opt.STC_referenceSlice = [];
31+
2832

2933
% Options for normalize
30-
opt.funcVoxelDims = []; % voxel dimensions to use for resampling at normalization
34+
% Voxel dimensions for resampling at normalization of functional data or leave empty [ ].
35+
opt.funcVoxelDims = [];
3136

32-
% Suffix output directory for the saved jobs
33-
opt.JOBS_dir = fullfile(opt.derivativesDir,'JOBS',opt.taskName);
3437

35-
opt.contrastList = {...
36-
{'word'}; ...
37-
{'pseudoword'}; ...
38-
% {'pseudoword-word'}; ...
39-
};
38+
% Suffix output directory for the saved jobs
39+
opt.JOBS_dir = fullfile(opt.dataDir, '..', 'derivatives', 'SPM12_CPPL', 'JOBS', opt.taskName);
4040

41-
%% SLICE TIMING INFORMATION
42-
% TO BE USED ONLY IF SPM_BIDS CAN'T EXTRACT SLICE INFORMATION
43-
opt.sliceOrder = [];
41+
% specify the model file that contains the contrasts to compute
42+
opt.model.univariate.file = '/home/remi/github/CPP_BIDS_SPM_pipeline/model-visMotionLoc_smdl.json';
4443

45-
opt.funcVoxelDims = []; % Voxel dimensions of the functional data or leave empty [ ].
4644

4745
% Save the opt variable as a mat file to load directly in the preprocessing
4846
% scripts

0 commit comments

Comments
 (0)