From 030b105ce214208694d71ef0650d57ac632341df Mon Sep 17 00:00:00 2001 From: Dung Truong Date: Thu, 7 Oct 2021 23:38:19 -0700 Subject: [PATCH] add option to export single top-level events.json --- bids_export.m | 9 +++++++-- pop_exportbids.m | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bids_export.m b/bids_export.m index 2f6f829..3e93808 100644 --- a/bids_export.m +++ b/bids_export.m @@ -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' {} '' ; @@ -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) % --------------------------- @@ -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'); diff --git a/pop_exportbids.m b/pop_exportbids.m index 41528cb..9062a42 100644 --- a/pop_exportbids.m +++ b/pop_exportbids.m @@ -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 ); @@ -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');