-
Notifications
You must be signed in to change notification settings - Fork 0
/
FluorologArray.m
245 lines (155 loc) · 6.03 KB
/
FluorologArray.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
classdef FluorologArray < handle
properties
data
conc
bndFrac
kd
b_max
ubnds
bnds
end
methods
function this = FluorologArray(varargin)
n = length(varargin);
flag = true;
for i = 1 : n
if ~ isa(varargin{i}, 'Fluorolog')
flag = false;
end
end
if ~ flag
error('All input arguments must be of class Fluorolog.');
else
this.data = cell(1, n);
this.data = varargin;
end
end
% basic operations
function this = push(this, fluorolog, index)
if nargin == 2 || isempty(index)
index = this.length + 1;
end
newdata = cell(1, this.length + 1);
sel = true(1, this.length + 1);
sel(index) = false;
newdata(sel) = this.data;
newdata{index} = fluorolog;
this.data = newdata;
end
function addUbnd(this, ubnd)
this.ubnds = [this.ubnds, ubnd];
end
function addBnd(this, bnd)
this.bnds = [this.bnds, bnd];
end
function unbound = unbound(this)
unbound = mean(this.ubnds, 2);
end
% fitting
function fitBoundFractions(this)
bnd = this.meanBnd();
ubnd = this.meanUbnd();
fracs = zeros(1, this.length);
for i = 1 : this.length
fracs(i) = Fluorolog.linearCombination(this.data{i}.spectra(:, 1), ubnd, bnd);
end
this.bndFrac = fracs;
end
function fitKd(this)
[this.kd, this.b_max] = Fluorolog.oneSiteSpecificFit(this.conc, this.bndFrac);
end
% utility
function n = length(this)
n = length(this.data);
end
function bnd = meanBnd(this)
bnd = mean(this.bnds, 2);
end
function ubnd = meanUbnd(this)
ubnd = mean(this.ubnds, 2);
end
function wl = wl(this, n)
wl = this.data{1}.wl;
if nargin == 2
wl = wl(n);
end
end
% plotting
function overlay(this)
this.plotFluorologArray(this.data);
end
function plotKdFit(this)
figure;
plot(this.conc, this.bndFrac * this.b_max, 's', 'markersize', 12, 'linewidth', 2.4);
hold on;
fineConc = linspace(min(this.conc), max(this.conc), 100);
fineBoundFrac = fineConc ./ (fineConc + this.kd);
plot(fineConc, fineBoundFrac, '-', 'linewidth', 2.4);
xlabel('Concentration', 'fontsize', 16);
ylabel('Bound Fraction', 'fontsize', 16);
title(['Kd = ', num2str(this.kd)]);
set(gca, 'fontsize', 14, 'ylim', [0 1], 'ytick', [0 0.5 1]);
end
function compareUbndBnd(this)
ax = this.plotSpectrum(this.wl, this.meanUbnd);
hold(ax, 'on');
this.plotSpectrum(this.wl, this.meanBnd, ax);
hold(ax, 'off');
legend(ax, {'Unbound', 'Bound'});
end
end
methods (Static)
% plot
function plotFluorologArray(arr, ax)
if nargin == 1 || isempty(ax)
figure;
ax = gca;
end
hold(ax, 'on');
legends = cell(1, length(arr));
for i = 1 : length(arr)
legends{i} = num2str(i);
plot(ax, arr{i}.wl, arr{i}.spectra(:, 1), FluorologArray.lineSpec(i), 'linewidth', 2, 'markersize', 8);
end
hold(ax, 'off');
xlabel(ax, 'Wavelength (nm)', 'fontsize', 16);
ylabel(ax, 'Fluorescence Intensity (a.u.)', 'fontsize', 16);
legend(ax, legends);
set(ax,'fontsize', 14);
end
function ax = plotSpectrum(wl, spec, ax)
if nargin == 2 || isempty(ax)
figure;
ax = gca;
end
plot(ax, wl, spec, 'linewidth', 2, 'markersize', 8);
xlabel(ax, 'Wavelength (nm)', 'fontsize', 16);
ylabel(ax, 'Fluorescence Intensity (a.u.)', 'fontsize', 16);
set(ax,'fontsize', 14);
end
% utility
function spec = lineSpec(n)
cs = FluorologArray.colors;
ss = FluorologArray.symbols;
colorInd = mod(n, length(cs));
symbolInd = floor(n / length(cs)) + 1;
color = FluorologArray.cycle(colorInd, cs);
symbol = FluorologArray.cycle(symbolInd, ss);
spec = [color, symbol];
end
function elem = cycle(n, array)
ind = mod(n, length(array));
if ind == 0
ind = length(array);
end
elem = array(ind);
end
% constants
function colors = colors
colors = 'kbrmcgy';
end
function symbols = symbols
symbols = 'os^vd><ph';
end
end
end