Skip to content

Commit fa2066e

Browse files
authored
Merge pull request #100 from cpp-lln-lab/transfer_to_spm_atlas
[ENH] Transfer all atlases to spm atlas
2 parents 582e49a + f071c64 commit fa2066e

8 files changed

+208
-43
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-
/ "Glasser"
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-
/ "Glasser"
19-
/ "space-MNI152ICBM2009anlin_atlas-glasser_dseg.xml"
18+
/ "space-MNI_atlas-wang_dseg.xml"
2019
)
2120

2221
mytree = ET.parse(xml_file)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<atlas version="2.0">
2+
<header>
3+
<name>A probabilistic functional parcellation of human occipito-temporal cortex. Rosenke 2020.</name>
4+
<version>1.0</version>
5+
<description>space-MNI_atlas-visfAtlas_dseg</description>
6+
<url />
7+
<licence />
8+
<coordinate_system>MNI</coordinate_system>
9+
<type>Label</type>
10+
<images>
11+
<imagefile>space-MNI_atlas-visfAtlas_dseg.nii</imagefile>
12+
</images>
13+
</header>
14+
<data>
15+
<label><index>1</index><name>lh_mFus</name></label>
16+
<label><index>2</index><name>lh_pFus</name></label>
17+
<label><index>3</index><name>lh_IOG</name></label>
18+
<label><index>4</index><name>lh_OTS</name></label>
19+
<label><index>5</index><name>lh_ITG</name></label>
20+
<label><index>6</index><name>lh_MTG</name></label>
21+
<label><index>7</index><name>lh_LOS</name></label>
22+
<label><index>8</index><name>lh_pOTS</name></label>
23+
<label><index>9</index><name>lh_IOS</name></label>
24+
<label><index>10</index><name>lh_CoS</name></label>
25+
<label><index>11</index><name>lh_hMT</name></label>
26+
<label><index>12</index><name>lh_v1d</name></label>
27+
<label><index>13</index><name>lh_v2d</name></label>
28+
<label><index>14</index><name>lh_v3d</name></label>
29+
<label><index>15</index><name>lh_v1v</name></label>
30+
<label><index>16</index><name>lh_v2v</name></label>
31+
<label><index>17</index><name>lh_v3v</name></label>
32+
<label><index>18</index><name>rh_mFus</name></label>
33+
<label><index>19</index><name>rh_pFus</name></label>
34+
<label><index>20</index><name>rh_IOG</name></label>
35+
<label><index>21</index><name>rh_OTS</name></label>
36+
<label><index>22</index><name>rh_ITG</name></label>
37+
<label><index>23</index><name>rh_MTG</name></label>
38+
<label><index>24</index><name>rh_LOS</name></label>
39+
<label><index>25</index><name>rh_CoS</name></label>
40+
<label><index>26</index><name>rh_TOS</name></label>
41+
<label><index>27</index><name>rh_hMT</name></label>
42+
<label><index>28</index><name>rh_v1d</name></label>
43+
<label><index>29</index><name>rh_v2d</name></label>
44+
<label><index>30</index><name>rh_v3d</name></label>
45+
<label><index>31</index><name>rh_v1v</name></label>
46+
<label><index>32</index><name>rh_v2v</name></label>
47+
<label><index>33</index><name>rh_v3v</name></label>
48+
</data>
49+
</atlas>

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: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function copyAtlasToSpmDir(varargin)
66
%
77
% copyAtlasToSpmDir(atlas, 'verbose', false)
88
%
9-
% :param atlas: Any of ``{'AAL'}``. Defaults to ``'AAL'``
9+
% :param atlas: Any of ``{'aal', 'hcpex', 'glasser', 'visfatlas', 'wang'}``.
10+
% Defaults to ``'AAL'``
1011
% :type atlas: char
1112
%
1213
% :param verbose: Defaults to ``false``
@@ -16,8 +17,6 @@ function copyAtlasToSpmDir(varargin)
1617

1718
% (C) Copyright 2022 CPP ROI developers
1819

19-
SUPPORTED_ATLASES = {'aal', 'hcpex'};
20-
2120
args = inputParser;
2221

