-
Notifications
You must be signed in to change notification settings - Fork 7
/
NeuronJSON.m
85 lines (72 loc) · 2.35 KB
/
NeuronJSON.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
classdef NeuronJSON < sbfsem.core.NeuronAPI
% NEURONJSON
%
% Description:
% Instantiates a Neuron object from a JSON file
%
% Constructor:
% obj = NeuronJSON(jsonPath)
%
% History:
% 21Aug2018 - SSP
% 25Nov2018 - SSP - Removed webread dependencies, works offline now
% ---------------------------------------------------------------------
properties
fPath % JSON file path
end
methods
function obj = NeuronJSON(jsonPath)
% NEURONJSON Constructor
if nargin < 1
[fileName, filePath] = uigetfile('.json', 'Pick a JSON file');
jsonPath = [filePath, fileName];
end
[~, fName, ext] = fileparts(jsonPath);
assert(strcmp(ext, '.json'), 'Input must be a JSON file!');
ID = str2double(fName(2:end));
source = validateSource(fName(1));
[email protected](ID, source);
obj.fPath = jsonPath;
obj.parseJSON(obj.fPath);
end
function update(~)
% UPDATE Overwrite, this function is only useful for databases
end
end
methods (Access = private)
function parseJSON(obj, jsonFile)
% Load JSON as a struct
S = loadjson(jsonFile);
assert(obj.ID == S.ID,...
'ID of imported JSON file does not match title ID');
assert(strcmp(obj.source, S.source), 'Volume names do not match');
% The easy stuff
obj.viking = S.viking;
obj.volumeScale = S.volumeScale;
obj.omittedIDs = S.omittedIDs;
obj.lastModified = S.lastModified;
% Convert to tables
obj.nodes = struct2table(vertcat(S.nodes{:}{:}));
obj.edges = struct2table(vertcat(S.edges{:}{:}));
if ~isempty(S.geometries)
obj.geometries = struct2table(vertcat(S.geometries{:}{:}));
end
if ~isempty(S.synapses)
try
obj.synapses = struct2table(vertcat(S.synapses{:}{:}));
catch
obj.synapses = [];
end
end
% Convert the enumerations
obj.transform = sbfsem.builtin.Transforms.fromStr(S.transform);
if ~isempty(obj.synapses)
obj.synapses.LocalName = arrayfun(@(x) sbfsem.core.StructureTypes(x), obj.synapses.LocalName);
end
% Convert the model... ? For now, just rebuild it.
if ~isempty(S.model)
obj.build();
end
end
end
end