Skip to content

Commit

Permalink
Merge branch 'main' into guiomar-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau authored Nov 21, 2023
2 parents 16fc610 + 55004d1 commit d1ed6b9
Show file tree
Hide file tree
Showing 300 changed files with 20,032 additions and 6,907 deletions.
1 change: 1 addition & 0 deletions +bids/+internal/add_missing_field.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%
% structure = add_missing_field(structure, field)
%

% (C) Copyright 2021 BIDS-MATLAB developers

if ~isfield(structure, field)
Expand Down
10 changes: 7 additions & 3 deletions +bids/+internal/append_to_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
% subject = append_to_layout(file, subject, modality, schema == [])
%
% :param file:
% :type file: string
% :type file: char
%
% :param subject: subject sub-structure from the BIDS layout
% :type subject: structure
%
% :param modality:
% :type modality: string
% :type modality: char
%
% :param schema:
% :type schema: structure
%
%

% (C) Copyright 2021 BIDS-MATLAB developers

pth = [subject.path, filesep, modality];
Expand Down Expand Up @@ -156,7 +160,7 @@

function [msg, msg_id] = error_message(msg_id, file, extra)

msg = sprintf('Skipping file: %s.\n', file);
msg = sprintf('Skipping file: %s.\n', bids.internal.format_path(file));

switch msg_id

Expand Down
5 changes: 3 additions & 2 deletions +bids/+internal/camel_case.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
% str = camel_case(str)
%
% :param str:
% :type str: string
% :type str: char
%
% :returns:
% :str: (string) returns the input with an upper case for first letter
% :str: (char) returns the input with an upper case for first letter
% for all words but the first one (``camelCase``) and
% removes invalid characters (like spaces).
%

% (C) Copyright 2018 BIDS-MATLAB developers

% camel case: upper case for first letter for all words but the first one
Expand Down
61 changes: 61 additions & 0 deletions +bids/+internal/create_unordered_list.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function list = create_unordered_list(list)
%
% turns a cell string or a structure into a string
% that is an unordered list to print to the screen
%
% USAGE::
%
% list = bids.internal.create_unordered_list(list)
%
% :param list: obligatory argument.
% :type list: cell string or structure
%
%

% (C) Copyright 2022 Remi Gau

if bids.internal.is_octave
warning('off', 'Octave:mixed-string-concat');
end

prefix = '\n\t- ';

if ischar(list)
list = cellstr(list);
end

if iscell(list)

for i = 1:numel(list)
if isnumeric(list{i})
list{i} = num2str(list{i});
end
end

list = sprintf([prefix, strjoin(list, prefix), '\n']);

elseif isstruct(list)

output = '';
fields = fieldnames(list);

for i = 1:numel(fields)
content = list.(fields{i});
if ~iscell(content)
content = {content};
end

for j = 1:numel(content)
if isnumeric(content{j})
content{j} = num2str(content{j});
end
end

output = [output prefix fields{i} ': {' strjoin(content, ', ') '}'];
end

list = sprintf(output);

end

end
26 changes: 17 additions & 9 deletions +bids/+internal/download.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
%
% filename = download(URL, output_dir, verbose)
%

% (C) Copyright 2021 BIDS-MATLAB developers
if nargin < 2
output_dir = pwd;
end
bids.util.mkdir(output_dir);

msg = sprintf('Downloading dataset from:\n %s\n\n', URL);
print_to_screen(msg, verbose);
Expand All @@ -16,26 +18,32 @@
protocol = tokens{1};

filename = tokens{end};
if strcmp(filename, '?zip=')
[~, filename] = fileparts(tempname);
filename = [filename '.zip'];
end

if exist(filename, 'file')
delete(filename);
end

if strcmp(protocol, 'http:')
if ismember(protocol, {'http:', 'https:'})

if isunix()
if verbose
system(sprintf('wget %s', URL));
else
system(sprintf('wget -q %s', URL));
try
urlwrite(URL, filename); %#ok<*URLWR>
catch
options = '';
if ~verbose
options = '-q';
end
else
urlwrite(URL, filename);
system(sprintf('wget %s %s', options, URL));
end

% move file in case it was not downloaded in the root dir
if ~exist(fullfile(output_dir, filename), 'file')
print_to_screen([filename ' --> ' output_dir], verbose);
print_to_screen([bids.internal.format_path(filename), ...
' --> ', ...
bids.internal.format_path(output_dir)], verbose);
movefile(filename, fullfile(output_dir, filename));
end
filename = fullfile(output_dir, filename);
Expand Down
3 changes: 2 additions & 1 deletion +bids/+internal/ends_with.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
% :param pattern:
% :type pattern: character array
%
%
% Based on the equivalent function from SPM12
%

