Skip to content

Commit f04835c

Browse files
authored
Merge pull request #12 from Remi-Gau/remi-doc
improve doc
2 parents 3ccbe22 + 07f4c87 commit f04835c

File tree

5 files changed

+159
-52
lines changed

5 files changed

+159
-52
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*DS_Store
2+
3+
*.m~
4+
*octave-workspace
5+
6+
# exclude content of logfiles folders
7+
*.tsv
8+
*.mat

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
A set of function for matlab and octave to create [BIDS-compatible](https://bids-specification.readthedocs.io/en/stable/) folder structure and filenames for the output of behavioral, EEG, fMRI, eyetracking studies.
44

5+
Here are the naming templates used.
6+
7+
- BOLD
8+
9+
`sub-<label>[_ses-<label>]_task-<label>[_acq-<label>][_ce-<label>][_dir-<label>][_rec-<label>][_run-<index>][_echo-<index>]_<contrast_label>.nii[.gz]`
10+
11+
- iEEG
12+
13+
`sub-<label>[_ses-<label>]_task-<task_label>[_run-<index>]_ieeg.json`
14+
15+
- EEG
16+
17+
`sub-<label>[_ses-<label>]_task-<label>[_run-<index>]_eeg.<manufacturer_specific_extension>`
18+
19+
- Eyetracker
20+
21+
`sub-<participant_label>[_ses-<label>][_acq-<label>]_task-<task_label>_eyetrack.<manufacturer_specific_extension>`
22+
523

624
## Contributing
725

@@ -12,17 +30,72 @@ Feel free to open issues to report a bug and ask for improvements.
1230
- We use camelCase.
1331
- We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/matlab_checkcode) below 15.
1432

33+
## How to install
1534

