Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] layout redone #134

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions +bids/+internal/parse_filename.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
% filename: 'sub-16_ses-mri_run-1_echo-2_FLASH.nii.gz'
% type: 'FLASH'
% ext: '.nii.gz'
% sub: '16'
% ses: 'mri'
% run: '1'
% echo: '2'
% gz: 1
% tab: 0
% depend: {}
% intended: {}
% entity:
% sub: '16'
% ses: 'mri'
% run: '1'
% echo: '2'
% __________________________________________________________________________

% Copyright (C) 2016-2018, Guillaume Flandin, Wellcome Centre for Human Neuroimaging
Expand All @@ -30,25 +35,33 @@
[parts, dummy] = regexp(filename, '(?:_)+', 'split', 'match'); %#ok<ASGLU>
p.filename = filename;

% filename without suffix, usefull to get accompagning files
p.basename = strjoin(parts(1:end-1), '_');

% -Identify the suffix and extension of this file
% https://bids-specification.readthedocs.io/en/stable/02-common-principles.html#file-name-structure
[p.type, p.ext] = strtok(parts{end}, '.');

% are files zipped or tabulats
p.gz = endsWith(p.ext, '.gz', 'IgnoreCase',true);
p.tab = startsWith(p.ext, '.tsv', 'IgnoreCase',true);
p.intended = {};

% -Separate the entity from the label for each pair identified above
for i = 1:numel(parts) - 1
[d, dummy] = regexp(parts{i}, '(?:\-)+', 'split', 'match'); %#ok<ASGLU>
p.(d{1}) = d{2};
p.entity.(d{1}) = d{2};
end

% -Extra fields can be added to the structure and ordered specifically.
if nargin == 2
for i = 1:numel(fields)
if ~isfield(p, fields{i})
p.(fields{i}) = '';
if ~isfield(p.entity, fields{i})
p.entity.(fields{i}) = '';
end
end
try
p = orderfields(p, ['filename', 'ext', 'type', fields]);
p = orderfields(p.entity, [fields]);
catch
warning('Ignoring file ''%s'' not matching template.', filename);
p = struct([]);
Expand Down
Loading