forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ea_checkinstall.m
420 lines (394 loc) · 14.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
function [success, commands] = ea_checkinstall(cmd,checkonly,robot,prefs)
success=1;
if ~exist('checkonly','var')
checkonly=0;
end
if ~exist('robot','var')
robot=0;
end
if ~exist('prefs','var')
prefs = [];
end
switch cmd
case 'list' % simply return list of installable datasets
success={'Redownload data files'
'Install development version of Lead'
'2009b Nonlinear Flip Transform'
'Allan Institute Genetics Database'
'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'
'allengenetics'
'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 'allengenetics'
checkf=[ea_space,'genetics'];
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('Allan Institute Genetics Database',...
[ea_space,'genetics.zip'],...
'allengenetics');
else
disp('Allan Institute Genetics Database is installed.')
end
case '7tcgflash'
space = ea_space;
if exist([space,'backdrops',filesep,'7T_Flash_Horn_2018.mat'], 'file')
movefile([space,'backdrops',filesep,'7T_Flash_Horn_2018.mat'], ...
[space,'backdrops',filesep,'7T_Flash_Horn_2019.mat']);
fid = fopen([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([space,'backdrops',filesep,'backdrops.txt'], 'w');
fwrite(fid, text);
fclose(fid);
end
checkf=[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([space,'backdrops']);
success=ea_downloadasset('7T Cardiac Gated Flash MRI',...
[ea_space,'backdrops',filesep,'7T_Flash_Horn_2019.mat'],...
'7tcgflash');
m = matfile([space,'backdrops',filesep,'7T_Flash_Horn_2019.mat'],'Writable',true);
m.fname = [space,'backdrops',filesep,'7T_Flash_Horn_2019.nii'];
fid=fopen([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'
space = ea_space;
checkf=[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([space,'backdrops']);
success=ea_downloadasset('7T Ex Vivo 100um Brain Atlas',...
[ea_space,'backdrops',filesep,'7T_100um_Edlow_2019.mat'],...
'7tev100um');
m = matfile([space,'backdrops',filesep,'7T_100um_Edlow_2019.mat'],'Writable',true);
m.fname = [space,'backdrops',filesep,'7T_100um_Edlow_2019.nii'];
fid=fopen([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'
space=ea_space;
checkf=[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',...
[space,'atlases',filesep,'Macroscale_Human_Connectome_Atlas_Yeh_2018.zip'],...
'macroscalehc');
else
disp('Macroscale Human Connectome Atlas is installed.')
end
case 'bigbrain'
space=ea_space;
checkf=[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',...
[space,'bigbrain_2015_100um_bb.nii.gz'],...
'bigbrain');
else
disp('BigBrain is installed.')
end
case 'groupconnectome2013'
checkf=[ea_getconnectomebase('dmri',prefs),'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',prefs),'groupconnectome2013.zip'],...
'group2013');
else
disp('Structural Group Connectome (Horn 2013) is installed.')
end
case 'groupconnectome2016'
checkf=[ea_getconnectomebase('dmri',prefs),'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',prefs),'groupconnectome2016.zip'],...
'group2016');
else
disp('Structural Group Connectome (Horn 2016) is installed.')
end
case 'groupconnectome2017'
checkf=[ea_getconnectomebase('dmri',prefs),'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',prefs),'groupconnectome2017.zip'],...
'group2017');
else
disp('Structural Group Connectome (Horn 2017) is installed.')
end
case 'groupconnectome_ppmi2017'
checkf=[ea_getconnectomebase('dmri',prefs),'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',prefs),'groupconnectome_ppmi2017.zip'],...
'group2017_ppmi');
else
disp('Structural Group Connectome (Ewert 2017) is installed.')
end
case 'fgroupconnectome_ppmi2017'
checkf=[ea_getconnectomebase('fmri',prefs),'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',prefs),'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;
if ~exist(fileparts(destination), 'dir')
mkdir(fileparts(destination));
end
% get the file size and display it to inform user of size
try
fsize = ea_getassetfilesize(id); % get the filesize in bytes from the server
catch
fsize = 0;
end
if fsize ~= 0
fprintf('Downloading %s with a size of %.2f GB\nFilename: %s\n', assetname, fsize*1e-9, destination);
else
fprintf('Downloading %s\nFilename: %s\n', ea_getspace, destination);
disp('This could take a while...');
end
% first see if parallel toolbox is installed and can be utilized to
% download in the backgroung
if license('test', 'Distrib_Computing_Toolbox') % check if parallel toolbox is installed
disp('Parallel toolbox detected, downloading via background worker')
try
ea_downloadasset_parallel(downloadurl, assetname, destination, id, fsize);
catch
try
delete(findall(0,'type','figure','tag','TMWWaitbar')); % delete waitbar if error occured
disp('Download using parallel toolbox failed, trying websave...')
webopts=weboptions('Timeout',Inf);
websave(destination,downloadurl,'id',id,webopts);
catch
disp('Parallel toolbox not detected, downloading via websave...')
try
disp('''websave'' failed, trying ''urlwrite''.');
urlwrite([downloadurl,'?id=',id],destination,'Timeout',Inf);
catch
disp('''urlwrite'' failed.');
success=0;
end
end
end
else
try
disp('Trying ''websave''.');
webopts=weboptions('Timeout',Inf);
% uncomment this if you encounter problems with certificate validation
% (see https://www.mathworks.com/matlabcentral/answers/400086-how-to-read-data-form-website-url)
%webopts.CertificateFilename=('');
websave(destination,downloadurl,'id',id,webopts);
catch
try
disp('''websave'' failed, trying ''urlwrite''.');
urlwrite([downloadurl,'?id=',id],destination,'Timeout',Inf);
catch
disp('''urlwrite'' failed.');
success=0;
end
end
end
[loc,~,ext] = fileparts(destination);
if success
disp(['Installing ',assetname,'...'])
try
if strcmp(ext,'.gz')
gunzip(destination, loc);
ea_delete(destination);
elseif strcmp(ext,'.zip')
unzip(destination, loc);
ea_delete(destination);
end
catch
disp('Installation failed.');
success=0;
end
end
if ~success
fprintf(['\nDownload / install 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