-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper_figure_4.m
247 lines (185 loc) · 7.63 KB
/
paper_figure_4.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
246
247
%% Paper argumentation for fPCA part (figure 2)
% 0. Cut signals in 2 parts dominated by a) Deterministic rise (t = [50 200]) b) Stochastic oscillations (t = [200 650])
% 1. Do fPCA for all ligands at all doses (no inhibitors) for t = [50 200]
% --> PC2vs3 - IGF one axis - BTC other axis - EGF/HGF/HRG inbetween - EPR/FGF not responding
% Plot first 4 harmonics --> argument for choosing PCs 2 and 3
% 2. Visualize this with coloring instead of points for IGF and BTC
% The following points are moved to figure 3
% 3. Subtract mean + first 3 harmonics (plot) from data for t = [200 650]
% --> Histograms for no dose + highest dose with threshold
% cell-to-cell heterogeneity <-> time-courses to show oscillations
% Ligands triggering subpopulation to oscillate; Others don't
% 4. Do same analysis for inhibitor data (EGF and HGF): MEKi induces oscillations; AKTi represses oscillations
% (Counter-intuitive: EGF-MEKi population mean like IGF, oscillations however not suppressed as for IGF)
close all
clear all
clc
remotepath = mypath();
fdaMPath = [remotepath 'fda'];
addpath(fdaMPath)
grabdataPath = [remotepath 'Code + Stage and Outputsignal'];
addpath(grabdataPath)
% Get properties of sites by calling siteprop(site)
% All ligands + EGF with Inhibitors
% sites = [1 2 4:10 17:-1:11 24:30 37:-1:31 41 42 44:50 57:-1:51 64:69];
sites_for_harmonics = [4:10 17:-1:11 24:30 37:-1:31 44:50 57:-1:51 64:69];
sites = sites_for_harmonics;
% sites = [1 4];
times = cell(0);
signals = cell(0);
celltype = [];
for isite = sites
if exist(remotepath,'dir')
[times{end+1},intensity] = grabdata(isite);
else
load(['./Workspaces/site_' num2str(isite)])
times{end+1} = timestamp;
end
log_trafo = 1; % log-transform signal
if log_trafo
signals{end+1} = log10(intensity);
else
signals{end+1} = intensity;
end
celltype = [celltype ones(1,size(intensity,2))*isite];
end
timestamp = times{1}; % same time sampling for all data sets
c_signal = cell2mat(signals);
return
%% Generate spline fits to data-sets given in sites_for_harmonics
% close all
nbasis = 20;
% time_range = [min(timestamp) max(timestamp)];
time_range = [50 200];
[tmp range_ind_min] = min(abs(timestamp - time_range(1)));
[tmp range_ind_max] = min(abs(timestamp - time_range(2)));
range_ind = range_ind_min:range_ind_max;
ind_harm = ismember(celltype,sites_for_harmonics);
ind_fit = ~ind_harm;
basis = create_bspline_basis([timestamp(range_ind(1)) timestamp(range_ind(end))], nbasis);
smoothed_data = smooth_basis(timestamp(range_ind),c_signal(range_ind,ind_harm),basis);
return
f = figure;
set(f,'DefaultAxesColorOrder',jet(size(c_signal(1,ind_harm),2)))
hold on
plot(smoothed_data)
plot(timestamp(range_ind),c_signal(range_ind,ind_harm),'o')
%% Make FPCA with data generated in previous block
% close all
nharm = 4;
% c_signal_pcastr = pca_fd(smoothed_data, nharm);
c_signal_pcastr = pca_fd(smoothed_data, nharm, fdPar(basis, int2Lfd(2), 0), 0); % WITHOUT CENTERING!!
% c_signal_pcastr = varmx_pca(c_signal_pcastr);
return
plot_pca_fd(c_signal_pcastr, 1, 0)
% c_signal_rotpcastr = varmx_pca(c_signal_pcastr);
% plot_pca_fd(c_signal_rotpcastr, 1, 0)
%% Figure 2A: fPCA with dose-dependend colored ligand level
close all
% Define principal components to be plotted
pcs = [2 3];
% angle = 0;
angle = -10; % rotation angle to right [degree]
Rmat = [1 0 0; ...
0 cos(2*pi*angle/360) sin(2*pi*angle/360); ...
0 -sin(2*pi*angle/360) cos(2*pi*angle/360)];
flipharm = ones(1,nharm);
flipharm(1:4) = [-1 1 -1 1];
unitypes = unique(celltype(ind_harm));
site_lig_ind = [];
site_lig_name = {};
site_lig_dose = [];
site_inh_name = {};
site_inh_dose = [];
% Exclude Inhibitor data
for isite = sites_for_harmonics % only plot ligands used for harmonics
s = siteprop(isite);
site_lig_ind = [site_lig_ind s.lig_index];
site_lig_name{end+1} = s.lig_name;
site_lig_dose = [site_lig_dose s.lig_dose];
site_inh_name{end+1} = s.inh_name;
site_inh_dose = [site_inh_dose s.inh_dose];
end
sites_remain = find(~site_inh_dose);
uni_lig = unique(site_lig_ind(sites_remain));
lig_min = min(site_lig_dose(sites_remain));
lig_max = max(site_lig_dose(sites_remain));
ncolor = 201;
colmap = flipud(jet(ncolor));
color_doses = 10.^linspace(max(log10([lig_min 1])),log10(lig_max),ncolor);
rowstocols = 0.3;
nrows = ceil((length(uni_lig)+1)^rowstocols);
ncols = ceil((length(uni_lig)+1) / nrows);
figure
posFig = get(gcf,'Position');
posFig(4) = posFig(4)/2;
set(gcf,'Position',posFig)
set(gcf,'PaperPosition', [0 0 posFig(3) posFig(4)]./15);
flipped_scores = repmat(flipharm,size(c_signal_pcastr.harmscr,1),1).*c_signal_pcastr.harmscr;
for ilig = 1:length(uni_lig)
subplot(nrows,ncols,ilig)
hold on
tmpind = find(site_lig_ind(sites_remain) == uni_lig(ilig));
title(site_lig_name{sites_remain(tmpind(1))})
if ilig == 1
ylabel(['PC ' num2str(pcs(2))])
end
if ilig == length(uni_lig)
xlabel(['PC ' num2str(pcs(1))])
end
x_scores = (Rmat(pcs(1),:) * flipped_scores(:,1:3)')';
y_scores = (Rmat(pcs(2),:) * flipped_scores(:,1:3)')';
plot(x_scores,y_scores,'.','Color',[.7 .7 .7]);
% ind_cells_tmp = ismember(celltype(ind_harm),tmpind);
for isite = tmpind
% Colored
[tmp color_ind] = min(abs(color_doses-site_lig_dose(sites_remain(isite))));
mycolor = colmap(color_ind,:);
% plot(x_scores(celltype(ind_harm) == sites_for_harmonics(sites_remain(isite)),:),y_scores(celltype(ind_harm) == sites_for_harmonics(sites_remain(isite)),:),'.','Color',mycolor);
mycolorhsv = rgb2hsv(mycolor);
mycolorhsv = mycolorhsv(1);
smoothhist2D([x_scores(celltype(ind_harm) == sites_for_harmonics(sites_remain(isite)),:) y_scores(celltype(ind_harm) == sites_for_harmonics(sites_remain(isite)),:)],5,[100 100],.05,'image',mycolorhsv);
hold on
end
set(gca,'XLim',[min(x_scores) max(x_scores)]*1.1)
aspRatioFig = posFig(3)/posFig(4);
posSubplot = get(gca,'Position');
aspRatioSubplot = posSubplot(3)/posSubplot(4);
% set(gca,'YLim',get(gca,'XLim')/(aspRatioFig*aspRatioSubplot)-.03) % PC1 vs PC3
% set(gca,'YLim',get(gca,'XLim')/(aspRatioFig*aspRatioSubplot)+.03) % PC1 vs PC2
end
h = get(gca);
subplot(nrows,ncols,ilig+1)
clim = log10([lig_min lig_max]);
clim(1) = max([clim(1) 0]);
set(gca,'CLim',clim)
colormap(flipud(jet(ncolor)))
colorbar('Location','North','XTick',log10([1 2.5 5 10 20 50 100]),'XTickLabel',[0 2.5 5 10 20 50 100])
set(gca,'Visible','off')
%% Figure 2B: Eigenfunctions (new - rotated)
close all
pcs = 1:3;
rowstocols = 1;
nrows = ceil(nharm^rowstocols);
ncols = ceil(nharm / nrows);
[tmp range_ind_min] = min(abs(timestamp - time_range(1)));
[tmp range_ind_max] = min(abs(timestamp - time_range(2)));
range_ind = range_ind_min:range_ind_max;
times_fine = linspace(timestamp(range_ind(1)),timestamp(range_ind(end)),501);
harm_eval = repmat(flipharm(1:nharm),length(times_fine),1) .* eval_fd(c_signal_pcastr.harmfd,times_fine);
harm_eval_rescale = 2 * repmat(sqrt(c_signal_pcastr.values(1:nharm))',length(times_fine),1) .* harm_eval;
figure
for iplot = 1:nharm
subplot(nrows,ncols,iplot)
if iplot <= length(pcs)
tmpplot = sum(repmat(Rmat(iplot,:),size(harm_eval_rescale,1),1) .* harm_eval_rescale(:,pcs),2);
else
tmpplot = harm_eval_rescale(:,iplot);
end
plot(times_fine,tmpplot)
xlabel(['Harmonic ' num2str(iplot)])
set(gca,'XLim',time_range)
set(gca,'YLim',[min(min(harm_eval_rescale)) max(max(harm_eval_rescale))]*1.2)
hold on
plot(time_range,[0 0],'--')
end