Skip to content

Commit 31b03cf

Browse files
committed
copy wang atlas to spm atlas dir
1 parent 227e736 commit 31b03cf

File tree

7 files changed

+138
-36
lines changed

7 files changed

+138
-36
lines changed

atlas/Glasser/space-MNI152ICBM2009anlin_atlas-glasser_dseg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
22
<atlas version="2.0">
33
<header>
4-
<name>space-MNI152ICBM2009anlin_atlas-glasser_dseg</name>
4+
<name>A multi-modal parcellation of human cerebral cortex. Glasser 2016</name>
55
<version>1.0</version>
66
<description>space-MNI152ICBM2009anlin_atlas-glasser_dseg</description>
77
<url></url>

atlas/space-MNI_atlas-wang_dseg.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<atlas version="2.0">
2+
<header>
3+
<name>Probabilistic Maps of Visual Topography in Human Cortex. Wang 2015.</name>
4+
<version>1.0</version>
5+
<description>space-MNI_atlas-wang_dseg</description>
6+
<url />
7+
<licence />
8+
<coordinate_system>MNI</coordinate_system>
9+
<type>Label</type>
10+
<images>
11+
<imagefile>space-MNI_atlas-wang_dseg.nii</imagefile>
12+
</images>
13+
</header>
14+
<data>
15+
<label><index>1</index><name>V1v</name></label>
16+
<label><index>2</index><name>V1d</name></label>
17+
<label><index>3</index><name>V2v</name></label>
18+
<label><index>4</index><name>V2d</name></label>
19+
<label><index>5</index><name>V3v</name></label>
20+
<label><index>6</index><name>V3d</name></label>
21+
<label><index>7</index><name>hV4</name></label>
22+
<label><index>8</index><name>VO1</name></label>
23+
<label><index>9</index><name>VO2</name></label>
24+
<label><index>10</index><name>PHC1</name></label>
25+
<label><index>11</index><name>PHC2</name></label>
26+
<label><index>12</index><name>MST</name></label>
27+
<label><index>13</index><name>hMT</name></label>
28+
<label><index>14</index><name>LO2</name></label>
29+
<label><index>15</index><name>LO1</name></label>
30+
<label><index>16</index><name>V3b</name></label>
31+
<label><index>17</index><name>V3a</name></label>
32+
<label><index>18</index><name>IPS0</name></label>
33+
<label><index>19</index><name>IPS1</name></label>
34+
<label><index>20</index><name>IPS2</name></label>
35+
<label><index>21</index><name>IPS3</name></label>
36+
<label><index>22</index><name>IPS4</name></label>
37+
<label><index>23</index><name>IPS5</name></label>
38+
<label><index>24</index><name>SPL1</name></label>
39+
<label><index>25</index><name>FEF</name></label>
40+
</data>
41+
</atlas>

atlas/update_atlas_xml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
lut_file = (
99
Path(__file__).parent
10-
/ "visfAtlas"
10+
/ "visual_topography_probability_atlas"
1111
/ "LUT.csv"
1212
)
1313

1414
df = pd.read_csv(lut_file, sep=",")
1515

1616
xml_file = (
1717
Path(__file__).parent
18-
/ "visfAtlas"
19-
/ "space-MNI_atlas-visfAtlas_dseg.xml"
18+
/ "space-MNI_atlas-wang_dseg.xml"
2019
)
2120

2221
mytree = ET.parse(xml_file)

atlas/visfAtlas/space-MNI_atlas-visfAtlas_dseg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<atlas version="2.0">
22
<header>
3-
<name>space-MNI_atlas-visfAtlas_dseg</name>
3+
<name>A probabilistic functional parcellation of human occipito-temporal cortex. Rosenke 2020.</name>
44
<version>1.0</version>
55
<description>space-MNI_atlas-visfAtlas_dseg</description>
66
<url />

initCppRoi.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function initCppRoi()
3131
copyAtlasToSpmDir('HCPex', 'verbose', true);
3232
copyAtlasToSpmDir('AAL', 'verbose', true);
3333
copyAtlasToSpmDir('Glasser', 'verbose', true);
34+
copyAtlasToSpmDir('Wang', 'verbose', true);
35+
copyAtlasToSpmDir('visfAtlas', 'verbose', true);
3436

3537
CPP_ROI_INITIALIZED = true();
3638

