-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeOutputPlots.m
299 lines (234 loc) · 9.37 KB
/
makeOutputPlots.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
function outputStats = makeOutputPlots(vocData,parameters,runBootstrap)
%Makes output plots from vocData structure
%
%
% (C) Gordon J. Berman, 2016
% Emory University
addpath('utilities');
addpath('analysis');
load('saved_colormaps.mat');
if nargin < 2 || isempty(parameters)
parameters = setRunParameters([]);
else
% p = vocData.parameters;
% a = fieldnames(parameters);
% for i=1:length(a)
% p.(a{i}) = parameters.(a{i});
% end
parameters = setRunParameters(parameters);
end
if nargin < 3 || isempty(runBootstrap)
runBootstrap = false;
end
outputStats.parameters = parameters;
fprintf(1,'Calculating Densities\n');
yData = vocData.yData;
sigma = parameters.sigma;
numPoints = parameters.numPoints_density;
maxVal = ceil(3*sigma + max(abs(yData(:)))/5)*5;
[xx,density] = findPointDensity(yData,sigma,numPoints,[-maxVal maxVal]);
outputStats.xx = xx;
outputStats.density = density;
outputStats.numPoints = numPoints;
outputStats.sigma = sigma;
outputStats.maxVal = maxVal;
% figure
% imagesc(xx,xx,density)
% maxDensity = round(max(density(:))*.8/5e-5)*5e-5;
% axis equal tight off xy
% colormap(cc)
% caxis([0 maxDensity]);
% colorbar
% set(gca,'fontsize',14,'fontweight','bold')
% title('Overall Density','fontsize',18,'fontweight','bold')
% drawnow
isSolo = vocData.isSolo;
individuals = unique(vocData.individualNumbers);
numIndividuals = length(individuals);
outputStats.numIndividuals = numIndividuals;
outputStats.individuals = individuals;
individualUrineDensities = zeros(numPoints,numPoints,numIndividuals);
individualFemaleDensities = zeros(numPoints,numPoints,numIndividuals);
numUrineCalls = zeros(numIndividuals,1);
numFemaleCalls = zeros(numIndividuals,1);
for i=1:numIndividuals
temp = yData(isSolo & vocData.individualNumbers == individuals(i),:);
numUrineCalls(i) = length(temp(:,1));
if ~isempty(temp)
[~,individualUrineDensities(:,:,i)] = ...
findPointDensity(temp,sigma,numPoints,[-maxVal maxVal]);
end
temp = yData(~isSolo & vocData.individualNumbers == individuals(i),:);
numFemaleCalls(i) = length(temp(:,1));
if ~isempty(temp)
[~,individualFemaleDensities(:,:,i)] = ...
findPointDensity(temp,sigma,numPoints,[-maxVal maxVal]);
end
end
outputStats.individualUrineDensities = individualUrineDensities(:,:,numUrineCalls>0);
outputStats.individualFemaleDensities = individualFemaleDensities(:,:,numFemaleCalls>0);
outputStats.numUrineCalls = numUrineCalls(numUrineCalls>0);
outputStats.numFemaleCalls = numFemaleCalls(numFemaleCalls>0);
outputStats.median_female_density = median(individualFemaleDensities,3);
outputStats.median_urine_density = median(individualUrineDensities,3);
outputStats.mean_female_density = mean(individualFemaleDensities,3);
outputStats.mean_urine_density = mean(individualUrineDensities,3);
fprintf(1,'Finding Significant Regions\n');
A = -density.*log2(density);
entropy = sum(A(~isnan(A) & ~isinf(A)))*(xx(2)-xx(1))^2;
numComparisons = round(2^entropy);
alpha = 1 - (1-parameters.sigAlpha)^(1/numComparisons);
outputStats.alpha = alpha;
outputStats.entropy = entropy;
outputStats.numComparisons = numComparisons;
outputStats.sigAlpha = parameters.sigAlpha;
outputStats.minDensity = parameters.minDensity;
[ii,jj] = find(density > outputStats.minDensity);
rankSumPValues = zeros(numPoints,numPoints);
rankSumPValues(~(density > outputStats.minDensity)) = 1;
temp = zeros(size(ii));
for i=1:length(ii)
temp(i) = ranksum(squeeze(individualUrineDensities(ii(i),jj(i),:)),...
squeeze(individualFemaleDensities(ii(i),jj(i),:)));
end
rankSumPValues(density > outputStats.minDensity) = temp;
clear temp
outputStats.rankSumPValues = rankSumPValues;
outputStats.significanceMap = rankSumPValues < alpha;
regions = bwlabel(outputStats.significanceMap);
outputStats.region = regions;
B = bwboundaries(density > parameters.minDensity);
a = max(max(outputStats.median_female_density(:)),max(outputStats.mean_urine_density(:)));
maxDensity = round(a*.75/5e-5)*5e-5;
figure
subplot(1,3,1)
imagesc(xx,xx,outputStats.mean_urine_density)
axis equal tight off xy
colormap(cc)
caxis([0 maxDensity]);
hold on
plot(xx(B{1}(:,2)),xx(B{1}(:,1)),'k-','linewidth',3)
set(gca,'fontsize',14,'fontweight','bold')
title('Urine-Elicited','fontsize',16,'fontweight','bold')
freezeColors
subplot(1,3,2)
imagesc(xx,xx, outputStats.mean_female_density)
axis equal tight off xy
colormap(cc)
caxis([0 maxDensity]);
hold on
plot(xx(B{1}(:,2)),xx(B{1}(:,1)),'k-','linewidth',3)
set(gca,'fontsize',14,'fontweight','bold')
title('Female-Elicited','fontsize',16,'fontweight','bold')
freezeColors
subplot(1,3,3)
imagesc(xx,xx, outputStats.mean_female_density - outputStats.mean_urine_density)
axis equal tight off xy
colormap(cc2)
caxis([-maxDensity maxDensity]);
colorbar
hold on
plot(xx(B{1}(:,2)),xx(B{1}(:,1)),'k-','linewidth',3)
if sum(regions(:)) > 0
for i=1:max(regions(:))
BB = bwboundaries(regions == i);
if ~isempty(BB)
plot(xx(BB{1}(:,2)),xx(BB{1}(:,1)),'k-','linewidth',2)
end
end
end
set(gca,'fontsize',14,'fontweight','bold')
title('Difference','fontsize',16,'fontweight','bold')
freezeColors
drawnow
figure
imagesc(xx,xx,-log10(1 - (1 - rankSumPValues).^numComparisons));
axis equal tight off xy
hold on
plot(xx(B{1}(:,2)),xx(B{1}(:,1)),'k-','linewidth',3)
colorbar
set(gca,'fontsize',14,'fontweight','bold');
title('-log_{10} Effective p-Value','fontsize',16,'fontweight','bold');
colormap(cc)
caxis([0 3]);
fprintf('Finding Watershed Regions\n');
L = watershed(-density,8);
LL = L;
LL(density < parameters.minDensity) = 0;
a = setdiff(unique(LL),0);
for i=1:length(a)
LL(LL == a(i)) = i;
end
outputStats.watershedMap = LL;
outputStats.numRegions = max(LL(:));
figure
subplot(1,2,1)
imagesc(xx,xx,density)
axis equal tight off xy
maxDensity = round(max(density(:))*.8/5e-5)*5e-5;
caxis([0 maxDensity]);
subplot(1,2,2)
imagesc(xx,xx,LL)
hold on
axis equal tight off xy
colormap(cc)
title('Watershed Region Map','fontsize',16,'fontweight','bold')
peakPoints = findPeakPoints(LL,density,xx);
for i=1:outputStats.numRegions
idx = LL == i;
BB = bwboundaries(idx);
for j=1:2
subplot(1,2,j)
hold on
plot(xx(BB{1}(:,2)),xx(BB{1}(:,1)),'k-','linewidth',2)
end
[ii,jj] = find(idx);
x = median(xx(jj));
y = median(xx(ii));
text(x,y,num2str(i),...
'backgroundcolor','k','fontweight','bold','color','w');
end
drawnow
watershedRegions = findWatershedRegions(yData,LL,xx,peakPoints);
bins = parameters.template_bins;
yrange = parameters.template_yaxis;
templatePlotDimensions = parameters.templatePlotDimensions;
colorAxis = parameters.template_caxis;
a = vocData.inTrainingSet;
plotTemplateHistograms(vocData.normalizedVocs(a,:),watershedRegions(a),bins,...
yrange,templatePlotDimensions,colorAxis);
drawnow
outputStats.watershedRegions = watershedRegions;
if runBootstrap
numBootstraps = parameters.numBootstrap;
xx_boot = linspace(xx(1),xx(end),parameters.numPoints_boot);
[probs,densities1,densities2] = ...
runPairwiseBootstrap(yData,isSolo,numBootstraps,...
xx_boot,sigma,parameters.minDensity,parameters);
regions_boot = bwlabel(min(probs,1-probs) < alpha);
outputStats.probs_bootstrap = probs;
outputStats.significance_probs_bootstrap = min(probs,1-probs);
outputStats.bootstrap_densities_urine = densities1;
outputStats.bootstrap_densities_female = densities2;
outputStats.regions_boot = regions_boot;
figure
imagesc(xx_boot,xx_boot, outputStats.mean_female_density - outputStats.mean_urine_density)
axis equal tight off xy
colormap(cc2)
caxis([-maxDensity maxDensity]);
colorbar
hold on
plot(xx(B{1}(:,2)),xx(B{1}(:,1)),'k-','linewidth',3);
if sum(regions_boot(:)) > 0
for i=1:max(regions_boot(:))
BB = bwboundaries(regions_boot == i);
if ~isempty(BB)
plot(xx_boot(BB{1}(:,2)),xx_boot(BB{1}(:,1)),'k-','linewidth',2)
end
end
end
set(gca,'fontsize',14,'fontweight','bold')
title('Difference','fontsize',16,'fontweight','bold')
freezeColors
drawnow
end