Skip to content

Commit

Permalink
parse meg with schema and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Feb 7, 2021
1 parent f02638d commit 71a7eb4
Showing 1 changed file with 9 additions and 138 deletions.
147 changes: 9 additions & 138 deletions +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,12 @@ function tolerant_message(tolerant, msg)
subject = parse_using_schema(subject, datatypes{iDatatype}, schema);
case 'dwi'
subject = parse_dwi(subject, schema);
case 'eeg'
subject = parse_eeg(subject, schema);
case {'eeg', 'meg'}
subject = parse_meeg(subject, datatypes{iDatatype}, schema);
case 'fmap'
subject = parse_fmap(subject, schema);
case 'func'
subject = parse_func(subject, schema);
case 'meg'
subject = parse_meg(subject);
case 'perf'
subject = parse_perf(subject, schema);
end
Expand Down Expand Up @@ -652,9 +650,7 @@ function tolerant_message(tolerant, msg)

end

function subject = parse_eeg(subject, schema)

datatype = 'eeg';
function subject = parse_meeg(subject, datatype, schema)

pth = fullfile(subject.path, datatype);

Expand All @@ -666,10 +662,13 @@ function tolerant_message(tolerant, msg)

subject = bids.internal.append_to_structure(file_list{i}, subject, datatype, schema);

switch subject.eeg(end).type
switch subject.(datatype)(end).type

case {'events', 'channels', 'electrodes'}
subject.eeg(end).meta = bids.util.tsvread(fullfile(pth, file_list{i}));
case {'events', 'channels', 'electrodes'} %
% TODO: events / channels file can also be stored
% at higher levels (inheritance principle)
%
subject.(datatype)(end).meta = bids.util.tsvread(fullfile(pth, file_list{i}));

case {'photo', 'coordsystem'}

Expand All @@ -681,58 +680,6 @@ function tolerant_message(tolerant, msg)

end

function subject = parse_meg(subject)

pth = fullfile(subject.path, 'meg');

if exist(pth, 'dir')

entities = return_entities('meg');

file_list = return_file_list('meg', subject);

for i = 1:numel(file_list)

subject = append_to_structure(file_list{i}, entities, subject, 'meg');

subject.meg(end).meta = struct([]); % ?

end

file_list = return_event_file_list('meg', subject);

for i = 1:numel(file_list)

subject = append_to_structure(file_list{i}, entities, subject, 'meg');

subject.meg(end).meta = bids.util.tsvread(fullfile(pth, file_list{i})); % ?

end

file_list = return_channel_description_file_list('meg', subject);

for i = 1:numel(file_list)

subject = append_to_structure(file_list{i}, entities, subject, 'meg');

subject.meg(end).meta = bids.util.tsvread(fullfile(pth, file_list{i})); % ?

end

file_list = return_session_specific_file_list('meg', subject);

for i = 1:numel(file_list)

subject = append_to_structure(file_list{i}, entities, subject, 'meg');

subject.meg(end).meta = struct([]); % ?

end

end

end

function subject = parse_pet(subject)
% --------------------------------------------------------------------------
% -Positron Emission Tomography imaging data
Expand Down Expand Up @@ -776,12 +723,6 @@ function tolerant_message(tolerant, msg)

switch modality

case 'eeg'
entities = {'sub', 'ses', 'task', 'acq', 'run', 'meta'};

case 'meg'
entities = {'sub', 'ses', 'task', 'acq', 'run', 'proc', 'meta'};

case 'pet'
entities = {'sub', 'ses', 'task', 'acq', 'rec', 'run'};

Expand Down Expand Up @@ -827,73 +768,3 @@ function tolerant_message(tolerant, msg)
file_list = convert_to_cell(file_list);

end

function file_list = return_event_file_list(modality, subject)
%
% TODO: events file can also be stored at higher levels (inheritance principle)
%

switch modality

case 'meg'
pattern = '_task-.*_events\\.tsv';

end

pth = fullfile(subject.path, modality);

file_list = bids.internal.file_utils('List', ...
pth, ...
sprintf(['^%s.*' pattern '$'], ...
subject.name));

file_list = convert_to_cell(file_list);

end

function file_list = return_channel_description_file_list(modality, subject)
%
% Channel description table
%
% TODO: those files can also be stored at higher levels (inheritance principle)
%

switch modality

case 'meg'
pattern = '_task-.*_channels\\.tsv';

end

pth = fullfile(subject.path, modality);

file_list = bids.internal.file_utils('List', ...
pth, ...
sprintf(['^%s.*' pattern '$'], ...
subject.name));

file_list = convert_to_cell(file_list);

end

function file_list = return_session_specific_file_list(modality, subject)

switch modality

case 'meg'
pattern = [ ...
'(_ses-[a-zA-Z0-9]+)?.*_', ...
'(electrodes\\.tsv|photo\\.jpg|coordsystem\\.json|headshape\\..*)'];

end

pth = fullfile(subject.path, modality);

file_list = bids.internal.file_utils('List', ...
pth, ...
sprintf(['^%s' pattern '$'], ...
subject.name));

file_list = convert_to_cell(file_list);

end

0 comments on commit 71a7eb4

Please sign in to comment.