Skip to content

Commit 3f55efd

Browse files
committed
update saveEvents to new cfg
1 parent 89897ce commit 3f55efd

File tree

5 files changed

+85
-86
lines changed

5 files changed

+85
-86
lines changed

saveEventsFile.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@
116116

117117
fprintf(1, '\nData were saved in this file:\n\n%s\n\n', ...
118118
fullfile( ...
119-
cfg.subjectOutputDir, ...
120-
cfg.modality, ...
119+
cfg.dir.outputSubject, ...
120+
cfg.fileName.modality, ...
121121
logFile.filename));
122122

123123
otherwise
@@ -179,8 +179,8 @@
179179
% event file
180180
logFile.fileID = fopen( ...
181181
fullfile( ...
182-
cfg.subjectOutputDir, ...
183-
cfg.modality, ...
182+
cfg.dir.outputSubject, ...
183+
cfg.fileName.modality, ...
184184
logFile.filename), ...
185185
'w');
186186

tests/test_saveEventsFileInit.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function test_saveEventsFileInit()
2121
clear;
2222

2323
%%% set up
24-
cfg = checkCFG();
24+
cfg = checkCFG();
2525
logFile.extraColumns = {'Speed'};
2626

2727
%%% do stuff
@@ -42,7 +42,7 @@ function test_saveEventsFileInit()
4242
clear;
4343

4444
%%% set up
45-
cfg = checkCFG();
45+
cfg = checkCFG();
4646
logFile.extraColumns.Speed.length = 1;
4747
logFile.extraColumns.LHL24.length = 3;
4848

tests/test_saveEventsFileOpen.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function test_saveEventsFileOpen()
77

88
%%% set up
99

10-
cfg.subjectNb = 1;
11-
cfg.runNb = 1;
12-
cfg.task = 'testtask';
13-
cfg.outputDir = outputDir;
10+
cfg.subject.subjectNb = 1;
11+
cfg.subject.runNb = 1;
12+
cfg.task.name = 'testtask';
13+
cfg.dir.output = outputDir;
1414

1515
cfg.testingDevice = 'mri';
1616

@@ -29,14 +29,13 @@ function test_saveEventsFileOpen()
2929
% test data
3030
funcDir = fullfile(outputDir, 'source', 'sub-001', 'ses-001', 'func');
3131
eventFilename = ['sub-001_ses-001_task-testtask_run-001_events_date-' ...
32-
cfg.date '.tsv'];
33-
34-
% open the file
35-
FID = fopen(fullfile(funcDir, eventFilename), 'r');
36-
C = textscan(FID, repmat('%s', 1, 3), 'Delimiter', '\t', 'EndOfLine', '\n');
32+
cfg.fileName.date '.tsv'];
3733

3834
% check that the file has the right path and name
3935
assert(exist(fullfile(funcDir, eventFilename), 'file') == 2);
36+
37+
FID = fopen(fullfile(funcDir, eventFilename), 'r');
38+
C = textscan(FID, repmat('%s', 1, 3), 'Delimiter', '\t', 'EndOfLine', '\n');
4039

4140
% check the extra columns of the header
4241
assert(isequal(C{1}{1}, 'onset'));
@@ -52,10 +51,10 @@ function test_saveEventsFileOpen()
5251

5352
%%% set up
5453

55-
cfg.subjectNb = 1;
56-
cfg.runNb = 1;
57-
cfg.task = 'testtask';
58-
cfg.outputDir = outputDir;
54+
cfg.subject.subjectNb = 1;
55+
cfg.subject.runNb = 1;
56+
cfg.task.name = 'testtask';
57+
cfg.dir.output = outputDir;
5958

6059
cfg.testingDevice = 'mri';
6160

@@ -64,7 +63,7 @@ function test_saveEventsFileOpen()
6463

6564
%%% do stuff
6665

67-
cfg = createFilename(cfg);
66+
cfg = createFilename(cfg);
6867

6968
% create the events file and header
7069
logFile = saveEventsFile('open', cfg, logFile);
@@ -75,12 +74,11 @@ function test_saveEventsFileOpen()
7574
%%% test section
7675

7776
% open the file
77+
funcDir = fullfile(cfg.dir.outputSubject, cfg.fileName.modality);
78+
eventFilename = cfg.fileName.events;
79+
7880
nbExtraCol = 2;
79-
FID = fopen(fullfile( ...
80-
cfg.subjectOutputDir, ...
81-
cfg.modality, ...
82-
cfg.fileName.events), ...
83-
'r');
81+
FID = fopen(fullfile(funcDir, eventFilename), 'r');
8482
C = textscan(FID, repmat('%s', 1, nbExtraCol + 3), 'Delimiter', '\t', 'EndOfLine', '\n');
8583

