Skip to content

Commit 4e504e5

Browse files
authored
Merge pull request #72 from Remi-Gau/remi-json_extra
allow createBoldJson to add extra content to a json file
2 parents b52ab2a + 0c03781 commit 4e504e5

File tree

5 files changed

+104
-7
lines changed

5 files changed

+104
-7
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
**BIDS validator and linter**
2-
3-
[![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_BIDS.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_BIDS)
4-
51
**Unit tests and coverage**
62

73
[![](https://img.shields.io/badge/Octave-CI-blue?logo=Octave&logoColor=white)](https://github.com/cpp-lln-lab/CPP_BIDS/actions)
84
![](https://github.com/cpp-lln-lab/CPP_BIDS/workflows/CI/badge.svg)
95

106
[![codecov](https://codecov.io/gh/cpp-lln-lab/CPP_BIDS/branch/master/graph/badge.svg)](https://codecov.io/gh/cpp-lln-lab/CPP_BIDS)
117

8+
**BIDS validator and linter**
9+
10+
[![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_BIDS.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_BIDS)
11+
1212
**Contributors**
1313

1414
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
@@ -30,6 +30,7 @@
3030
- [saveEventsFile](#saveeventsfile)
3131
- [checkCFG](#checkcfg)
3232
- [CFG content](#cfg-content)
33+
- [createBoldJson](#createboldjson)
3334
- [How to install](#how-to-install)
3435
- [Download with git](#download-with-git)
3536
- [Add as a submodule](#add-as-a-submodule)
@@ -297,6 +298,26 @@ cfg.fileName.datasetDescription
297298
298299
```
299300

301+
### createBoldJson
302+
303+
```
304+
createBoldJson(cfg)
305+
```
306+
307+
This function creates a very light-weight version of the side-car JSON file for a BOLD functional run.
308+
309+
This will only contain the minimum BIDS requirement and will likely be less complete than the info you could from DICOM conversion.
310+
311+
If you put the following line at the end of your experiment script, it will dump the content of the `extraInfo` structure in the json file.
312+
313+
```
314+
createBoldJson(cfg, extraInfo)
315+
```
316+
317+
This allows to add all the parameters that you used to run your experiment in a human readable format: so that when you write your methods sections 2 years later ("the reviewer asked me for the size of my fixation cross... FML"), the info you used WHEN you ran the experiment is saved in an easily accessible text format. For the love of the flying spaghetti monster do not save all your parameters in a `.mat` file: think of the case when you won't have matlab or octave installed on a computer (plus not everyone uses those).
318+
319+
Also to reading your experiment parameters, you won't have to read it from the `setParameters.m` file and wonder if those might have been modified when running the experiment and you did not commit and tagged that change with git.
320+
300321
## How to install
301322

302323
### Download with git
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Instructions": "",
3+
"RepetitionTime": [],
4+
"SliceTiming": [],
5+
"TaskDescription": "",
6+
"TaskName": "testtask",
7+
"extraInfo": {
8+
"nestedExtraInfo": "something extra"
9+
}
10+
}

manualTests/test_createBoldJson.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function test_suite = test_createBoldJson %#ok<*STOUT>
2+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
3+
test_functions = localfunctions(); %#ok<*NASGU>
4+
catch % no problem; early Matlab versions can use initTestSuite fine
5+
end
6+
initTestSuite;
7+
end
8+
9+
function test_createBoldJsonExtra()
10+
11+
outputDir = fullfile(fileparts(mfilename('fullpath')), 'output');
12+
13+
%% set up
14+
15+
cfg.verbose = false;
16+
17+
cfg.subject.subjectNb = 1;
18+
cfg.subject.runNb = 1;
19+
20+
cfg.task.name = 'testtask';
21+
22+
cfg.dir.output = outputDir;
23+
24+
cfg.testingDevice = 'mri';
25+
26+
cfg = createFilename(cfg);
27+
28+
logFile = saveEventsFile('init', cfg); %#ok<*NASGU>
29+
30+
extraInfo = struct('extraInfo', struct('nestedExtraInfo', 'something extra'));
31+
32+
createBoldJson(cfg, extraInfo);
33+
34+
%% check content
35+
fileName = strrep(cfg.fileName.events, '_events', '_bold');
36+
fileName = strrep(fileName, '.tsv', '.json');
37+
38+
actualStruct = bids.util.jsondecode(fullfile( ...
39+
cfg.dir.outputSubject, ...
40+
cfg.fileName.modality, ...
41+
fileName));
42+
43+
% data to test against
44+
expectedStruct = bids.util.jsondecode( ...
45+
fullfile(pwd, 'testData', 'extra_bold.json'));
46+
47+
% test
48+
assertEqual(expectedStruct, actualStruct);
49+
50+
end

manualTests/test_makeRawDataset.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function test_makeRawDataset()
2929

3030
cfg = createFilename(cfg);
3131

32-
createBoldJson(cfg);
32+
extraInfo = struct('extraInfo', struct('nestedExtraInfo', 'something extra'));
33+
createBoldJson(cfg, extraInfo);
3334

3435
createDatasetDescription(cfg);
3536

src/createBoldJson.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
function createBoldJson(cfg)
2-
% createBoldJson(cfg)
1+
function createBoldJson(cfg, extraInfo)
2+
% createBoldJson(cfg, extraInfo)
33
%
44
% Creates the side car JSON file for a BOLD functional run.
55
% This will only contain the minimum BIDS requirement and will likey be less
66
% complete than the info you could from DICOM conversion.
7+
%
8+
% Extra content can be added to the JSON file
79

810
opts.Indent = ' ';
911

12+
if nargin < 2
13+
extraInfo = struct();
14+
end
15+
1016
fileName = strrep(cfg.fileName.events, '_events', '_bold');
1117
fileName = strrep(fileName, '.tsv', '.json');
1218

@@ -17,6 +23,15 @@ function createBoldJson(cfg)
1723

1824
jsonContent = cfg.bids.mri;
1925

26+
% add content of extraInfo to the JSON content
27+
if ~isstruct(extraInfo)
28+
warning('additional info added to a json file must be a structure');
29+
end
30+
fieldList = fieldnames(extraInfo);
31+
for iField = 1:numel(fieldList)
32+
jsonContent.(fieldList{iField}) = extraInfo.(fieldList{iField});
33+
end
34+
2035
bids.util.jsonencode(fileName, jsonContent, opts);
2136

2237
end

0 commit comments

Comments
 (0)