Skip to content

Commit 0579645

Browse files
committed
make the copy atlas functional optionally verbose
1 parent 88b2f22 commit 0579645

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

docs/source/atlas.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Atlas
66
.. autofunction:: extractRoiFromAtlas
77
.. autofunction:: extractRoiByLabel
88
.. autofunction:: labelClusters
9+
.. autofunction:: copyAtlasToSpmDir

src/atlas/copyAtlasToSpmDir.m

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,68 @@
1-
function copyAtlasToSpmDir(atlas)
1+
function copyAtlasToSpmDir(varargin)
22
%
3-
% copies a given atlas to the SPM atlas dir
3+
% Copies a given atlas to the SPM atlas directory.
44
%
55
% USAGE::
66
%
7-
% copyAtlasToSpmDir(atlas)
7+
% copyAtlasToSpmDir(atlas, 'verbose', false)
88
%
99
% :param atlas: Any of ``{'AAL'}``. Defaults to ``'AAL'``
1010
% :type atlas: char
1111
%
12-
% (C) Copyright 2022 CPP_SPM developers
13-
14-
if nargin < 1
15-
atlas = 'AAL';
16-
end
17-
12+
% :param verbose: Defaults to ``false``
13+
% :type verbose: boolean
14+
%
15+
%
16+
% (C) Copyright 2022 CPP ROI developers
17+
18+
args = inputParser;
19+
20+
addOptional(args, 'atlas', 'AAL', @ischar);
21+
addParameter(args, 'verbose', false, @islogical);
22+
23+
parse(args, varargin{:});
24+
25+
atlas = args.Results.atlas;
26+
verbose = args.Results.verbose;
27+
1828
spmAtlasDir = fullfile(spm('dir'), 'atlas');
1929
cppRoiAtlasDir = returnAtlasDir();
20-
30+
2131
switch lower(atlas)
22-
32+
2333
case 'aal'
2434
sourceAtlasImage = fullfile(cppRoiAtlasDir, 'AAL3', 'AAL3v1_1mm.nii.gz');
2535
sourceAtlasXml = fullfile(cppRoiAtlasDir, 'AAL3', 'AAL3v1_1mm.xml');
2636
end
27-
37+
2838
targetAtlasImage = fullfile(spmAtlasDir, spm_file(sourceAtlasImage, 'filename'));
2939
targetAtlasXml = fullfile(spmAtlasDir, spm_file(sourceAtlasXml, 'filename'));
30-
40+
3141
atlasPresent = isdir(spmAtlasDir) && ...
32-
exist(targetAtlasImage(1:end-3), 'file') && ...
42+
exist(targetAtlasImage(1:end - 3), 'file') && ...
3343
exist(targetAtlasXml, 'file');
34-
44+
3545
if ~atlasPresent
36-
fprintf('\nCopying atlas "%s" to spm atlas directory:\n\t%s\n', ...
37-
atlas, ...
38-
spmAtlasDir)
46+
if verbose
47+
fprintf('\nCopying atlas "%s" to spm atlas directory:\n\t%s\n', ...
48+
atlas, ...
49+
spmAtlasDir);
50+
end
3951
spm_mkdir(spmAtlasDir);
40-
52+
4153
copyfile(sourceAtlasImage, spmAtlasDir);
42-
gunzip(fullfile(spmAtlasDir, '*.nii.gz'))
43-
delete(fullfile(spmAtlasDir, '*.nii.gz'))
44-
54+
gunzip(fullfile(spmAtlasDir, '*.nii.gz'));
55+
delete(fullfile(spmAtlasDir, '*.nii.gz'));
56+
4557
copyfile(sourceAtlasXml, spmAtlasDir);
46-
58+
4759
else
48-
fprintf('\nAtlas "%s" already in spm atlas directory:\n\t%s\n', ...
49-
atlas, ...
50-
spmAtlasDir)
51-
60+
if verbose
61+
fprintf('\nAtlas "%s" already in spm atlas directory:\n\t%s\n', ...
62+
atlas, ...
63+
spmAtlasDir);
64+
end
65+
5266
end
53-
54-
end
67+
68+
end

0 commit comments

Comments
 (0)