EEGLAB: BIDS import of condition per participant

Dear NeuroStars,

I’m new to the brain imaging data structure (BIDS: https://bids.neuroimaging.io/) practice and am attempting to organise an EEG dataset with four separate files per subject which reflect different experimental conditions.

I’m using the following naming convention for the files:
sub-001_task-auditorydesat_run-2_condition-1_eeg.edf

Using the ‘Import BIDS folder to STUDY’ option in the bids-matlab-tools v8.0 extension, my BIDS structure imports without error into EEGLAB and it’s recognising the ‘run’ of the file but not the ‘condition’ variable (or ‘group’ which is coded in a participants.tsv).

Is there anything simple that I’m missing?

Be grateful for any assistance.

Thanks,
Nic

Hi @NicBadcock,

And welcome to neurostars!

condition-<> is not a BIDS-valid label. .edf files must follow the following naming convention:

sub-<label>[_ses-<label>]_task-<label>[_acq-<label>][_run-<index>]_eeg.<extension>

so you may consider using acq-condition1 instead, making the full file name:

sub-001_task-auditorydesat_acq-condition1_run-2_eeg.edf

You can read more about the BIDS EEG specification here: Electroencephalography - Brain Imaging Data Structure v1.9.0

Best,
Steven

Thanks @Steven,

That’s very helpful. I’ve been digging into the MATLAB code but I’m not sure it’s going to recognise acq either.

I’ll keep tinkering but it’s always helpful to have a definitive answer.

Thanks again - for the answer and the warm welcome :slightly_smiling_face:
Nic

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