-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathAP_loadStructureTree.m
51 lines (38 loc) · 1.86 KB
/
AP_loadStructureTree.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
function structureTreeTable = AP_loadStructureTree(fn)
% function structureTreeTable = loadStructureTree(fn)
% note: use an edited version that doesn't have commas in any fields...
%
% AP didn't write this, it was directly copied from:
% https://github.com/cortex-lab/allenCCF/blob/master/Browsing%20Functions/loadStructureTree.m
%
% AP prefix was added to remove dependency on that repository
if nargin<1
p = mfilename('fullpath');
fn = fullfile(fileparts(fileparts(p)), 'structure_tree_safe_2017.csv');
end
[~, fnBase] = fileparts(fn);
if ~isempty(strfind(fnBase, '2017'))
mode = '2017';
else
mode = 'old';
end
fid = fopen(fn, 'r');
if strcmp(mode, 'old')
titles = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s', 1, 'delimiter', ',');
titles = cellfun(@(x)x{1}, titles, 'uni', false);
titles{1} = 'index'; % this is blank in the file
data = textscan(fid, '%d%s%d%s%d%s%d%d%d%d%d%s%s%d%d%s%d%s%s%d%d', 'delimiter', ',');
elseif strcmp(mode, '2017')
titles = textscan(fid, repmat('%s', 1, 21), 1, 'delimiter', ',');
titles = cellfun(@(x)x{1}, titles, 'uni', false);
data = textscan(fid, ['%d%d%s%s'... % 'id' 'atlas_id' 'name' 'acronym'
'%s%d%d%d'... % 'st_level' 'ontology_id' 'hemisphere_id' 'weight'
'%d%d%d%d'... % 'parent_structure_id' 'depth' 'graph_id' 'graph_order'
'%s%s%d%s'... % 'structure_id_path' 'color_hex_triplet' neuro_name_structure_id neuro_name_structure_id_path
'%s%d%d%d'... % 'failed' 'sphinx_id' structure_name_facet failed_facet
'%s'], 'delimiter', ','); % safe_name
titles = ['index' titles];
data = [[0:numel(data{1})-1]' data];
end
structureTreeTable = table(data{:}, 'VariableNames', titles);
fclose(fid);