Skip to content

Commit 33706ec

Browse files
committed
mh fix
1 parent e8fd1a7 commit 33706ec

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

src/readAndFilterLogfile.m

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
% (C) Copyright 2020 CPP_BIDS developers
2+
13
function outputFiltered = readAndFilterLogfile(columnName, filterBy, saveOutputTsv, varargin)
24
% outputFiltered = readAndFilterLogfile(columnName, filterBy, saveOutputTsv, varargin)
35
%
@@ -18,31 +20,31 @@
1820
%
1921
% - outputFiltered: dataset with only the specified content, to see it in the command window
2022
% use display(outputFiltered)
21-
23+
2224
% Create tag to add to output file in case you want to save it
2325
outputFilterTag = ['_filteredBy-' columnName '_' filterBy '.tsv'];
24-
26+
2527
% Checke if input is cfg or the file path and assign the output filename for later saving
2628
if ischar(varargin{1})
27-
29+
2830
tsvFile = varargin{1};
29-
31+
3032
elseif isstruct(varargin{1})
31-
33+
3234
tsvFile = fullfile(varargin{1}.dir.outputSubject, ...
33-
varargin{1}.fileName.modality, ...
34-
varargin{1}.fileName.events);
35-
35+
varargin{1}.fileName.modality, ...
36+
varargin{1}.fileName.events);
37+
3638
end
37-
39+
3840
% Create output file name
3941
outputFileName = strrep(tsvFile, '.tsv', outputFilterTag);
40-
42+
4143
% Check if the file exists
4244
if ~exist(tsvFile, 'file')
4345
error([newline 'Input file does not exist: %s'], tsvFile);
4446
end
45-
47+
4648
try
4749
% Read the the tsv file and store each column in a field of `output` structure
4850
output = bids.util.tsvread(tsvFile);
@@ -52,25 +54,23 @@
5254
% Read the the tsv file and store each column in a field of `output` structure
5355
output = bids.util.tsvread(tsvFile);
5456
end
55-
57+
5658
% Get the index of the target contentent to filter and display
5759
filterIdx = strncmp(output.(columnName), filterBy, length(filterBy));
58-
60+
5961
% apply the filter
60-
listFields = fieldnames(output);
62+
listFields = fieldnames(output);
6163
for iField = 1:numel(listFields)
6264
output.(listFields{iField})(~filterIdx) = [];
6365
end
64-
66+
6567
% Convert the structure to dataset
6668
outputFiltered = struct2dataset(output);
67-
69+
6870
if saveOutputTsv
6971

7072
bids.util.tsvwrite(outputFileName, output);
71-
72-
end
73-
74-
end
7573

74+
end
7675

76+
end

tests/setUp.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
logFile.extraColumns.LHL24.length = 12;
2020
logFile.extraColumns.is_Fixation.length = 1;
2121

22-
end
22+
end

tests/test_readAndFilterLogfile.m

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function test_readAndFilterLogfileBasic()
2222
logFile(end, 1).Speed = 2;
2323
logFile(end, 1).is_Fixation = true;
2424
logFile(end, 1).LHL24 = 1:12;
25-
25+
2626
logFile(2, 1).onset = 2;
2727
logFile(end, 1).trial_type = 'motion_down';
2828
logFile(end, 1).duration = 3;
@@ -34,44 +34,43 @@ function test_readAndFilterLogfileBasic()
3434

3535
% close the file
3636
saveEventsFile('close', cfg, logFile);
37-
37+
3838
% filter file
3939
outputFiltered = readAndFilterLogfile('trial_type', 'motion_down', true, cfg);
4040

4141
%% test
4242
expectedFilename = strrep(cfg.fileName.events, '.tsv', ...
43-
['_filteredBy-' 'trial_type' '_' 'motion_down' '.tsv']);
43+
['_filteredBy-' 'trial_type' '_' 'motion_down' '.tsv']);
4444
expectedFile = fullfile(cfg.dir.outputSubject, ...
45-
cfg.fileName.modality, ...
46-
expectedFilename);
45+
cfg.fileName.modality, ...
46+
expectedFilename);
47+
48+
assertEqual(exist(expectedFile, 'file'), 2);
4749

48-
assertEqual(exist(expectedFile, 'file'), 2)
49-
5050
content = bids.util.tsvread(expectedFile);
51-
52-
assertEqual(content.trial_type{1}, 'motion_down')
53-
54-
end
5551

52+
assertEqual(content.trial_type{1}, 'motion_down');
53+
54+
end
5655

5756
function test_readAndFilterLogfileFromFile()
5857

5958
%% set up
60-
59+
6160
inputFile = fullfile(fileparts(mfilename('fullpath')), 'dummyData', ...
62-
'sub-blind01_ses-01_task-vislocalizer_events.tsv');
63-
61+
'sub-blind01_ses-01_task-vislocalizer_events.tsv');
62+
6463
% filter file
6564
outputFiltered = readAndFilterLogfile('trial_type', 'VisStat', true, inputFile);
6665

6766
%% test
6867
expectedFile = strrep(inputFile, '.tsv', ...
69-
['_filteredBy-' 'trial_type' '_' 'VisStat' '.tsv']);
68+
['_filteredBy-' 'trial_type' '_' 'VisStat' '.tsv']);
69+
70+
assertEqual(exist(expectedFile, 'file'), 2);
7071

71-
assertEqual(exist(expectedFile, 'file'), 2)
72-
7372
content = bids.util.tsvread(expectedFile);
74-
75-
assertEqual(content.trial_type{1}, 'VisStat')
76-
73+
74+
assertEqual(content.trial_type{1}, 'VisStat');
75+
7776
end

tests/test_saveEventsFileSave.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ function test_saveEventsFileSaveErrors()
207207

208208
end
209209

210-
211210
function content = getFileContent(cfg, logFile)
212211

213212
% check the extra columns of the header and some of the content

0 commit comments

Comments
 (0)