-
Notifications
You must be signed in to change notification settings - Fork 1
/
SynapseLocator.m
127 lines (108 loc) · 3.98 KB
/
SynapseLocator.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
function SynapseLocator()
%SynapseLocator initializes SynapseLocator
%
%
%
% MATLAB Version: '9.3.0.713579 (R2017b)'
% MATLAB Version: '9.5.0.944444 (R2018b)'
%
%
% drchrisch10sep2018
% drchrisch30nov2018
%
%
if isempty(findobj('Name', 'Synapse Locator'))
% Read parameters from file and set fields in synLoc object!
mFile = which(mfilename, '-all');
% Check for single installation!
if ne(numel(mFile), 1)
opts = struct('WindowStyle', 'modal', 'Interpreter', 'tex');
warndlg('\color{red} More than one installation of SynapseLocator found!', 'Installation Warning', opts);
return
end
% Create waitbar to track process of application!
wbH = waitbar(0, 'Starting Synapse Locator GUI...', 'Name', 'Synapse Locator Initialization', 'WindowStyle', 'modal', 'Pointer', 'watch');
[mPath,~,~] = fileparts(mFile{:});
paramsFile = dir(fullfile(mPath, 'synapseLocatorParams.txt'));
paramsFile = fullfile(mPath, paramsFile.name);
params_ = table2struct(readtable(paramsFile, 'readVariableNames', 0, 'Delimiter', ',', 'CommentStyle', '#'));
params = struct('SynapseLocatorParameterFile', paramsFile);
for idx = 1:size(params_, 1)
params.(params_(idx).Var1) = params_(idx).Var2;
end
params.synapseLocatorFolder = mPath;
% Check fiji path and load jars!
[success, params] = IJ_checker_Fcn(params);
if ~success
delete(wbH)
errordlg('SORRY, NO IMAGEJ INSTALLATION FOUND!', 'ImageJ NOT FOUND')
return
end
% Initiate synapseLocator object!
sLobj = synapseLocator.synLoc();
% Set parameters!
paramF = fields(params);
field_idx = ismember(paramF, fields(sLobj));
for ps_ = paramF(field_idx)'
sLobj.(ps_{:}) = params.(ps_{:});
end
% Convert strings to numbers!
for sLobjF_ = fields(sLobj)'
if ischar(sLobj.(sLobjF_{:}))
if startsWith(sLobj.(sLobjF_{:}), '[') && endsWith(sLobj.(sLobjF_{:}), ']')
sLobj.(sLobjF_{:}) = strrep(sLobj.(sLobjF_{:}), '[', '');
sLobj.(sLobjF_{:}) = strrep(sLobj.(sLobjF_{:}), ']', '');
sLobj.(sLobjF_{:}) = str2double((split(sLobj.(sLobjF_{:}), {' ', ','}))');
end
if ~isnan(str2double(sLobj.(sLobjF_{:})))
sLobj.(sLobjF_{:}) = str2double(sLobj.(sLobjF_{:}));
end
end
end
% Prepare summary tables
sLobj.summaryFields = strtrim(split(sLobj.summaryFields, ','));
sLobj.summaryTemplate = struct();
for tmpField = [sLobj.summaryFields]'
sLobj.summaryTemplate.(tmpField{:}) = [];
end
sLobj.summaryTableFields = strtrim(split(sLobj.summaryTableFields, ','));
sLobj.summaryTableTemplate = struct();
for tmpField = [sLobj.summaryTableFields]'
sLobj.summaryTableTemplate.(tmpField{:}) = [];
end
% Open Synapse Locator GUI!
synapseLocatorGUI(sLobj)
delete(wbH)
else
% Bring Synapse Locator GUI to front!
figure(findobj('Name', 'Synapse Locator'))
end
movegui(findobj('Name', 'Synapse Locator'), 'northwest')
end
function [success, params] = IJ_checker_Fcn(params)
% Look for ImageJ installation!
success = 0;
[filepath_, ~, ~] = fileparts(params.IJ_exe);
if all([exist(filepath_, 'dir'), exist(params.IJ_exe, 'file')])
% disp('That''s fine!')
success = 1;
else
% Try other location!
dialog_title = 'Select ImageJ Program Folder!';
IJ_dir = uigetdir(dialog_title);
if ischar(IJ_dir)
[filepath_, name_, ext_] = fileparts(params.IJ_exe);
if all([exist(filepath_, 'dir'), exist(params.IJ_exe, 'file')])
% Ok, change directory and procede!
params.IJ_exe = fullfile(filepath_, [name_, ext_]);
success = 1;
end
end
end
% Load jars!
if success
% Add jars and plugins!
ImageJ_loader(params.IJ_exe)
end
end