8684
% check the extra columns of the header
@@ -89,5 +87,7 @@ function test_saveEventsFileOpen()
8987
assert(isequal(C{3}{1}, 'trial_type'));
9088
assert(isequal(C{4}{1}, 'Speed'));
9189
assert(isequal(C{5}{1}, 'is_Fixation'));
90+
91+
9292

9393
end
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
function test_saveEventsFileOpenMultiColumn()
2-
2+
33
%% check header writing with several columns for one variable
44
clear;
5-
5+
66
outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
7-
7+
88
%%% set up
9-
10-
cfg.subjectNb = 1;
11-
cfg.runNb = 1;
12-
cfg.task = 'testtask';
13-
cfg.outputDir = outputDir;
14-
9+
10+
cfg.subject.subjectNb = 1;
11+
cfg.subject.runNb = 1;
12+
cfg.task.name = 'testtask';
13+
cfg.dir.output = outputDir;
14+
1515
cfg.testingDevice = 'mri';
16-
17-
cfg = createFilename(cfg);
18-
16+
17+
cfg = createFilename(cfg);
18+
1919
% define the extra columns: here we specify how many columns we want for
2020
% each variable
2121
logFile.extraColumns.Speed.length = 1; % will set 1 columns with name Speed
2222
logFile.extraColumns.LHL24.length = 12; % will set 12 columns with names LHL24-01, LHL24-02, ...
2323
logFile.extraColumns.is_Fixation = []; % will set 1 columns with name is_Fixation
24-
24+
2525
%%% do stuff
26-
26+
2727
% create the events file and header
2828
logFile = saveEventsFile('open', cfg, logFile);
29-
29+
3030
% close the file
3131
saveEventsFile('close', cfg, logFile);
32-
32+
3333
%%% test section
34-
34+
3535
% check the extra columns of the header and some of the content
36+
funcDir = fullfile(cfg.dir.outputSubject, cfg.fileName.modality);
37+
eventFilename = cfg.fileName.events;
38+
3639
nbExtraCol = ...
3740
logFile(1).extraColumns.Speed.length + ...
3841
logFile(1).extraColumns.LHL24.length + ...
3942
logFile(1).extraColumns.is_Fixation.length;
40-
FID = fopen(fullfile( ...
41-
cfg.subjectOutputDir, ...
42-
cfg.modality, ...
43-
cfg.fileName.events), ...
44-
'r');
43+
44+
FID = fopen(fullfile(funcDir, eventFilename), 'r');
4545
C = textscan(FID, repmat('%s', 1, nbExtraCol + 3), 'Delimiter', '\t', 'EndOfLine', '\n');
46-
46+
4747
% check the extra columns of the header
4848
assert(isequal(C{4}{1}, 'Speed'));
4949
assert(isequal(C{5}{1}, 'LHL24_01'));
5050
assert(isequal(C{16}{1}, 'LHL24_12'));
5151
assert(isequal(C{17}{1}, 'is_Fixation'));
52-
52+
5353
end

