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 Aug 20, 2021
2 parents 98d1788 + c51ea49 commit 35aacc3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 74 deletions.
4 changes: 2 additions & 2 deletions JSONio/LICENCE → JSONio/LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
JSONio: a MATLAB JSON library
Copyright (c) 2015-2019 Guillaume Flandin <[email protected]>
JSONio: a MATLAB/Octave JSON library
Copyright (c) 2015-2021 Guillaume Flandin <[email protected]>

The MIT License (MIT)

Expand Down
45 changes: 0 additions & 45 deletions JSONio/README

This file was deleted.

30 changes: 11 additions & 19 deletions JSONio/README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
JSONio: a MATLAB/Octave JSON library
====================================
# JSONio: a MATLAB/Octave JSON library

https://www.artefact.tk/software/matlab/jsonio/

JSONio is a MATLAB/Octave library to read/write data in the JSON (JavaScript Object Notation) data-interchange format.
JSONio is a MATLAB/Octave library to read/write data in the JSON (JavaScript Object Notation) data-interchange format.

* JSON: https://www.json.org/
* JSON: https://www.json.org/

It relies on the JSON parser jsmn written by Serge Zaitsev:
It relies on the JSON parser jsmn written by [Serge Zaitsev](https://zserge.com/):

* jsmn: https://zserge.com/jsmn.html
* jsmn: https://zserge.com/jsmn/

This library is also part of SPM:
This library is also part of SPM:

* SPM: https://www.fil.ion.ucl.ac.uk/spm/
* SPM: https://www.fil.ion.ucl.ac.uk/spm/

INSTALLATION
------------
## INSTALLATION

Simply add the JSONio directory to the MATLAB path:
Simply add the JSONio directory to the MATLAB path:

```matlab
addpath /home/login/Documents/MATLAB/JSONio
```

A compiled MEX file is provided for 64-bit MATLAB platforms. It needs to be compiled for Octave with:
A compiled MEX file is provided for 64-bit MATLAB platforms. It needs to be compiled for Octave with:
```
mkoctfile --mex jsonread.c jsmn.c -DJSMN_PARENT_LINKS
```

EXAMPLE
-------
## EXAMPLE

```matlab
json = jsonread(filename)
jsonwrite(filename, json)
```

-------------------------------------------------------------------------------
Copyright (C) 2015-2020 Guillaume Flandin <[email protected]>
Binary file removed JSONio/jsonread.mexw32
Binary file not shown.
8 changes: 6 additions & 2 deletions JSONio/jsonwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%
% FORMAT [...] = jsonwrite(...,opts)
% opts - structure or list of name/value pairs of optional parameters:
% indent: string to use for indentation [Default: '']
% prettyPrint: indent output [Default: false]
% replacementStyle: string to control how non-alphanumeric
% characters are replaced {'underscore','hex','delete','nop'}
% [Default: 'underscore']
Expand All @@ -22,13 +22,14 @@
% jsonencode: https://www.mathworks.com/help/matlab/ref/jsonencode.html

% Guillaume Flandin
% $Id: jsonwrite.m 7526 2019-02-06 14:33:18Z guillaume $
% $Id: spm_jsonwrite.m 8031 2020-12-10 13:37:00Z guillaume $


%-Input parameters
%--------------------------------------------------------------------------
opts = struct(...
'indent','',...
'prettyprint',false,...
'replacementstyle','underscore',...
'convertinfandnan',true);
opt = {struct([])};
Expand Down Expand Up @@ -61,6 +62,9 @@
if ~isfield(opts,lower(fn{i})), warning('Unknown option "%s".',fn{i}); end
opts.(lower(fn{i})) = opt.(fn{i});
end
if opts.prettyprint
opts.indent = ' ';
end
optregistry(opts);

%-JSON serialization
Expand Down
File renamed without changes.
File renamed without changes.
34 changes: 28 additions & 6 deletions pop_importbids.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
% 'eventtype' - [string] BIDS event column to use for EEGLAB event types.
% common choices are usually 'trial_type' or 'value'.
% Default is 'value'.
% 'bidstask' - [string] value of a key task- allowing to analyze some
% tasks only
%
% Outputs:
% STUDY - EEGLAB STUDY structure
Expand Down Expand Up @@ -114,6 +116,10 @@
}, 'pop_importbids');
if isstr(opt), error(opt); end

if ~exist('jsondecode.m','file')
addpath([fileparts(which('pop_importbids.m')) filesep 'JSONio'])
end

% Options:
% - copy folder
% - use channel location and event
Expand All @@ -136,7 +142,11 @@
dataset_descriptionFile = fullfile(bidsFolder, 'dataset_description.json');
bids.dataset_description = '';
if exist(dataset_descriptionFile,'File')
bids.dataset_description = jsondecode(importalltxt( dataset_descriptionFile ));
if exist('jsondecode.m','file')
bids.dataset_description = jsondecode(importalltxt( dataset_descriptionFile ));
else
bids.dataset_description = jsonread(dataset_descriptionFile);
end
end

% load participant file
Expand All @@ -155,7 +165,11 @@
participantsJSONFile = fullfile(bidsFolder, 'participants.json');
bids.participantsJSON = '';
if exist(participantsJSONFile,'File')
bids.participantsJSON = jsondecode(importalltxt( participantsJSONFile ));
if exist('jsondecode.m','file')
bids.participantsJSON = jsondecode(importalltxt( participantsJSONFile ));
else
bids.participantsJSON = jsonread(participantsJSONFile);
end
end

% scan participants
Expand Down Expand Up @@ -236,7 +250,7 @@
ind = strmatch( '.fif', cellfun(@(x)x(end-3:end), allFiles, 'uniformoutput', false) ); % FIF
if isempty(ind)
ind = strmatch( '.gz', cellfun(@(x)x(end-2:end), allFiles, 'uniformoutput', false) ); % FIF
if isempty(ind)
if isempty(ind) && ~isempty(allFiles)
fprintf(2, 'No EEG file found for subject %s\n', bids.participants{iSubject,1});
end
end
Expand Down Expand Up @@ -558,7 +572,7 @@
parent = fileparts(parent);
end
if isempty(outFile)
outFile = filterHiddenFile(folder, dir(fullfile(parent, fileName)));
outFile = filterHiddenFile(parent, dir(fullfile(parent, fileName)));
end

function fileList = filterHiddenFile(folder, fileList)
Expand Down Expand Up @@ -601,13 +615,21 @@
if strcmpi(ext, '.tsv')
data = importtsv( fullfile(localFile(1).folder, localFile(1).name));
else
data = jsondecode( importalltxt( fullfile(localFile(1).folder, localFile(1).name) ));
if exist('jsondecode.m','file')
data = jsondecode( importalltxt( fullfile(localFile(1).folder, localFile(1).name) ));
else
data = jsonread(fullfile(localFile(1).folder, localFile(1).name));
end
end
elseif ~isempty(globalFile)
if strcmpi(ext, '.tsv')
data = importtsv( fullfile(globalFile(1).folder, globalFile(1).name));
else
data = jsondecode( importalltxt( fullfile(globalFile(1).folder, globalFile(1).name) ));
if exist('jsondecode.m','file')
data = jsondecode( importalltxt( fullfile(globalFile(1).folder, globalFile(1).name) ));
else
data = jsonread(fullfile(globalFile(1).folder, globalFile(1).name));
end
end
end

Expand Down

0 comments on commit 35aacc3

Please sign in to comment.