Skip to content

Commit

Permalink
[ENH] add support for BIDS MRS (#718)
Browse files Browse the repository at this point in the history
* prepare mrs

* update schema

* fix tests
  • Loading branch information
Remi-Gau authored Sep 2, 2024
1 parent f3ea54b commit 08fdbe7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ manual:

update_schema:
wget https://bids-specification.readthedocs.io/en/latest/schema.json -O schema.json
# get schema from a PR on the spec
# wget https://bids-specification--1377.org.readthedocs.build/en/1377/schema.json -O schema.json
2 changes: 2 additions & 0 deletions tests/test_bids_file.m
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ function test_reorder_schemaless()
'task'
'tracksys'
'acq'
'nuc'
'voi'
'ce'
'trc'
'stain'
Expand Down
13 changes: 12 additions & 1 deletion tests/test_bids_schema.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function test_get_datatypes()
'ieeg', ...
'meg', ...
'micr', ...
'mrs', ...
'motion', ...
'nirs', ...
'perf', ...
Expand Down Expand Up @@ -226,7 +227,15 @@ function test_return_suffix_groups_for_datatype()
assertEqual(datatypes, {'func'});

datatypes = schema.return_datatypes_for_suffix('events');
expected_output = {'beh', 'eeg', 'func', 'ieeg', 'meg', 'motion', 'nirs', 'pet'};
expected_output = {'beh', ...
'eeg', ...
'func', ...
'ieeg', ...
'meg', ...
'motion', ...
'mrs', ...
'nirs', ...
'pet'};
assertEqual(sort(datatypes), sort(expected_output));

datatypes = schema.return_datatypes_for_suffix('m0scan');
Expand Down Expand Up @@ -326,6 +335,8 @@ function test_schemaless()
'task'; ...
'tracksys'; ...
'acquisition'; ...
'nucleus'; ...
'volume'; ...
'ceagent'; ...
'tracer'; ...
'stain'; ...
Expand Down
60 changes: 60 additions & 0 deletions tests/tests_query/test_bids_query_mrs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function test_suite = test_bids_query_mrs %#ok<*STOUT>
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end

function test_bids_query_asl_basic_2dmrsi()

BIDS = bids.layout(fullfile(get_test_data_dir(), 'mrs_2dmrsi'));

modalities = {'anat', 'mrs'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = {'T1w', 'mrsi'};
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

assertEqual(numel(bids.query(BIDS, 'data')), 32);

filename = bids.query(BIDS, 'data', 'sub', '01', 'suffix', 'mrsi');
basename = bids.internal.file_utils(filename, 'basename');
assertEqual(basename, { 'sub-01_run-1_mrsi.nii'
'sub-01_run-2_mrsi.nii'
'sub-01_run-3_mrsi.nii'});

end

function test_bids_query_asl_basic_biggaba()

BIDS = bids.layout(fullfile(get_test_data_dir(), 'mrs_biggaba'));

modalities = {'anat', 'mrs'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = {'T1w', 'mrsref', 'svs'};
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

assertEqual(numel(bids.query(BIDS, 'data')), 84);

end

function test_bids_query_asl_basic_fmrs()

BIDS = bids.layout(fullfile(get_test_data_dir(), 'mrs_fmrs'));

modalities = {'anat', 'mrs'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = { 'T1w', 'events', 'mrsref', 'svs'};
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

assertEqual(numel(bids.query(BIDS, 'data')), 90);

metadata = bids.query(BIDS, 'metadata', 'sub', '01', 'suffix', 'svs');

metadata{1}.ReferenceSignal;
bids.internal.resolve_bids_uri(metadata{1}.ReferenceSignal, BIDS);

end

0 comments on commit 08fdbe7

Please sign in to comment.