Skip to content

Commit 8fdb408

Browse files
authored
Merge pull request #75 from marcobarilari/marco_readOutputFilter
add readOuputFilter function
2 parents 558a247 + 4f45d95 commit 8fdb408

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

docs/functions_description.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* 1.6. [eyeTracker](#eyeTracker)
1111
* 1.7. [standByScreen](#standByScreen)
1212
* 1.8. [waitForTrigger](#waitForTrigger)
13+
* 1.9 [readAndFilterLogfile](#readAndFilterLogfile)
1314
* 2. [Keyboard functions: response collection and aborting experiment](#Keyboardfunctions:responsecollectionandabortingexperiment)
1415
* 2.1. [testKeyboards](#testKeyboards)
1516
* 2.2. [getResponse](#getResponse)
@@ -73,6 +74,9 @@ It shows a basic one-page instruction stored in `cfg.task.instruction` and wait
7374
Counts a certain number of triggers coming from the mri/scanner before returning.
7475
Requires number of triggers to wait for.
7576

77+
### 1.9 <a name='readAndFilterLogfile'></a>readAndFilterLogfile
78+
79+
Displays in the command window part of the `*events.tsv` file filterd by an element (e.g. 'trigger'). It can take the last output produced (through `cfg`) or any output BIDS compatible (through file path).
7680

7781
## 2. <a name='Keyboardfunctions:responsecollectionandabortingexperiment'></a>Keyboard functions: response collection and aborting experiment
7882

@@ -120,4 +124,4 @@ Define the parameters of the fixation cross in `cfg` and `expParameters` and thi
120124

121125
## 4. <a name='Drawingdots'></a>Drawing dots
122126

123-
## 5. <a name='Drawingapertures'></a>Drawing apertures
127+
## 5. <a name='Drawingapertures'></a>Drawing apertures

src/readAndFilterLogfile.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function outputFiltered = readAndFilterLogfile(columnName, filterBy, varargin)
2+
% outputFiltered = readOutputFilter(filterHeader, filterContent, varargin)
3+
%
4+
% It will display in the command window the content of the `output.tsv' filtered by one element
5+
% of a target column.
6+
%
7+
% DEPENDENCIES:
8+
% - bids_matlab (from CPP_BIDS)
9+
%
10+
% INPUT:
11+
%
12+
% - columnName: string, the header of the column where the content of insterest is stored
13+
% (e.g., for 'trigger' will be 'trial type')
14+
% - filterBy: string, the content of the column you want to filter out. It can take just
15+
% part of the content name (e.g., you want to display the triggers and you have
16+
% 'trigger_motion' and 'trigger_static', 'trigger' as input will do)
17+
% - varargin: either cfg (to display the last run output) or the file path as string
18+
%
19+
% OUTPUT:
20+
%
21+
% - outputFiltered: dataset with only the specified content, to see it in the command window
22+
% use display(outputFiltered)
23+
24+
% Checke if input is cfg or the file path
25+
if ischar(varargin{1})
26+
tsvFile = varargin{1};
27+
elseif isstruct(varargin{1})
28+
tsvFile = fullfile(varargin{1}.dir.outputSubject, ...
29+
varargin{1}.fileName.modality, ...
30+
varargin{1}.fileName.events);
31+
end
32+
33+
% Check if the file exists
34+
if ~exist(tsvFile, 'file')
35+
error([newline 'Input file does not exist']);
36+
end
37+
38+
% Read the the tsv file and store each column in a field of `output` structure
39+
output = bids.util.tsvread(tsvFile);
40+
41+
% Get the index of the target contentent to filter and display
42+
filterIdx = find(strncmp(output.(columnName), filterBy, length(filterBy)));
43+
44+
% Convert the structure to dataset
45+
outputDataset = struct2dataset(output);
46+
47+
% Get the dataset with the content of intereset
48+
outputFiltered = outputDataset(filterIdx, :);
49+
50+
end

0 commit comments

Comments
 (0)