Skip to content
Merged
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
1 change: 1 addition & 0 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

% create_roi only
addParameter(args, 'roi_dir', '', isChar);
addParameter(args, 'hemisphere', {'L', 'R'}, isCellStr);
addParameter(args, 'roi_atlas', 'neuromorphometrics', isInAvailableAtlas);
addParameter(args, 'roi_name', {''}, isCellStr);

Expand Down
2 changes: 1 addition & 1 deletion lib/CPP_ROI
1 change: 1 addition & 0 deletions src/cli/getOptionsFromCliArgument.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
% create_roi
opt.roi.atlas = args.Results.roi_atlas;
opt.roi.name = args.Results.roi_name;
opt.roi.hemi = args.Results.hemisphere;

% stats
opt.dir.preproc = args.Results.preproc_dir;
Expand Down
4 changes: 1 addition & 3 deletions src/defaults/checkOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
% 't2w', struct('modality', 'anat', 'suffix', 'T2w'), ...
% 't1w', struct('modality', 'anat', 'space', '', 'suffix', 'T1w'), ...
% 'roi', struct('modality', 'roi', 'suffix', 'mask'), ...
% 'xfm', struct('modality', 'anat', ...
% 'suffix', 'xfm', ...
% 'to', 'T1w'));
% 'xfm', struct('modality', 'anat', 'suffix', 'xfm', 'to', 'T1w'));
%
% - **preprocessing**
%
Expand Down
5 changes: 5 additions & 0 deletions src/messages/bidspmHelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function bidspmHelp()
% 'verbosity', 2, ...
% 'roi_atlas', 'wang', ...
% 'roi_name', {'V1v', 'V1d'}, ...
% 'hemisphre', {'L', 'R'}, ...
% 'space', {'wang'}, ...
% 'options', struct([]))
%
Expand All @@ -181,6 +182,10 @@ function bidspmHelp()
% the list of available ROI will be returned in the error message.
% :type roi_name: cell string
%
% :param hemisphre: Hemisphere of the ROI to create.
% Not all ROIs have both hemispheres.
% :type hemisphre: cell string containing any of 'L', 'R'
%
%
% **SMOOTH:**
%
Expand Down
22 changes: 16 additions & 6 deletions src/messages/bugReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ function bugReport(opt, ME)

json.GeneratedBy = GeneratedBy;
json.OS = OS;
if nargin > 1
json.ME = ME;
end

output_dir = pwd;
if isfield(opt, 'dir') && isfield(opt.dir, 'output')
Expand All @@ -30,12 +27,25 @@ function bugReport(opt, ME)
output_dir = fullfile(output_dir, 'error_logs');
spm_mkdir(output_dir);

logger('WARNING', 'An error occurred');
unfold(json);
if nargin > 1
json.ME = ME;

for i = 1:numel(json.ME.stack)
stackTrace{i} = sprintf('Error in %s\n\t\tline %i in %s', ...
json.ME.stack(i).name, ...
json.ME.stack(i).line, ...
json.ME.stack(i).file); %#ok<*AGROW>
end