src/atlas/copyAtlasToSpmDir.m

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function copyAtlasToSpmDir(varargin)
66
%
77
% copyAtlasToSpmDir(atlas, 'verbose', false)
88
%
9-
% :param atlas: Any of ``{'aal', 'hcpex', 'glasser', 'visfatlas'}``.
9+
% :param atlas: Any of ``{'aal', 'hcpex', 'glasser', 'visfatlas', 'wang'}``.
1010
% Defaults to ``'AAL'``
1111
% :type atlas: char
1212
%
@@ -17,8 +17,6 @@ function copyAtlasToSpmDir(varargin)
1717

1818
% (C) Copyright 2022 CPP ROI developers
1919

20-
SUPPORTED_ATLASES = {'aal', 'hcpex', 'glasser', 'visfatlas'};
21-
2220
args = inputParser;
2321

2422
addOptional(args, 'atlas', 'AAL', @ischar);
@@ -31,34 +29,7 @@ function copyAtlasToSpmDir(varargin)
3129

3230
spmAtlasDir = fullfile(spm('dir'), 'atlas');
3331

34-
switch lower(atlas)
35-
36-
case 'aal'
37-
sourceAtlasImage = fullfile(returnAtlasDir(), 'AAL3', 'AAL3v1_1mm.nii.gz');
38-
sourceAtlasXml = fullfile(returnAtlasDir(), 'AAL3', 'AAL3v1_1mm.xml');
39-
40-
case 'hcpex'
41-
unzipAtlas(lower(atlas));
42-
sourceAtlasImage = fullfile(returnAtlasDir(lower(atlas)), 'HCPex.nii');
43-
sourceAtlasXml = fullfile(returnAtlasDir(), 'HCPex.xml');
44-
45-
case 'visfatlas'
46-
unzipAtlas(lower(atlas));
47-
sourceAtlasImage = fullfile(returnAtlasDir(lower(atlas)), 'space-MNI_atlas-visfAtlas_dseg.nii');
48-
sourceAtlasXml = fullfile(returnAtlasDir(lower(atlas)), 'space-MNI_atlas-visfAtlas_dseg.xml');
49-
50-
case 'glasser'
51-
unzipAtlas(lower(atlas));
52-
sourceAtlasImage = fullfile(returnAtlasDir(lower(atlas)), ...
53-
'space-MNI152ICBM2009anlin_atlas-glasser_dseg.nii');
54-
sourceAtlasXml = fullfile(returnAtlasDir(lower(atlas)), ...
55-
'space-MNI152ICBM2009anlin_atlas-glasser_dseg.xml');
56-
57-
otherwise
58-
error(['Only the following atlases can be copied to SPM atlas folder:\n', ...
59-
bids.internal.create_unordered_list(SUPPORTED_ATLASES)]);
60-
61-
end
32+
[sourceAtlasImage, sourceAtlasXml] = prepareFiles(atlas);
6233

6334
targetAtlasImage = fullfile(spmAtlasDir, spm_file(sourceAtlasImage, 'filename'));
6435
targetAtlasXml = fullfile(spmAtlasDir, spm_file(sourceAtlasXml, 'filename'));
@@ -97,3 +68,63 @@ function copyAtlasToSpmDir(varargin)
9768
end
9869