tests/test_saveEventsFileSave.m

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,91 @@
11
function test_saveEventsFileSave()
2-
2+
33
%% write things in it
44
clear;
5-
5+
66
outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
7-
7+
88
%%% set up
9-
10-
cfg.subjectNb = 1;
11-
cfg.runNb = 1;
12-
cfg.task = 'testtask';
13-
cfg.outputDir = outputDir;
14-
9+
10+
cfg.subject.subjectNb = 1;
11+
cfg.subject.runNb = 1;
12+
cfg.task.name = 'testtask';
13+
cfg.dir.output = outputDir;
14+
1515
cfg.testingDevice = 'mri';
16-
17-
cfg = createFilename(cfg);
18-
16+
17+
cfg = createFilename(cfg);
18+
1919
logFile.extraColumns.Speed.length = 1;
2020
logFile.extraColumns.LHL24.length = 12;
2121
logFile.extraColumns.is_Fixation.length = 1;
22-
22+
2323
% create the events file and header
2424
logFile = saveEventsFile('open', cfg, logFile);
25-
25+
2626
%%% do stuff
27-
27+
2828
% ROW 2: normal events : all info is there
2929
logFile(1, 1).onset = 2;
3030
logFile(end, 1).trial_type = 'motion_up';
3131
logFile(end, 1).duration = 3;
3232
logFile(end, 1).Speed = 2;
3333
logFile(end, 1).is_Fixation = true;
3434
logFile(end, 1).LHL24 = 1:12;
35-
35+
3636
logFile = saveEventsFile('save', cfg, logFile);
37-
37+
3838
% ROW 3: missing info (speed, LHL24)
3939
logFile(1, 1).onset = 3;
4040
logFile(end, 1).trial_type = 'static';
4141
logFile(end, 1).duration = 4;
4242
logFile(end, 1).is_Fixation = false;
43-
43+
4444
% ROW 4: missing info (duration is missing and speed is empty)
4545
logFile(2, 1).onset = 4;
4646
logFile(end, 1).trial_type = 'motion_up';
4747
logFile(end, 1).Speed = [];
4848
logFile(end, 1).is_Fixation = true;
4949
logFile(end, 1).LHL24 = 1:12;
50-
50+
5151
% empty events
5252
logFile(3, 1).onset = [];
5353
logFile(end, 1).trial_type = [];
5454
logFile(end, 1).duration = 3;
55-
55+
5656
logFile(4, 1).onset = 1;
5757
logFile(end, 1).trial_type = '';
58-
58+
5959
% ROW 5: missing info (array is too short)
6060
logFile(5, 1).onset = 5;
6161
logFile(end, 1).trial_type = 'jazz';
6262
logFile(end, 1).duration = 3;
6363
logFile(end, 1).LHL24 = rand(1, 10);
64-
64+
6565
% ROW 6: too much info (array is too long)
6666
% logFile(5, 1).onset = 5;
6767
% logFile(end, 1).trial_type = 'blues';
6868
% logFile(end, 1).duration = 3;
6969
% logFile(end, 1).LHL24 = rand(1, 15);
70-
70+
7171
saveEventsFile('save', cfg, logFile);
72-
72+
7373
% close the file
7474
saveEventsFile('close', cfg, logFile);
75-
75+
7676
%%% test section
77-
77+
7878
% check the extra columns of the header and some of the content
7979
nbExtraCol = ...
8080
logFile(1).extraColumns.Speed.length + ...
8181
logFile(1).extraColumns.LHL24.length + ...
8282
logFile(1).extraColumns.is_Fixation.length;
83-
FID = fopen(fullfile( ...
84-
cfg.subjectOutputDir, ...
85-
cfg.modality, ...
86-
cfg.fileName.events), ...
87-
'r');
83+
84+
funcDir = fullfile(cfg.dir.outputSubject, cfg.fileName.modality);
85+
eventFilename = cfg.fileName.events;
86+
FID = fopen(fullfile(funcDir, eventFilename), 'r');
8887
C = textscan(FID, repmat('%s', 1, nbExtraCol + 3), 'Delimiter', '\t', 'EndOfLine', '\n');
89-
88+
9089
% event 1/ ROW 2: check that values are entered correctly
9190
assert(isequal(C{1}{2}, sprintf('%f', 2)));
9291
assert(isequal(C{3}{2}, 'motion_up'));
@@ -95,22 +94,22 @@ function test_saveEventsFileSave()
9594
assert(isequal(C{5}{2}, sprintf('%f', 1)));
9695
assert(isequal(C{16}{2}, sprintf('%f', 12)));
9796
assert(isequal(C{17}{2}, 'true'));
98-
97+
9998
% event 2 / ROW 3: missing info replaced by nans
10099
assert(isequal(C{4}{3}, 'n/a'));
101100
assert(isequal(C{5}{3}, 'n/a'));
102101
assert(isequal(C{16}{3}, 'n/a'));
103102
assert(isequal(C{17}{3}, 'false'));
104-
103+
105104
% event 3 / ROW 4: missing info (duration is missing and speed is empty)
106105
assert(isequal(C{2}{4}, 'n/a'));
107106
assert(isequal(C{4}{4}, 'n/a'));
108-
107+
109108
% event 4-5 / ROW 5-6: skip empty events
110109
assert(~isequal(C{1}{5}, 'n/a'));
111-
110+
112111
% check values entered properly
113112
assert(isequal(C{15}{5}, 'n/a'));
114113
assert(isequal(C{16}{5}, 'n/a'));
115-
114+
116115
end

0 commit comments

Comments
 (0)