16-
## Functions descriptions
35+
### Use the matlab package manager
36+
37+
This repository can be added as a dependencies by listing it in a [mpm-requirements.txt file](.mpm-requirements.txt)
38+
as follows:
39+
40+
```
41+
CPP_BIDS -u https://github.com/cpp-lln-lab/CPP_BIDS.git
42+
```
43+
44+
You can then use the [matlab package manager](https://github.com/mobeets/mpm), to simply download the appropriate version of those dependencies and add them to your path by running a `getDependencies` function like the one below where you just need to replace `YOUR_EXPERIMENT_NAME` by the name of your experiment.
1745

1846

47+
```matlab
48+
function getDependencies(action)
49+
% Will install on your computer the matlab dependencies specified in the mpm-requirements.txt
50+
% and add them to the matlab path. The path is never saved so you need to run getDependencies() when
51+
% you start matlab.
52+
%
53+
% getDependencies('update') will force the update and overwrite previous version of the dependencies.
54+
%
55+
% getDependencies() If you only already have the appropriate version but just want to add them to the matlab path.
56+
57+
experimentName = YOUR_EXPERIMENT_NAME;
58+
59+
if nargin<1
60+
action = '';
61+
end
62+
63+
switch action
64+
case 'update'
65+
% install dependencies
66+
mpm install -i mpm-requirements.txt -f -c YOUR_EXPERIMENT_NAME
67+
end
68+
69+
% adds them to the path
70+
mpm_folder = fileparts(which('mpm'));
71+
addpath(genpath(fullfile(mpm_folder, 'mpm-packages', 'mpm-collections', experimentName)));
72+
73+
end
74+
```
75+
76+
## Functions descriptions
77+
1978
### userInputs
2079

80+
Get subject, run and session number and make sure they are positive integer values.
81+
2182

2283
### createFilename
2384

85+
Create the BIDS compliant directories and filenames (but not the files) for the behavioral output for this subject /
86+
session / run.
87+
88+
Will also create the right filename for the eye-tracking data file.
89+
90+
For the moment the date of acquisition is appended to the filename
91+
- can work for behavioral experiment if cfg.device is set to 'PC'
92+
- can work for fMRI experiment if cfg.device is set to 'scanner'
93+
- can work for simple eyetracking data if cfg.eyeTracker is set to 1
2494

2595
### saveEventsFile
2696

97+
Function to save output files for events that will be BIDS compliant.
98+
2799

28100
### checkCFG
101+
Check that we have all the fields that we need in the experiment parameters.

createFilename.m

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function expParameters = createFilename(expParameters, cfg)
22
% create the BIDS compliant directories and filenames for the behavioral output for this subject /
3-
% session / run.
3+
% session / run using the information from cfg and expParameters.
44
% Will also create the right filename for the eyetracking data file.
55
%
6-
% For the moment the date of acquisition is appreneded to the filename
6+
% For the moment the date of acquisition is appended to the filename
77
%
88
% can work for behavioral experiment if cfg.device is set to 'PC'
99
% can work for fMRI experiment if cfg.device is set to 'scanner'
@@ -20,6 +20,9 @@
2020
%
2121
% EYETRACKER
2222
% sub-<participant_label>[_ses-<label>][_acq-<label>]_task-<task_label>_eyetrack.<manufacturer_specific_extension>
23+
%
24+
%
25+
% See test_createFilename in the test folder for more details on how to use it.
2326

2427
zeroPadding = 3;
2528
pattern = ['%0' num2str(zeroPadding) '.0f'];
@@ -97,50 +100,50 @@
97100
%% create filenames
98101

99102
switch modality
100-
103+
101104
case 'beh'
102-
105+
103106
expParameters.fileName.events = ...
104107
[expParameters.fileName.base, runSuffix, '_events_date-' expParameters.date '.tsv'];
105-
108+
106109
case 'func'
107-
110+
108111
expParameters.fileName.events = ...
109112
[expParameters.fileName.base, ...
110113
expParameters.acqSuffix, expParameters.ceSuffix, ...
111114
expParameters.dirSuffix, expParameters.recSuffix, ...
112115
runSuffix, expParameters.echoSuffix, ...
113116
'_events_date-' expParameters.date '.tsv'];
114-
117+
115118
end
116119

117120
if cfg.eyeTracker
118-
121+
119122
expParameters.fileName.eyetracker = ...
120123
[expParameters.fileName.base, expParameters.acqSuffix, ...
121124
runSuffix, '_eyetrack_date-' expParameters.date '.edf'];
122-
125+
123126
end
124127

125128
if expParameters.verbose
126-
129+
127130
fprintf(1,'\nData will be saved in this directory:\n\t%s\n', ...
128131
fullfile(expParameters.outputDir, modality));
129-
132+
130133
fprintf(1,'\nData will be saved in this file:\n\t%s\n', ...
131134
expParameters.fileName.events);
132-
135+
133136
if cfg.eyeTracker
134-
137+
135138
fprintf(1,'\nEyetracking data will be saved in this directory:\n\t%s\n', ...
136139
fullfile(expParameters.outputDir, 'eyetracker'));
137140

138141
fprintf(1,'\nEyetracking data will be saved in this file:\n\t%s\n', ...
139142
expParameters.fileName.eyetracker);
140-
143+
141144
end
142-
145+
143146
end
144147

145148

146-
end
149+
end

saveEventsFile.m

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,108 @@
1-
function [ logFile ] = saveEventsFile(input, expParameters, logFile, varargin)
1+
function [ logFile ] = saveEventsFile(action, expParameters, logFile, varargin)
2+
% Function to save output files for events that will be BIDS compliant.
3+
%
4+
% INPUTS
5+
%
6+
% action:
7+
% - 'open': will create the file ID and return it in logFile.eventLogFile using the information in
8+
% the expParameters structure. This file ID is then reused when calling that function to save data
9+
% into this file.
10+
% This creates the header with the obligatory 'onset', 'trial_type', 'duration' required bt BIDS and other
11+
% coluns can be specified in varargin.
12+
% example : logFile = saveEventsFile('open', expParameters, [], 'direction', 'speed', 'target');
13+
%
14+
% - 'save': will save the data contained in logfile by using the file ID logFile.eventLogFile;
15+
% logfile must then contain:
16+
% - logFile.onset
17+
% - logFile.trial_type
18+
% - logFile.duration
19+
% The name of any extra column whose content must be saved should be listed in varargin.
20+
%
21+
% - 'close': closes the file with file ID logFile.eventLogFile. If expParameters.verbose is set to true
22+
% then this will tell you where the file is located.
23+
%
24+
% See test_saveEventsFile in the test folder for more details on how to use it.
225

326
if nargin<3 || isempty(logFile)
427
logFile = struct();
528
end
629

7-
switch input
8-
30+
switch action
31+
932
case 'open'
10-
33+
1134
logFile = struct();
12-
35+
1336
% Initialize txt logfiles and empty fields for the standard BIDS
1437
% event file
1538
logFile.eventLogFile = fopen(...
1639
fullfile(expParameters.outputDir, expParameters.modality, expParameters.fileName.events), ...
1740
'w');
18-
41+
1942
% print the basic BIDS columns
2043
fprintf(logFile.eventLogFile, '%s\t%s\t%s\t', 'onset', 'trial_type', 'duration');
21-
44+
2245
% print any extra column specified by the user
2346
% also prepare an empty field in the structure to collect data
2447
% for those
2548
for iExtraColumn = 1:numel(varargin)
2649
fprintf(logFile.eventLogFile,'%s\t', lower(varargin{iExtraColumn}));
2750
end
28-
51+
2952
% next line so we start printing at the right place
3053
fprintf(logFile.eventLogFile, '\n');
31-
32-
54+
55+
3356
case 'save'
34-
57+
3558
% appends to the logfile all the data stored in the structure
3659
% first with the standard BIDS data and then any extra things
3760
for iEvent = 1:size(logFile,1)
38-
61+
3962
fprintf(logFile(1).eventLogFile,'%f\t%s\t%f\t',...
4063
logFile(iEvent).onset, ...
4164
logFile(iEvent).trial_type, ...
4265
logFile(iEvent).duration);
43-
66+
4467
for iExtraColumn = 1:numel(varargin)
45-
68+
4669
% if the field we are looking for does not exist or is empty in the
47-
% input logFile structure we will write a NaN otherwise we
70+
% action logFile structure we will write a NaN otherwise we
4871
% write its content
49-
72+
5073
if ~isfield(logFile, varargin{iExtraColumn})
5174
data = [];
5275
else
5376
data = getfield(logFile(iEvent), varargin{iExtraColumn});
5477
end
55-
78+
5679
if isempty(data)
5780
data = NaN;
5881
end
59-
82+
6083
if ischar(data)
6184
fprintf(logFile(1).eventLogFile, '%s\t', data);
6285
else
6386
fprintf(logFile(1).eventLogFile, '%f\t', data);
6487
end
65-
88+
6689
end
67-
90+
6891
fprintf(logFile(1).eventLogFile, '\n');
6992
end
70-
93+
7194
case 'close'
72-
95+
7396
% close txt log file
7497
fclose(logFile(1).eventLogFile);
75-
98+
7699
if expParameters.verbose
77100
fprintf(1,'\nData were saved in this file:\n\n%s\n\n', ...
78101
fullfile(...
79102
expParameters.outputDir, ...
80103
expParameters.modality, ...
81104
expParameters.fileName.events));
82-
105+
83106
end
84-
85-
end
107+
108+
end

userInputs.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function [expParameters] = userInputs(cfg, expParameters)
2-
% Get subject, run and session number and mae sure they are
2+
% Get subject, run and session number and make sure they are
33
% positive integer values
44

55
if nargin<1
@@ -12,25 +12,25 @@
1212

1313

1414
if cfg.debug
15-
15+
1616
subjectGrp = 'ctrl';
1717
subjectNb = 666;
1818
runNb = 666;
1919
sessionNb = 666;
20-
20+
2121
else
22-
22+
2323
subjectGrp = lower(input('Enter subject group (leave empty if none): ', 's'));
24-
24+
2525
subjectNb = str2double(input('Enter subject number (1-999): ', 's') );
2626
subjectNb = checkInput(subjectNb);
27-
27+
2828
sessionNb = str2double(input('Enter the session (i.e day - 1-999)) number: ', 's'));
2929
sessionNb = checkInput(sessionNb);
30-
30+
3131
runNb = str2double(input('Enter the run number (1-999): ', 's'));
3232
runNb = checkInput(runNb);
33-
33+
3434
end
3535

3636

@@ -51,4 +51,4 @@
5151
end
5252

5353

54-
end
54+
end

0 commit comments

Comments
 (0)