9970
end
71+
72+
function [sourceAtlasImage, sourceAtlasXml] = prepareFiles(atlas)
73+
74+
SUPPORTED_ATLASES = {'aal', 'hcpex', 'glasser', 'visfatlas', 'wang'};
75+
76+
atlas = lower(atlas);
77+
switch atlas
78+
79+
case 'aal'
80+
sourceAtlasImage = fullfile(returnAtlasDir(), 'AAL3', 'AAL3v1_1mm.nii.gz');
81+
sourceAtlasXml = fullfile(returnAtlasDir(), 'AAL3', 'AAL3v1_1mm.xml');
82+
83+
case 'hcpex'
84+
sourceAtlasImage = fullfile(returnAtlasDir(atlas), 'HCPex.nii');
85+
sourceAtlasXml = fullfile(returnAtlasDir(), 'HCPex.xml');
86+
87+
case 'visfatlas'
88+
sourceAtlasImage = fullfile(returnAtlasDir(atlas), 'space-MNI_atlas-visfAtlas_dseg.nii');
89+
sourceAtlasXml = fullfile(returnAtlasDir(atlas), 'space-MNI_atlas-visfAtlas_dseg.xml');
90+
91+
case 'glasser'
92+
93+
sourceAtlasImage = fullfile(returnAtlasDir(atlas), ...
94+
'space-MNI152ICBM2009anlin_atlas-glasser_dseg.nii');
95+
sourceAtlasXml = fullfile(returnAtlasDir(atlas), ...
96+
'space-MNI152ICBM2009anlin_atlas-glasser_dseg.xml');
97+
98+
case 'wang'
99+
sourceAtlasImage = fullfile(returnAtlasDir(atlas), ...
100+
'subj_vol_all', ...
101+
'space-MNI_atlas-wang_dseg.nii');
102+
sourceAtlasXml = fullfile(returnAtlasDir(), ...
103+
'space-MNI_atlas-wang_dseg.xml');
104+
105+
otherwise
106+
error(['Only the following atlases can be copied to SPM atlas folder:\n', ...
107+
bids.internal.create_unordered_list(SUPPORTED_ATLASES)]);
108+
109+
end
110+
111+
if ismember(atlas, {'hcpex', 'glasser', 'visfatlas', 'wang'})
112+
if exist(sourceAtlasImage, 'file') ~= 2
113+
unzipAtlas(atlas);
114+
end
115+
end
116+
117+
if strcmp(atlas, 'wang')
118+
% merge left and right
119+
files = spm_select('FPList', ...
120+
fullfile(returnAtlasDir(lower(atlas)), 'subj_vol_all'), ...
121+
'^space.*hemi.*nii$');
122+
hdr = spm_vol(files);
123+
vols = spm_read_vols(hdr);
124+
vol = sum(vols, 4);
125+
hdr = hdr(1);
126+
hdr(1).fname = sourceAtlasImage;
127+
spm_write_vol(hdr, vol);
128+
end
129+
130+
end

tests/test_copyAtlasToSpmDir.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
initTestSuite;
88
end
99

10+
function test_copyAtlasToSpmDir_wang()
11+
12+
copyAtlasToSpmDir('wang', 'verbose', false);
13+
14+
targetAtlasImage = fullfile(spmAtlasDir(), ...
15+
'space-MNI_atlas-wang_dseg.nii');
16+
targetAtlasXml = fullfile(spmAtlasDir(), ...
17+
'space-MNI_atlas-wang_dseg.xml');
18+
19+
assertEqual(exist(targetAtlasImage, 'file'), 2);
20+
assertEqual(exist(targetAtlasXml, 'file'), 2);
21+
22+
cleanSpmAtlasDir();
23+
24+
end
25+
1026
function test_copyAtlasToSpmDir_visfatlas()
1127

1228
copyAtlasToSpmDir('visfatlas', 'verbose', false);
@@ -19,6 +35,8 @@ function test_copyAtlasToSpmDir_visfatlas()
1935
assertEqual(exist(targetAtlasImage, 'file'), 2);
2036
assertEqual(exist(targetAtlasXml, 'file'), 2);
2137

38+
cleanSpmAtlasDir();
39+
2240
end
2341

2442
function test_copyAtlasToSpmDir_glasser()
@@ -37,6 +55,8 @@ function test_copyAtlasToSpmDir_glasser()
3755
assertEqual(exist(targetAtlasImage, 'file'), 2);
3856
assertEqual(exist(targetAtlasXml, 'file'), 2);
3957

58+
cleanSpmAtlasDir();
59+
4060
end
4161

4262
function test_copyAtlasToSpmDir_basic()
@@ -53,6 +73,8 @@ function test_copyAtlasToSpmDir_basic()
5373
assertEqual(exist(targetAtlasImage, 'file'), 2);
5474
assertEqual(exist(targetAtlasXml, 'file'), 2);
5575

76+
cleanSpmAtlasDir();
77+
5678
end
5779

5880
function test_copyAtlasToSpmDir_HPCex()
@@ -69,8 +91,15 @@ function test_copyAtlasToSpmDir_HPCex()
6991
assertEqual(exist(targetAtlasImage, 'file'), 2);
7092
assertEqual(exist(targetAtlasXml, 'file'), 2);
7193

94+
cleanSpmAtlasDir();
95+
7296
end
7397

7498
function value = spmAtlasDir()
7599
value = fullfile(spm('dir'), 'atlas');
76100
end
101+
102+
function cleanSpmAtlasDir()
103+
delete(fullfile(spmAtlasDir, '*.nii'));
104+
delete(fullfile(spmAtlasDir, '*.xml'));
105+
end

0 commit comments

Comments
 (0)