% (C) Copyright 2011-2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
%

% (C) Copyright 2018 BIDS-MATLAB developers

res = false;
Expand Down
44 changes: 28 additions & 16 deletions +bids/+internal/error_handling.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ function error_handling(varargin)
%
% :param function_name: default = ``bidsMatlab``
% :type function_name:
%
% :param id: default = ``unspecified``
% :type id: string
% :type id: char
%
% :param msg: default = ``unspecified``
% :type msg: string
% :type msg: char
%
% :param tolerant:
% :type tolerant: boolean
% :type tolerant: logical
%
% :param verbose:
% :type verbose: boolean
% :type verbose: logical
%
% Example
% -------
%
% .. code-block:: matlab
%
% bids.internal.error_handling(mfilename(), 'thisError', 'this is an error', tolerant, verbose)
%

% (C) Copyright 2018 BIDS-MATLAB developers

default_function_name = 'bidsMatlab';
Expand All @@ -23,28 +35,28 @@ function error_handling(varargin)
default_tolerant = true;
default_verbose = false;

p = inputParser;
args = inputParser;

addOptional(p, 'function_name', default_function_name, @ischar);
addOptional(p, 'id', default_id, @ischar);
addOptional(p, 'msg', default_msg, @ischar);
addOptional(p, 'tolerant', default_tolerant, @islogical);
addOptional(p, 'verbose', default_verbose, @islogical);
addOptional(args, 'function_name', default_function_name, @ischar);
addOptional(args, 'id', default_id, @ischar);
addOptional(args, 'msg', default_msg, @ischar);
addOptional(args, 'tolerant', default_tolerant, @islogical);
addOptional(args, 'verbose', default_verbose, @islogical);

parse(p, varargin{:});
parse(args, varargin{:});

function_name = bids.internal.file_utils(p.Results.function_name, 'basename');
function_name = bids.internal.file_utils(args.Results.function_name, 'basename');

id = [function_name, ':' p.Results.id];
msg = p.Results.msg;
id = [function_name, ':' args.Results.id];
msg = sprintf(['\n' args.Results.msg '\n']);

if ~p.Results.tolerant
if ~args.Results.tolerant
errorStruct.identifier = id;
errorStruct.message = msg;
error(errorStruct);
end

if p.Results.verbose
if args.Results.verbose
warning(id, msg);
end

Expand Down
17 changes: 8 additions & 9 deletions +bids/+internal/file_utils.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function varargout = file_utils(str, varargin)
%
% Character array (or cell array of strings) handling facility
% Character array (or cell array of char) handling facility
%
% USAGE:
%
Expand All @@ -11,33 +11,32 @@
% [dirs] = bids.internal.file_utils('List', directory, 'dir', regexp)
% [dirs] = bids.internal.file_utils('FPList', directory, 'dir', regexp)
%
%
% To get a certain piece of information from a file::
%
% str = bids.internal.file_utils(str, option)
%
% str - character array, or cell array of strings
% str - character array, or cell array of char
%
% option - string of requested item - one among:
% option - char of requested item - one among:
% {'path', 'basename', 'ext', 'filename', 'cpath', 'fpath'}
%
%
% To set a certain piece of information from a file::
%
% str = bids.internal.file_utils(str, opt_key, opt_val, ...)
%
% str - character array, or cell array of strings
% str - character array, or cell array of char
%
% opt_key - string of targeted item - one among:
% opt_key - char of targeted item - one among:
% {'path', 'basename', 'ext', 'filename', 'prefix', 'suffix'}
%
% opt_val - string of new value for feature
%
% opt_val - char of new value for feature
%
% Based on spm_file.m and spm_select.m from SPM12.
%

% (C) Copyright 2011-2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
%

% (C) Copyright 2018 BIDS-MATLAB developers

%#ok<*AGROW>
Expand Down
31 changes: 31 additions & 0 deletions +bids/+internal/format_path.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function pth = format_path(pth)
%
% USAGE::
%
% pth = bids.internal.format_path(pth)
%
% Replaces single '\' by '/' in Windows paths
% to prevent escaping warning when printing a path to screen
%
% :param pth: If pth is a cellstr of paths, pathToPrint will work
% recursively on it.
% :type pth: char or cellstr$
%
%

% (C) Copyright 2022 BIDS-MATLAB developers

if isunix()
return
end

if ischar(pth)
pth = strrep(pth, '\', '\\');

elseif iscell(pth)
for i = 1:numel(pth)
pth{i} = strrep(pth{i}, '\', '\\');
end
end

end
Loading

0 comments on commit d1ed6b9

Please sign in to comment.