Skip to content

Commit

Permalink
add option to export single top-level events.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dungscout96 committed Oct 8, 2021
1 parent 1d17c90 commit 030b105
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions bids_export.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ function bids_export(files, varargin)
'chanlookup' 'string' {} '';
'defaced' 'string' {'on' 'off'} 'on';
'createids' 'string' {'on' 'off'} 'on';
'singleEventsJson' 'string' {'on' 'off'} 'on';
'exportext' 'string' { 'edf' 'eeglab' } 'eeglab';
'README' 'string' {} '';
'CHANGES' 'string' {} '' ;
Expand Down Expand Up @@ -457,6 +458,9 @@ function bids_export(files, varargin)
if ~isfield(opt.eInfoDesc, fields{iField}), opt.eInfoDesc(1).(fields{iField}) = struct([]); end
opt.eInfoDesc.(fields{iField}) = checkfields(opt.eInfoDesc.(fields{iField}), eInfoDescFields, 'eInfoDesc');
end
if strcmpi(opt.singleEventsJson, 'on')
jsonwrite(fullfile(opt.targetdir, ['task-' opt.taskName '_events.json' ]), opt.eInfoDesc,struct('indent',' '));
end

% Write README files (README)
% ---------------------------
Expand Down Expand Up @@ -745,8 +749,9 @@ function copy_data_bids(fileIn, fileOut, notes, opt, chanlocs, copydata, exportE
[folderOut,fileOut,~] = fileparts(fileOut);
fileOut = fullfile(folderOut,fileOut);
if ~isempty(EEG.event)
jsonwrite([ fileOut(1:end-3) 'events.json' ], opt.eInfoDesc,struct('indent',' '));

if strcmpi(opt.singleEventsJson,'off')
jsonwrite([ fileOut(1:end-3) 'events.json' ], opt.eInfoDesc,struct('indent',' '));
end
% --- _events.tsv

fid = fopen( [ fileOut(1:end-3) 'events.tsv' ], 'w');
Expand Down
7 changes: 4 additions & 3 deletions pop_exportbids.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@
{ 'Style', 'pushbutton', 'string', 'Edit participants' 'tag' 'participants' 'callback' cb_participants }, ...
{ 'Style', 'pushbutton', 'string', 'Edit event info' 'tag' 'events' 'callback' cb_events }, ...
{ 'Style', 'checkbox', 'string', 'Do not use participants ID and create anonymized participant ID instead' 'tag' 'newids' }, ...
{ 'Style', 'checkbox', 'string', 'Use single top-level events.json' 'tag' 'eventsJson' }, ...
};
relSize = 0.7;
geometry = { [1] [1] [1-relSize relSize*0.8 relSize*0.2] [1-relSize relSize] [1] [1] [1 1 1] [1] };
geomvert = [1 0.2 1 1 1 3 1 1 ];
geometry = { [1] [1] [1-relSize relSize*0.8 relSize*0.2] [1-relSize relSize] [1] [1] [1 1 1] [1] [1]};
geomvert = [1 0.2 1 1 1 3 1 1 1];
userdata.EEG = EEG;
userdata.STUDY = STUDY;
[results,userdata,~,restag] = inputgui( 'geometry', geometry, 'geomvert', geomvert, 'uilist', uilist, 'helpcom', 'pophelp(''pop_exportbids'');', 'title', 'Export EEGLAB STUDY to BIDS -- pop_exportbids()', 'userdata', userdata );
Expand All @@ -80,7 +81,7 @@
% end

% options
options = { 'targetdir' restag.outputfolder 'License' restag.license 'CHANGES' restag.changes 'createids' fastif(restag.newids, 'on', 'off') };
options = { 'targetdir' restag.outputfolder 'License' restag.license 'CHANGES' restag.changes 'createids' fastif(restag.newids, 'on', 'off') 'singleEventsJson' fastif(restag.eventsJson, 'on', 'off')};

if ~isfield(EEG(1), 'BIDS') % none of the edit button was clicked
EEG = pop_eventinfo(EEG, STUDY, 'default');
Expand Down

0 comments on commit 030b105

Please sign in to comment.