-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLEXY_lambda_dependence.m
170 lines (137 loc) · 5.01 KB
/
LEXY_lambda_dependence.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
% Plot the NLS-mCherry-LEXY export for different excitation wavelength
% Load the dataset
%File directories
FigPath = 'S:\YangJoon\Dropbox\Optogenetics\Figures';
DataPath = 'S:\YangJoon\Dropbox\Optogenetics\WavelengthDependence';
D = dir(DataPath);
% Note. D is a cell, I need to use cell2mat to extract from D
data_compiled = {};
k=1; % counter
for i=3:length(D)
% extract the wavelength from the file name
filename = D(i).name;
lambda = filename(end-2:end);
% define a data structure to extract compilednuclei info.
dataset = struct;
dataset = load([DataPath, filesep, D(i).name, filesep, 'CompiledNuclei.mat']);
% extract key fields for generating plots
MeanFluo = dataset.MeanVectorAll;
SDFluo = dataset.SDVectorAll;
SEFluo = dataset.SDVectorAll./sqrt(dataset.NParticlesAll);
Time = dataset.ElapsedTime;
Frame = 1:length(MeanFluo);
data_compiled(k).wavelength = str2num(lambda);
data_compiled(k).MeanFluo = MeanFluo;
data_compiled(k).SEFluo = SEFluo;
data_compiled(k).Time = Time;
data_compiled(k).Frames = Frame;
k=k+1; % counter count
end
%% generate plots of time traces
colorCode = [];
wavelength = {};
k=1; % counter
hold on
for i= [1,3,5,8,10]%1:length(data_compiled)
% Normalization of the fluorescence intensity is needed
% as the laser power is not controlled in this case.
% We tried with strong enough laser power, to saturate the export.
% color code matching the wavelength
colorCode(i,:) = wavelength2color(data_compiled(i).wavelength + 40*k, 'colorSpace', 'rgb');
% errorbar plot of fluo intensity over time
MaxIntensity = max(data_compiled(i).MeanFluo);
% find the time point where it's the maximum
MaxIndex = find(data_compiled(i).MeanFluo == MaxIntensity);
errorbar(data_compiled(i).Time,...
data_compiled(i).MeanFluo/MaxIntensity,...
data_compiled(i).SEFluo/MaxIntensity)%,...
%'Color',colorCode(i,:))
wavelength{k} = num2str(data_compiled(i).wavelength);
k=k+1;
end
xlim([0 5])
ylim([0 1.2])
xlabel('time (min)')
ylabel('normalized intensity')
xticks([0 1 2 3 4 5])
yticks([0 0.5 1 1.5])
legend(wavelength)
box on
StandardFigure(gcf,gca)
saveas(gcf, [FigPath, filesep, 'NLS-mCherry-LEXY-lambda_dependence_Maxnormalized.pdf'])
%% Test the color coding function
wave = 458:1:670;
hold on
for i=1:length(wave)
colorCode = wavelength2color(wave(i), 'colorSpace', 'rgb')
plot(1:10, (1:10)*i/100,'Color',colorCode)
end
%% plot to check (time window for the fitting)
hold on
for i=1:length(data_compiled)
Time = [];
Fluo = [];
Fluo_SE = [];
Time = data_compiled(i).Time;
Fluo = data_compiled(i).MeanFluo;
Fluo_SE = data_compiled(i).SEFluo;
errorbar(Time, Fluo/(max(Fluo)), Fluo_SE/(max(Fluo)))
% plot(Time, log(Fluo/(max(Fluo))))
%pause
end
%% fitting an exponential decay function to extract the decay constant
for i=1:length(data_compiled)
% extract the useful fields, time and fluo
Time = [];
Fluo = [];
Time = data_compiled(i).Time;
Fluo = data_compiled(i).MeanFluo;
% find the time point where it's the maximum
MaxFluo = max(Fluo(5:end)); % this is because we illuminated from the end of the 5th frame.
if i==10
MaxIndex = 7;
elseif i==3 || i==4 || i==5
MaxIndex = 5;
else
MaxIndex = 6;%find(Fluo == MaxFluo);
end
% normalize the fluo to its maximum
Fluo = Fluo/MaxFluo;
% truncate the data from the maximum fluorescence to focus on the decay
% regime.
Time = Time(MaxIndex:end) - Time(MaxIndex);
Fluo = Fluo(MaxIndex:end);
decay_model = @(params) params(1)*exp(-params(2)*Time) + params(3) - Fluo;
% initial guess for the parameters
params0 = [1, 2, 0.3];
lb = [0, 0, 0];
ub = [2, 10000, 1];
% fitting
[params_fit,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(decay_model, params0, lb, ub);
% calculate the decay constant (2nd parameter) and its STD using the
% 95% confidence interval
CI = nlparci(params_fit,residual,'jacobian',jacobian);
decay_constant_STD = (CI(2,2) - CI(2,1))/2;
data_compiled(i).decay_const = params_fit(2);
data_compiled(i).decay_const_STD = decay_constant_STD;
hold on
plot(Time, Fluo)
plot(Time, params_fit(1)*exp(-params_fit(2)*Time) + params_fit(3))
% pause
end
%% generate plots for the decay constant (k)
wavelength = extractfield(data_compiled,'wavelength');
decay_const = extractfield(data_compiled,'decay_const');
decay_const_STD = extractfield(data_compiled,'decay_const_STD');
errorbar(wavelength, decay_const, decay_const_STD)
xlabel('wavelength (nm)')
ylabel('export rate (1/min)')
xlim([450 550])
xticks([450 475 500 525 550])
yticks([0 1 2 3 4 5])
box on
StandardFigure(gcf, gca)
saveas(gcf, [FigPath, filesep, 'NLS-mCherry-LEXY-lambda_export_rate.pdf'])
%% Save the result into the structure, data_compiled
save([DataPath 'wavelength_dependence.mat'],'data_compiled')