For the record, I edited the pop_importbids.m
file to add group
information from the participants.tsv
file.
MATLAB: added at line 539
% check group information
% -----------------------
if isempty(EEG.group) && sum(ismember(lower(bids.participants(1,:)),'group'))
bids.participantsTable = cell2table(bids.participants(2:end,:),'VariableNames',bids.participants(1,:));
[~,eegFileRawOnly] = fileparts(eegFileRaw);
isub = strtok(eegFileRawOnly,'_');
isubRow = find(ismember(bids.participantsTable.participant_id,isub));
igroup = bids.participantsTable{isubRow(1), ismember(lower(bids.participants(1,:)),'group')};
EEG.group = igroup{1};
end
Attempting to share this to be part of the plugin.
I’ve done something similar to add condition
information using the ‘samples.tsv’ file, but the samples file seems to be less standardised in terms of BIDS, so the code is more bespoke. Included here for reference: happy to help others would want to do something similar.
This involves loading the samples.tsv
file around line 190:
% load samples file
samplesFile = fullfile(bidsFolder, 'samples.tsv');
bids.samples = '';
pInd = 1;
if exist(samplesFile,'File')
bids.samples = bids_loadfile( samplesFile );
if ~isempty(bids.samples) && ~isequal(bids.samples{1}, 'participant_id')
pInd = find(cellfun(@(x)contains(x, 'participant_id'), bids.samples(1,:))); % sometime special chars
if isempty(pInd)
error('Cannot find participant_id column')
end
end
end
And then finding the ‘condition’ variable for a specific subject id - note: for our experiment, we had 4 runs per subject so there were two levels of matching here - around line 500: after EEG = eeg_checkset(EEG);
% check condition information
if isempty(EEG.condition) && sum(ismember(lower(bids.samples(1,:)),'sample_type')) && sum(ismember(lower(bids.samples(1,:)),'run'))
bids.samplesTable = cell2table(bids.samples(2:end,:),'VariableNames',bids.samples(1,:));
[~,eegFileRawOnly] = fileparts(eegFileRaw);
isub = strtok(eegFileRawOnly,'_');
isubRow = ismember(bids.samplesTable.participant_id,isub);
iRunRow = ismember(bids.samplesTable.run,iRun);
isubRunRow = find(isubRow + iRunRow == 2);
icondition = bids.samplesTable.sample_type{isubRunRow(1)};
EEG.condition = icondition;
end