Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sccn/bids-matlab-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodelorme committed Nov 15, 2021
2 parents 62e9cda + 64fd4cc commit a999767
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
36 changes: 19 additions & 17 deletions bids_export.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ function bids_export(files, varargin)
'anattype' '' {} 'T1w';
'chanlocs' '' {} '';
'chanlookup' 'string' {} '';
'interactive' 'string' {'on' 'off'} 'off';
'defaced' 'string' {'on' 'off'} 'on';
'createids' 'string' {'on' 'off'} 'on';
'singleEventsJson' 'string' {'on' 'off'} 'on';
'individualEventsJson' 'string' {'on' 'off'} 'off';
'exportext' 'string' { 'edf' 'eeglab' } 'eeglab';
'README' 'string' {} '';
'CHANGES' 'string' {} '' ;
Expand All @@ -277,21 +278,22 @@ function bids_export(files, varargin)

% deleting folder
fprintf('Exporting data to %s...\n', opt.targetdir);
if exist(opt.targetdir,'dir')
uilist = { ...
{ 'Style', 'text', 'string', 'Output directory exists and all current files will be deleted if continue', 'fontweight', 'bold' }, ...
{ 'Style', 'text', 'string', 'Would you want to proceed?'}, ...
};
geometry = { [1] [1]};
geomvert = [1 1 ];
[results,userdata,isOk,restag] = inputgui( 'geometry', geometry, 'geomvert', geomvert, 'uilist', uilist, 'title', 'Warning');
if isempty(isOk)
disp('BIDS export cancelled...')
return
else
disp('Deleting folder...')
rmdir(opt.targetdir, 's');
if exist(opt.targetdir,'dir')
if strcmpi(opt.interactive, 'on')
uilist = { ...
{ 'Style', 'text', 'string', 'Output directory exists and all current files will be deleted if continue', 'fontweight', 'bold' }, ...
{ 'Style', 'text', 'string', 'Would you want to proceed?'}, ...
};
geometry = { [1] [1]};
geomvert = [1 1 ];
[results,userdata,isOk,restag] = inputgui( 'geometry', geometry, 'geomvert', geomvert, 'uilist', uilist, 'title', 'Warning');
if isempty(isOk)
disp('BIDS export cancelled...')
return
end
end
disp('Folder exist. Deleting folder...')
rmdir(opt.targetdir, 's');
end

disp('Creating sub-directories...')
Expand Down Expand Up @@ -473,7 +475,7 @@ 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')
if strcmpi(opt.individualEventsJson, 'off')
jsonwrite(fullfile(opt.targetdir, ['task-' opt.taskName '_events.json' ]), opt.eInfoDesc,struct('indent',' '));
end

Expand Down Expand Up @@ -764,7 +766,7 @@ function copy_data_bids(fileIn, fileOut, notes, opt, chanlocs, copydata, exportE
[folderOut,fileOut,~] = fileparts(fileOut);
fileOut = fullfile(folderOut,fileOut);
if ~isempty(EEG.event)
if strcmpi(opt.singleEventsJson,'off')
if strcmpi(opt.individualEventsJson,'on')
jsonwrite([ fileOut(1:end-3) 'events.json' ], opt.eInfoDesc,struct('indent',' '));
end
% --- _events.tsv
Expand Down
10 changes: 7 additions & 3 deletions pop_exportbids.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{ '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' }, ...
{ 'Style', 'checkbox', 'string', 'Export individual 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] [1]};
Expand All @@ -81,7 +81,7 @@
% end

% options
options = { 'targetdir' restag.outputfolder 'License' restag.license 'CHANGES' restag.changes 'createids' fastif(restag.newids, 'on', 'off') 'singleEventsJson' fastif(restag.eventsJson, 'on', 'off')};
options = { 'targetdir' restag.outputfolder 'License' restag.license 'CHANGES' restag.changes 'createids' fastif(restag.newids, 'on', 'off') 'individualEventsJson' 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 Expand Up @@ -180,7 +180,11 @@
if ~isempty(pInfo)
options = [options 'pInfo' {pInfo}];
end
bids_export(subjects, options{:});
if nargin < 3
bids_export(subjects, 'interactive', 'on', options{:});
else
bids_export(subjects, options{:});
end
disp('Done');

% history
Expand Down
50 changes: 26 additions & 24 deletions rename_brainvision_files.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,33 @@ function rename_brainvision_files(varargin)
fclose(fid1);
fclose(fid2);

oldmarkerfile = fullfile(pathIn , oldmarkerfile);
newmarkerfile = fullfile(pathOut, newmarkerfile);
assert(exist(newmarkerfile, 'file')==0, 'the file %s already exists', newmarkerfile);
fid1 = fopen(oldmarkerfile, 'r');
fid2 = fopen(newmarkerfile, 'w');
if exist('oldmarkerfile', 'var')
oldmarkerfile = fullfile(pathIn , oldmarkerfile);
newmarkerfile = fullfile(pathOut, newmarkerfile);
assert(exist(newmarkerfile, 'file')==0, 'the file %s already exists', newmarkerfile);
fid1 = fopen(oldmarkerfile, 'r');
fid2 = fopen(newmarkerfile, 'w');

while ~feof(fid1)
line = fgetl(fid1);
if ~isempty(regexp(line, '^HeaderFile', 'once'))
[~, rem] = strtok(line, '=');
oldheaderfile = rem(2:end);
[~, ~, x] = fileparts(oldheaderfile);
newheaderfile = [baseNameOut switchcase(x)];
line = sprintf('HeaderFile=%s', newheaderfile);
elseif ~isempty(regexp(line, '^DataFile', 'once'))
[~, rem] = strtok(line, '=');
olddatafile = rem(2:end);
[~, ~, x] = fileparts(olddatafile);
newdatafile = [baseNameOut switchcase('.eeg')];
line = sprintf('DataFile=%s', newdatafile);
end
fprintf(fid2, '%s\r\n', line);
while ~feof(fid1)
line = fgetl(fid1);
if ~isempty(regexp(line, '^HeaderFile', 'once'))
[~, rem] = strtok(line, '=');
oldheaderfile = rem(2:end);
[~, ~, x] = fileparts(oldheaderfile);
newheaderfile = [baseNameOut switchcase(x)];
line = sprintf('HeaderFile=%s', newheaderfile);
elseif ~isempty(regexp(line, '^DataFile', 'once'))
[~, rem] = strtok(line, '=');
olddatafile = rem(2:end);
[~, ~, x] = fileparts(olddatafile);
newdatafile = [baseNameOut switchcase('.eeg')];
line = sprintf('DataFile=%s', newdatafile);
end
fprintf(fid2, '%s\r\n', line);
end
fclose(fid1);
fclose(fid2);
end
fclose(fid1);
fclose(fid2);

olddatafile = fullfile(pathIn , olddatafile);
newdatafile = fullfile(pathOut, newdatafile);
Expand All @@ -114,4 +116,4 @@ function rename_brainvision_files(varargin)
try delete(oldheaderfile); end
try delete(oldmarkerfile); end
try delete(olddatafile); end
end
end

0 comments on commit a999767

Please sign in to comment.