logger('INFO', sprintf('%s\n Error %s occurred:%s%s', ...
json.ME.message, ...
json.ME.identifier, ...
createUnorderedList(stackTrace)), ...
'color', 'red');
end
logFile = spm_file(fullfile(output_dir, sprintf('error_%s.log', timeStamp())), 'cpath');
bids.util.jsonwrite(logFile, json);
printToScreen(sprintf(['\nERROR LOG SAVED:\n\t%s\n', ...
printToScreen(sprintf(['ERROR LOG SAVED:\n\t%s\n', ...
'Use it when opening an issue:\n\t%s.\n\n'], ...
pathToPrint(logFile), ...
[returnRepoURL() '/issues/new/choose']), ...
Expand Down
6 changes: 4 additions & 2 deletions src/messages/logger.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
addParameter(args, 'options', default_opt, @isstruct);
addParameter(args, 'filename', '', @ischar);
addParameter(args, 'id', '', @ischar);
addParameter(args, 'color', 'blue', @ischar);

parse(args, varargin{:});

Expand All @@ -36,6 +37,7 @@
opt = args.Results.options;
filename = args.Results.filename;
id = args.Results.id;
color = args.Results.color;

[~, filename, ext] = fileparts(filename);

Expand Down Expand Up @@ -81,15 +83,15 @@
errorHandling(filename, id, logMsg, true, true);
end
if ismember(logLevel, {'INFO'})
printToScreen(logMsg, opt, 'format', 'blue');
printToScreen(logMsg, opt, 'format', color);
end

case 3
if ismember(logLevel, {'WARNING'})
errorHandling(filename, id, logMsg, true, true);
end
if ismember(logLevel, {'INFO', 'DEBUG'})
printToScreen(logMsg, opt, 'format', 'blue');
printToScreen(logMsg, opt, 'format', color);
end
end

Expand Down
34 changes: 20 additions & 14 deletions src/workflows/roi/bidsCreateROI.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,45 @@ function bidsCreateROI(opt)
%
% USAGE::
%
% opt = get_option();
% opt.roi.atlas = 'wang';
% opt.roi.name = {'V1v', 'V1d'};
% opt.roi.space = {'IXI549Space', 'individual'};
% opt.dir.stats = fullfile(opt.dir.raw, '..', 'derivatives', 'bidspm-stats');
% % to create ROI in MNI space
% opt.dir.roi = pwd;
% opt.roi.atlas = 'wang';
% opt.roi.hemi = {'L', 'R'};
% opt.roi.name = {'V1v', 'V1d'};
% opt.roi.space = {'IXI549Space''};
%
% bidsCreateROI(opt);
% bidsCreateROI(opt);
%
%
% % to create ROI in subject space
% opt.dir.roi = pwd;
% opt.roi.atlas = 'wang';
% opt.roi.hemi = {'L', 'R'};
% opt.roi.name = {'V1v', 'V1d'};
% opt.roi.space = {'IXI549Space', 'individual'};
% opt.dir.input = fullfile(opt.dir.raw, '..', 'derivatives', 'bidspm-preproc');
%
% bidsCreateROI(opt);
%
%

% (C) Copyright 2021 bidspm developers

if nargin < 1
opt = [];
end

if any(~strcmp(opt.roi.space, 'individual'))

if ~isfield(opt.dir, 'roi')
opt.dir.roi = spm_file(fullfile(opt.dir.derivatives, 'bidspm-roi'), 'cpath');
end
spm_mkdir(fullfile(opt.dir.roi, 'group'));

hemi = {'L', 'R'};

for iHemi = 1:numel(hemi)
for iHemi = 1:numel(opt.roi.hemi)

for iROI = 1:numel(opt.roi.name)

extractRoiFromAtlas(fullfile(opt.dir.roi, 'group'), ...
opt.roi.atlas, ...
opt.roi.name{iROI}, ...
hemi{iHemi});
opt.roi.hemi{iHemi});

end

Expand Down
54 changes: 40 additions & 14 deletions tests/tests_cli/test_bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

end

function test_bidsCreateROI_CLI()
function test_bidsCreateROI_wang()

bidspm(pwd, fullfile(pwd, 'tmp'), ...
'subject', ...
Expand All @@ -25,19 +25,24 @@ function test_bidsCreateROI_CLI()
cleanUp(fullfile(pwd, 'options'));
cleanUp(fullfile(pwd, 'error_logs'));

if ~isOctave()
bidspm(pwd, fullfile(pwd, 'tmp'), ...
'subject', ...
'action', 'create_roi', ...
'roi_atlas', 'visfatlas', ...
'roi_name', {'OTS'}, ...
'space', {'IXI549Space'}, ...
'verbosity', 0);

cleanUp(fullfile(pwd, 'tmp'));
cleanUp(fullfile(pwd, 'options'));
cleanUp(fullfile(pwd, 'error_logs'));
end
end

function test_bidsCreateROI_visfatlas()

bidspm(pwd, fullfile(pwd, 'tmp'), ...
'subject', ...
'action', 'create_roi', ...
'roi_atlas', 'visfatlas', ...
'roi_name', {'OTS'}, ...
'space', {'IXI549Space'}, ...
'verbosity', 0);

cleanUp(fullfile(pwd, 'tmp'));
cleanUp(fullfile(pwd, 'options'));
cleanUp(fullfile(pwd, 'error_logs'));
end

function test_bidsCreateROI_neuromorphometrics()

bidspm(pwd, fullfile(pwd, 'tmp'), ...
'subject', ...
Expand All @@ -51,6 +56,10 @@ function test_bidsCreateROI_CLI()
cleanUp(fullfile(pwd, 'options'));
cleanUp(fullfile(pwd, 'error_logs'));

end

function test_bidsCreateROI_neuromorphometrics_inve_norm()

% requires some deformation field to work

% if ~isGithubCi
Expand All @@ -71,6 +80,23 @@ function test_bidsCreateROI_CLI()

end

function test_bidsCreateROI_one_hemisphere()
bidspm(pwd, fullfile(pwd, 'tmp'), 'subject', ...
'action', 'create_roi', ...
'verbosity', 0, ...
'roi_atlas', 'visfatlas', ...
'hemisphere', {'L'}, ...
'roi_name', {'OTS', 'ITG', 'MTG', 'LOS', 'pOTS', 'IOS'}, ...
'space', {'IXI549Space'});
assertEqual(size(spm_select('FPListRec', ...
fullfile(pwd, 'tmp'), ...
'.*mask.nii'), 1), ...
6);
cleanUp(fullfile(pwd, 'tmp'));
cleanUp(fullfile(pwd, 'options'));
cleanUp(fullfile(pwd, 'error_logs'));
end

function test_boilerplate_stats_only()

if ~isGithubCi
Expand Down
5 changes: 5 additions & 0 deletions tests/tests_workflows/stats/test_bidsRoiBasedGLM.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function test_bidsRoiBasedGLM_run()
% - also makes sure that previous results are not deleted
%

if isOctave
return
end

opt = setOptions('MoAE-fmriprep', '01');

opt.query.space = opt.space;
Expand Down Expand Up @@ -53,6 +57,7 @@ function test_bidsRoiBasedGLM_run()

opt.roi.atlas = 'wang';
opt.roi.name = {'V1v', 'V1d'};
opt.roi.hemi = {'L', 'R'};
opt.roi.space = opt.space;

opt.bidsFilterFile.roi.space = 'MNI';
Expand Down