Skip to content

Commit

Permalink
IO: Added support for channels in BIDS events .tsv
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Aug 22, 2019
1 parent e632e70 commit d5ce65b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion toolbox/core/bst_get.m
Expand Up @@ -3306,7 +3306,7 @@
argout1 = {...
{'.trg'}, 'ANT EEProbe (*.trg)', 'ANT'; ...
{'.evt'}, 'BESA (*.evt)', 'BESA'; ...
{'.tsv'}, 'BIDS events (*.tsv)', 'BIDS'; ...
{'.tsv'}, 'BIDS events: onset, duration, trial_type, channel (*.tsv)', 'BIDS'; ...
{'.vmrk'}, 'BrainVision BrainAmp (*.vmrk)', 'BRAINAMP'; ...
{'_events'}, 'Brainstorm (events*.mat)', 'BST'; ...
{'.mrk'}, 'Cartool (*.mrk)', 'CARTOOL'; ...
Expand Down
14 changes: 12 additions & 2 deletions toolbox/io/in_events_bids.m
Expand Up @@ -28,7 +28,7 @@
% Authors: Francois Tadel, 2019

% Read tsv file
Markers = in_tsv(EventFile, {'onset', 'duration', 'trial_type'});
Markers = in_tsv(EventFile, {'onset', 'duration', 'trial_type', 'channel'}, 0);
if isempty(Markers) || isempty(Markers{1,1}) || isempty(Markers{1,3})
events = [];
return;
Expand All @@ -44,12 +44,22 @@
% Get event onsets and durations
onsets = cellfun(@(c)sscanf(c,'%f',1), Markers(iMrk,1), 'UniformOutput', 0);
durations = cellfun(@(c)sscanf(c,'%f',1), Markers(iMrk,2), 'UniformOutput', 0);
channels = Markers(iMrk,4)';
% Find and reject events with no latency
iEmpty = find(cellfun(@isempty, onsets));
if ~isempty(iEmpty)
iMrk(iEmpty) = [];
onsets(iEmpty) = [];
durations(iEmpty) = [];
channels(iEmpty) = [];
end
% Channel names
for iOcc = 1:length(channels)
if (isempty(channels{iOcc}) || strcmpi(channels{iOcc}, 'n/a'))
channels{iOcc} = [];
else
channels{iOcc} = {channels{iOcc}};
end
end
% Add event structure
events(iEvt).label = uniqueEvt{iEvt};
Expand All @@ -62,7 +72,7 @@
events(iEvt).times = round(events(iEvt).times .* sFile.prop.sfreq) ./ sFile.prop.sfreq;
events(iEvt).reactTimes = [];
events(iEvt).select = 1;
events(iEvt).channels = cell(1, size(events(iEvt).times, 2));
events(iEvt).channels = channels;
events(iEvt).notes = cell(1, size(events(iEvt).times, 2));
end

Expand Down
10 changes: 7 additions & 3 deletions toolbox/io/in_tsv.m
@@ -1,4 +1,4 @@
function cTsv = in_tsv(TsvFile, ColNames)
function cTsv = in_tsv(TsvFile, ColNames, isWarning)
% IN_TSV: Reads specific columns in a .tsv file

% @=============================================================================
Expand All @@ -19,8 +19,12 @@
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2018
% Authors: Francois Tadel, 2018-2019

% Parse inputs
if (nargin < 3) || isempty(isWarning)
isWarning = 1;
end
% Intialize returned variable
cTsv = {};
% Open file
Expand Down Expand Up @@ -52,7 +56,7 @@
iCol = find(strcmpi(tsvHeader, ColNames{i}));
if ~isempty(iCol)
cTsv(:,i) = tsvValues{iCol};
else
elseif isWarning
disp(['Error: Column "' ColNames{i} '" not found in file: ' TsvFile]);
end
end
Expand Down

0 comments on commit d5ce65b

Please sign in to comment.