forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathea_checkinstall.m
340 lines (319 loc) · 11.5 KB
/
ea_checkinstall.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
function [success, commands] = ea_checkinstall(cmd,checkonly,robot)
success=1;
if ~exist('checkonly','var')
checkonly=0;
end
if ~exist('robot','var')
robot=0;
end
switch cmd
case 'list' % simply return list of installable datasets
success={'Redownload data files'
'Install development version of Lead'
'2009b Nonlinear Flip Transform'
'7T Cardiac Gated FLASH MRI (Backdrop visualization)'
'7T Ex Vivo 100um Brain Atlas (Backdrop visualization)'
'Macroscale Human Connectome Atlas (Yeh 2018)'
'Structural group connectome 20 subjects Gibbs-tracker (Horn 2013)'
'Structural group connectome 169 NKI subjects Gibbs-tracker (Horn 2016)'
'Structural group connectome 32 Adult Diffusion HCP subjects GQI v1.1 (Horn 2017)'
'Structural group connectome 85 PPMI PD-patients GQI v1.1 (Ewert 2017)'
'Functional group connectome 74 PPMI PD-patients, 15 controls (Horn 2017)'};
commands={'leaddata'
'hotfix'
'nlinflip'
'7tcgflash'
'7tev100um'
'macroscalehc'
'groupconnectome2013'
'groupconnectome2016'
'groupconnectome2017'
'groupconnectome_ppmi2017'
'fgroupconnectome_ppmi2017'};
case 'leaddata'
checkf=[ea_space,'bb.nii'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Lead Datafiles',...
[],...
'');
else
disp('Lead datafiles is installed.')
end
case 'nlinflip'
checkf=[ea_space,'fliplr'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('FlipLR',...
[ea_space,'fliplr.zip'],...
'fliplr');
else
disp('2009b asym LR flip transform is installed.')
end
case '7tcgflash'
if exist([ea_space,'backdrops',filesep,'7T_Flash_Horn_2018.mat'], 'file')
movefile([ea_space,'backdrops',filesep,'7T_Flash_Horn_2018.mat'], ...
[ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.mat']);
fid = fopen([ea_space,'backdrops',filesep,'backdrops.txt'], 'r');
text = fread(fid, inf, '*char')';
fclose(fid);
text = strrep(text, '7T_Flash_Horn_2018.mat', '7T_Flash_Horn_2019.mat');
fid = fopen([ea_space,'backdrops',filesep,'backdrops.txt'], 'w');
fwrite(fid, text);
fclose(fid);
end
checkf=[ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
ea_mkdir([ea_space,'backdrops']);
success=ea_downloadasset('7T Cardiac Gated Flash MRI',...
[ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.mat'],...
'7tcgflash');
m = matfile([ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.mat'],'Writable',true);
m.fname = [ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.nii'];
fid=fopen([ea_space,'backdrops',filesep,'backdrops.txt'],'a');
fprintf(fid,'%s %s\n','7T_Flash_Horn_2019.mat','7T_Cardiac_Gated_Flash_MRI_(Horn_2019)');
fclose(fid);
else
disp('7T Cardiac Gated FLASH MRI (Backdrop visualization) is installed.')
end
case '7tev100um'
checkf=[ea_space,'backdrops',filesep,'7T_100um_Edlow_2019.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
ea_mkdir([ea_space,'backdrops']);
success=ea_downloadasset('7T Ex Vivo 100um Brain Atlas',...
[ea_space,'backdrops',filesep,'7T_100um_Edlow_2019.mat'],...
'7tev100um');
m = matfile([ea_space,'backdrops',filesep,'7T_100um_Edlow_2019.mat'],'Writable',true);
m.fname = [ea_space,'backdrops',filesep,'7T_100um_Edlow_2019.nii'];
fid=fopen([ea_space,'backdrops',filesep,'backdrops.txt'],'a');
fprintf(fid,'%s %s\n','7T_100um_Edlow_2019.mat','7T_Ex_Vivo_100um_Brain_Atlas_(Edlow_2019)');
fclose(fid);
else
disp('7T Ex Vivo 100um Brain Atlas (Backdrop visualization) is installed.')
end
case 'macroscalehc'
checkf=[ea_space,'atlases',filesep,'Macroscale Human Connectome Atlas (Yeh 2018)',filesep,'atlas_index.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Macroscale Human Connectome Atlas',...
[ea_space,'atlases',filesep,'Macroscale_Human_Connectome_Atlas_Yeh_2018.zip'],...
'macroscalehc');
else
disp('Macroscale Human Connectome Atlas is installed.')
end
case 'bigbrain'
checkf=[ea_space,'bigbrain_2015_100um_bb.nii'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Bigbrain 100um subcortical',...
[ea_space,'bigbrain_2015_100um_bb.nii.gz'],...
'bigbrain');
else
disp('BigBrain is installed.')
end
case 'groupconnectome2013'
checkf=[ea_getconnectomebase('dmri'),'Groupconnectome (Horn 2013) full',filesep,'data.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Structural Group Connectome (Horn 2013)',...
[ea_getconnectomebase('dmri'),'groupconnectome2013.zip'],...
'group2013');
else
disp('Structural Group Connectome (Horn 2013) is installed.')
end
case 'groupconnectome2016'
checkf=[ea_getconnectomebase('dmri'),'Gibbsconnectome_169 (Horn 2016)',filesep,'data.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Structural Group Connectome (Horn 2016)',...
[ea_getconnectomebase('dmri'),'groupconnectome2016.zip'],...
'group2016');
else
disp('Structural Group Connectome (Horn 2016) is installed.')
end
case 'groupconnectome2017'
checkf=[ea_getconnectomebase('dmri'),'HCP_MGH_32fold_groupconnectome (Horn 2017)',filesep,'data.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Structural Group Connectome (Horn 2017)',...
[ea_getconnectomebase('dmri'),'groupconnectome2017.zip'],...
'group2017');
else
disp('Structural Group Connectome (Horn 2017) is installed.')
end
case 'groupconnectome_ppmi2017'
checkf=[ea_getconnectomebase('dmri'),'PPMI_85 (Ewert 2017)',filesep,'data.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Structural Group Connectome (Ewert 2017)',...
[ea_getconnectomebase('dmri'),'groupconnectome_ppmi2017.zip'],...
'group2017_ppmi');
else
disp('Structural Group Connectome (Ewert 2017) is installed.')
end
case 'fgroupconnectome_ppmi2017'
checkf=[ea_getconnectomebase('fmri'),'PPMI 74_15 (Horn 2017)',filesep,'dataset_info.mat'];
force=ea_alreadyinstalled(checkf,checkonly,robot);
if checkonly
success=~force;
return;
end
if force==-1
success=-1;
return;
end
if ~exist(checkf,'file') || force
success=ea_downloadasset('Functional Group Connectome (Horn 2017)',...
[ea_getconnectomebase('fmri'),'fgroupconnectome_ppmi2017.zip'],...
'fgroup2017_ppmi');
else
disp('Functional Group Connectome (Horn 2017) is installed.')
end
case 'hotfix'
if ~checkonly
success=ea_hotfix;
end
otherwise
success=0;
end
function success=ea_downloadasset(assetname,destination,id)
if strcmp(assetname,'Lead Datafiles')
ea_update_data('full');
success=1;
else
downloadurl = 'https://www.lead-dbs.org/release/download.php';
success=1;
disp(['Downloading ',assetname,'...'])
if ~exist(fileparts(destination), 'dir')
mkdir(fileparts(destination));
end
try
webopts=weboptions('Timeout',Inf);
websave(destination,downloadurl,'id',id,webopts);
catch
try
urlwrite([downloadurl,'?id=',id],destination,'Timeout',Inf);
catch
success=0;
end
end
[loc,~,ext] = fileparts(destination);
if success
disp(['Installing ',assetname,'...'])
if strcmp(ext,'.gz')
gunzip(destination, loc);
ea_delete(destination);
elseif strcmp(ext,'.zip')
unzip(destination, loc);
ea_delete(destination);
end
else
fprintf(['\nDownload error! You may try to download the file manually from:\n',...
'%s\nand then extract it into %s.\n\n'], [downloadurl,'?id=',id], loc);
msgbox('Please check the command window for more information.','Download error!','Error')
return
end
end
function force=ea_alreadyinstalled(checkf,checkonly,robot)
if ~exist(checkf,'file') % then file not there, should install anyways.
force=1;
return
end
if checkonly % return here.
force=0;
return
end
if ~robot
choice = questdlg('This dataset seems already to be installed. Do you wish to re-download it?', ...
'Redownload Dataset?', ...
'Yes','No','No');
if strcmp(choice,'Yes')
force=1;
else
force=-1;
end
else
force=0;
end