Skip to content

Commit 23fb7e8

Browse files
committed
parse meg with schema and refactor
1 parent ad26630 commit 23fb7e8

File tree

1 file changed

+9
-138
lines changed

1 file changed

+9
-138
lines changed

+bids/layout.m

+9-138
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,12 @@ function tolerant_message(tolerant, msg)
204204
subject = parse_using_schema(subject, datatypes{iDatatype}, schema);
205205
case 'dwi'
206206
subject = parse_dwi(subject, schema);
207-
case 'eeg'
208-
subject = parse_eeg(subject, schema);
207+
case {'eeg', 'meg'}
208+
subject = parse_meeg(subject, datatypes{iDatatype}, schema);
209209
case 'fmap'
210210
subject = parse_fmap(subject, schema);
211211
case 'func'
212212
subject = parse_func(subject, schema);
213-
case 'meg'
214-
subject = parse_meg(subject);
215213
case 'perf'
216214
subject = parse_perf(subject, schema);
217215
end
@@ -652,9 +650,7 @@ function tolerant_message(tolerant, msg)
652650

653651
end
654652

655-
function subject = parse_eeg(subject, schema)
656-
657-
datatype = 'eeg';
653+
function subject = parse_meeg(subject, datatype, schema)
658654

659655
pth = fullfile(subject.path, datatype);
660656

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

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

669-
switch subject.eeg(end).type
665+
switch subject.(datatype)(end).type
670666

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

674673
case {'photo', 'coordsystem'}
675674

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

682681
end
683682

684-
function subject = parse_meg(subject)
685-
686-
pth = fullfile(subject.path, 'meg');
687-
688-
if exist(pth, 'dir')
689-
690-
entities = return_entities('meg');
691-
692-
file_list = return_file_list('meg', subject);
693-
694-
for i = 1:numel(file_list)
695-
696-
subject = append_to_structure(file_list{i}, entities, subject, 'meg');
697-
698-
subject.meg(end).meta = struct([]); % ?
699-
700-
end
701-
702-
file_list = return_event_file_list('meg', subject);
703-
704-
for i = 1:numel(file_list)
705-
706-
subject = append_to_structure(file_list{i}, entities, subject, 'meg');
707-
708-
subject.meg(end).meta = bids.util.tsvread(fullfile(pth, file_list{i})); % ?
709-
710-
end
711-
712-
file_list = return_channel_description_file_list('meg', subject);
713-
714-
for i = 1:numel(file_list)
715-
716-
subject = append_to_structure(file_list{i}, entities, subject, 'meg');
717-
718-
subject.meg(end).meta = bids.util.tsvread(fullfile(pth, file_list{i})); % ?
719-
720-
end
721-
722-
file_list = return_session_specific_file_list('meg', subject);
723-
724-
for i = 1:numel(file_list)
725-
726-
subject = append_to_structure(file_list{i}, entities, subject, 'meg');
727-
728-
subject.meg(end).meta = struct([]); % ?
729-
730-
end
731-
732-
end
733-
734-
end
735-
736683
function subject = parse_pet(subject)
737684
% --------------------------------------------------------------------------
738685
% -Positron Emission Tomography imaging data
@@ -776,12 +723,6 @@ function tolerant_message(tolerant, msg)
776723

777724
switch modality
778725

779-
case 'eeg'
780-
entities = {'sub', 'ses', 'task', 'acq', 'run', 'meta'};
781-
782-
case 'meg'
783-
entities = {'sub', 'ses', 'task', 'acq', 'run', 'proc', 'meta'};
784-
785726
case 'pet'
786727
entities = {'sub', 'ses', 'task', 'acq', 'rec', 'run'};
787728

@@ -827,73 +768,3 @@ function tolerant_message(tolerant, msg)
827768
file_list = convert_to_cell(file_list);
828769

829770
end
830-
831-
function file_list = return_event_file_list(modality, subject)
832-
%
833-
% TODO: events file can also be stored at higher levels (inheritance principle)
834-
%
835-
836-
switch modality
837-
838-
case 'meg'
839-
pattern = '_task-.*_events\\.tsv';
840-
841-
end
842-
843-
pth = fullfile(subject.path, modality);
844-
845-
file_list = bids.internal.file_utils('List', ...
846-
pth, ...
847-
sprintf(['^%s.*' pattern '$'], ...
848-
subject.name));
849-
850-
file_list = convert_to_cell(file_list);
851-
852-
end
853-
854-
function file_list = return_channel_description_file_list(modality, subject)
855-
%
856-
% Channel description table
857-
%
858-
% TODO: those files can also be stored at higher levels (inheritance principle)
859-
%
860-
861-
switch modality
862-
863-
case 'meg'
864-
pattern = '_task-.*_channels\\.tsv';
865-
866-
end
867-
868-
pth = fullfile(subject.path, modality);
869-
870-
file_list = bids.internal.file_utils('List', ...
871-
pth, ...
872-
sprintf(['^%s.*' pattern '$'], ...
873-
subject.name));
874-
875-
file_list = convert_to_cell(file_list);
876-
877-
end
878-
879-
function file_list = return_session_specific_file_list(modality, subject)
880-
881-
switch modality
882-
883-
case 'meg'
884-
pattern = [ ...
885-
'(_ses-[a-zA-Z0-9]+)?.*_', ...
886-
'(electrodes\\.tsv|photo\\.jpg|coordsystem\\.json|headshape\\..*)'];
887-
888-
end
889-
890-
pth = fullfile(subject.path, modality);
891-
892-
file_list = bids.internal.file_utils('List', ...
893-
pth, ...
894-
sprintf(['^%s' pattern '$'], ...
895-
subject.name));
896-
897-
file_list = convert_to_cell(file_list);
898-
899-
end

0 commit comments

Comments
 (0)