forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ea_assignpretra.m
54 lines (46 loc) · 1.83 KB
/
ea_assignpretra.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
function [options, presentfiles] = ea_assignpretra(options,allowgz)
if ~exist('allowgz','var')
allowgz=0;
end
directory = fullfile(options.root, options.patientname);
if allowgz
sstr=[options.prefs.prenii_searchstring(1:end-1),'*'];
else
sstr=[options.prefs.prenii_searchstring];
end
presfiles = dir(fullfile(directory, sstr));
pfcell = {presfiles.name}';
% order the anatomical images in accordance with 'prefs.prenii_order'
prenii_order = cellfun(@(x) strrep(options.prefs.prenii_searchstring,'*',x), options.prefs.prenii_order, 'UniformOutput', 0);
[~,idx] = ismember(ea_stripext(prenii_order), ea_stripext(pfcell));
presentfiles = pfcell([nonzeros(idx)',setdiff(1:numel(pfcell),nonzeros(idx))]);
load([ea_space,'ea_space_def.mat']);
options.primarytemplate = spacedef.templates{1}; % default T1.
if isempty(presentfiles)
warning(['No anatomy information found! Please put either ', ...
prenii_order{1},', ',prenii_order{2},' or ',prenii_order{3},' into subject folder.']);
return
end
ism=ismember(presentfiles,{'anat_STN.nii','anat_GPi.nii','anat_GPe.nii','anat_RN.nii'});
addtoend=presentfiles(ism);
presentfiles(ism)=[];
presentfiles=[presentfiles;addtoend];
% set prenii_unnormalized
options.prefs.prenii_unnormalized = presentfiles{1};
% determine primary template
if any(idx)
which=options.prefs.prenii_order(find(idx,1));
for t=1:size(spacedef.norm_mapping,1)
if ismember(which,spacedef.norm_mapping{t,1})
break
end
end
if t==size(spacedef.norm_mapping,1) && (~ismember(which,spacedef.norm_mapping{t,1})) % didnt find corresponding template
options.primarytemplate=spacedef.norm_mapping{t,2};
else
options.primarytemplate = spacedef.misfit_template;
end
if iscell(options.primarytemplate)
options.primarytemplate=options.primarytemplate{1};
end
end