2322
addOptional(args, 'atlas', 'AAL', @ischar);
@@ -30,29 +29,7 @@ function copyAtlasToSpmDir(varargin)
3029

3130
spmAtlasDir = fullfile(spm('dir'), 'atlas');
3231

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

5734
targetAtlasImage = fullfile(spmAtlasDir, spm_file(sourceAtlasImage, 'filename'));
5835
targetAtlasXml = fullfile(spmAtlasDir, spm_file(sourceAtlasXml, 'filename'));
@@ -90,4 +67,68 @@ function copyAtlasToSpmDir(varargin)
9067

9168
end
9269

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

src/atlas/extractRoiFromAtlas.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@
9292
roiIdx = strcmp([hemisphere '_' roiName], lut.ROI);
9393

9494
case 'glasser'
95-
95+
warning(['The volumetric version of the Glasser atlas is not ideally suited ', ...
96+
'to be used for standard brain-mapping approaches ', ...
97+
'that use volumetric nonlinear deformations.']);
9698
roiIdx = strcmp(roiName, lut.ROI);
9799

98100
end

tests/test_copyAtlasToSpmDir.m

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,39 @@
77
initTestSuite;
88
end
99

10-
function test_copyAtlasToSpmDir_glasser()
10+
function test_copyAtlasToSpmDir_wang()
1111

12-
if bids.internal.is_github_ci()
13-
return
14-
end
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+
26+
function test_copyAtlasToSpmDir_visfatlas()
27+
28+
copyAtlasToSpmDir('visfatlas', 'verbose', false);
29+
30+
targetAtlasImage = fullfile(spmAtlasDir(), ...
31+
'space-MNI_atlas-visfAtlas_dseg.nii');
32+
targetAtlasXml = fullfile(spmAtlasDir(), ...
33+
'space-MNI_atlas-visfAtlas_dseg.xml');
34+
35+
assertEqual(exist(targetAtlasImage, 'file'), 2);
36+
assertEqual(exist(targetAtlasXml, 'file'), 2);
37+
38+
cleanSpmAtlasDir();
39+
40+
end
41+
42+
function test_copyAtlasToSpmDir_glasser()
1543

1644
copyAtlasToSpmDir('Glasser', 'verbose', false);
1745

@@ -23,14 +51,12 @@ function test_copyAtlasToSpmDir_glasser()
2351
assertEqual(exist(targetAtlasImage, 'file'), 2);
2452
assertEqual(exist(targetAtlasXml, 'file'), 2);
2553

54+
cleanSpmAtlasDir();
55+
2656
end
2757

2858
function test_copyAtlasToSpmDir_basic()
2959

30-
if bids.internal.is_github_ci()
31-
return
32-
end
33-
3460
copyAtlasToSpmDir('AAL', 'verbose', false);
3561

3662
targetAtlasImage = fullfile(spmAtlasDir(), 'AAL3v1_1mm.nii');
@@ -39,14 +65,12 @@ function test_copyAtlasToSpmDir_basic()
3965
assertEqual(exist(targetAtlasImage, 'file'), 2);
4066
assertEqual(exist(targetAtlasXml, 'file'), 2);
4167

68+
cleanSpmAtlasDir();
69+
4270
end
4371

4472
function test_copyAtlasToSpmDir_HPCex()
4573

46-
if bids.internal.is_github_ci()
47-
return
48-
end
49-
5074
copyAtlasToSpmDir('HCPex', 'verbose', false);
5175

5276
targetAtlasImage = fullfile(spmAtlasDir(), 'HCPex.nii');
@@ -55,8 +79,15 @@ function test_copyAtlasToSpmDir_HPCex()
5579
assertEqual(exist(targetAtlasImage, 'file'), 2);
5680
assertEqual(exist(targetAtlasXml, 'file'), 2);
5781

82+
cleanSpmAtlasDir();
83+
5884
end
5985

6086
function value = spmAtlasDir()
6187
value = fullfile(spm('dir'), 'atlas');
6288
end
89+
90+
function cleanSpmAtlasDir()
91+
delete(fullfile(spmAtlasDir, '*.nii'));
92+
delete(fullfile(spmAtlasDir, '*.xml'));
93+
end

0 commit comments

Comments
 (0)