-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 20.2 KB
/
.Rhistory
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
geom_point(data=williamette, aes(PC1, PC2), color="red")
# Inspect samples with large difference
outliers<- lat_pred %>% filter(Diff> 2) %>% pull(Geno)
# Find outliers
outliers<- samples %>% filter(Geno %in% outliers)
outliers
williamette
williamette %>% filter(grepl('GW', Geno))
williamette %>% filter(!grepl('GW', Geno))
nonGW_will<- williamette %>% filter(!grepl('GW', Geno))
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red")
GW_will<- williamette %>% filter(grepl('GW', Geno))
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red") +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue")
?geom_point
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red", show.legend = T) +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue", show.legend = T)
?aes
### Plot faceted scatter for all GW river systems
gw_samples<- samples %>% filter(grepl("GW", Geno))
head(gw_samples)
unique(gw_samples$River)
unique(samples$River)
gw_samples %>% pull(River) %>% distinct()
gw_samples %>% pull(River) %>% unique()
rivers<- samples %>% filter(River %in% gw_rivers)
gw_rivers<- gw_samples %>% pull(River) %>% unique()
rivers<- samples %>% filter(River %in% gw_rivers)
head(rivers)
# Save dataframe
write.table(samples, "../data/meta_pca_1254.csv", sep="\t", quote = F, row.names = F)
rivers$'GW Sample'<- FALSE
head(rivers)
rivers %>% filter(grepl("GW", Geno)) <- TRUE
filter(rivers, grepl("GW", Geno)) <- TRUE
rivers<- filter(rivers, grepl("GW", Geno)) %>% mutate('GW Sample'= TRUE)
head(rivers)
?mutate
rivers<- samples %>% filter(River %in% gw_rivers)
rivers$'GW Sample'<- FALSE
rivers<- filter(rivers, grepl("GW", Geno)) %>% mutate('GW Sample'= TRUE, .keep='all')
?grepl
grepl("GW", rivers$Geno)
rivers<- samples %>% filter(River %in% gw_rivers)
rivers$'GW Sample'<- FALSE
grepl("GW", rivers$Geno)
rivers$'GW Sample'<- grepl("GW", rivers$Geno)
head(rivers)
tail(rivers)
# Faceted Plot
rivers %>% ggplot(aes(PC1, PC2, color= 'GW Sample')) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
facet_grid(River)
# Faceted Plot
rivers %>% ggplot(aes(PC1, PC2, color= 'GW Sample')) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
facet_grid("River")
# Faceted Plot
rivers %>% ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
facet_grid("River")
?facet_grid
# Faceted Plot
rivers %>% ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
facet_grid(cols="River")
# Faceted Plot
rivers %>% ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
facet_grid(cols=River)
# Faceted Plot
rivers %>% filter(River == "Columbia") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Cowlitz") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Nisqually") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Nooksack") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Olympic Penninsula") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Pullyallup") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
gw_rivers
# Faceted Plot
rivers %>% filter(River == "Skagit") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Snoqualmie") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Faceted Plot
rivers %>% filter(River == "Willamette") %>%
ggplot(aes(PC1, PC2, color= `GW Sample`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
?geom_point
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="point"), color="red", show.legend = T) +
geom_point(data=GW_will, aes(PC1, PC2, color="point"), color="skyblue", show.legend = T)
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="False"), color="red", show.legend = T) +
geom_point(data=GW_will, aes(PC1, PC2, color="True"), color="skyblue", show.legend = T) +
scale_color_manual(name = "GW Samples", values = "black") +
### Plot faceted scatter for all GW river systems
# Isolate river systems of interest
gw_samples<- samples %>% filter(grepl("GW", Geno))
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="False"), color="red", show.legend = T) +
geom_point(data=GW_will, aes(PC1, PC2, color="True"), color="skyblue", show.legend = T) +
scale_color_manual(name = "GW Samples", values = "black")
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="False"), color="red", show.legend = T) +
geom_point(data=GW_will, aes(PC1, PC2, color="True"), color="skyblue", show.legend = T) +
scale_color_manual(name = "GW Samples", values = "black")
# PLot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="False"), color="red") +
geom_point(data=GW_will, aes(PC1, PC2, color="True"), color="skyblue") +
scale_color_manual(name = "GW Samples", values = "black")
# Inspect samples with large difference
outliers<- lat_pred %>% filter(Diff> 2) %>% pull(Geno)
outliers
# Find outliers
outliers<- samples %>% filter(Geno %in% outliers)
outliers
lat_pred %>% filter(Geno == "GW-9760")
rivers
gw_rivers
# Inspect samples with large difference
outliers<- lat_pred %>% filter(Diff> 2) %>% pull(Geno)
?ifelse
outmarked<- samples %>% mutate(Outlier= if_else(Geno %in% outliers, TRUE, FALSE))
head(outmarked)
unique(outmarked$Outlier)
# Visualize PCA
# Faceted Plot
outmarked %>%
ggplot(aes(PC1, PC2, color= `Outlier`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Zoom in on outlier PCA coordinates
xmin<- outmarked %>% filter(Outlier) %>% select(PC1)
xmin
# Zoom in on outlier PCA coordinates
xmin<- outmarked %>% filter(Outlier) %>% select(PC1) %>% min()
xmin
xmax<- outmarked %>% filter(Outlier) %>% select(PC1) %>% max()
ymin<-outmarked %>% filter(Outlier) %>% select(PC2) %>% min()
ymax<- outmarked %>% filter(Outlier) %>% select(PC2) %>% max()
outmarked %>%
ggplot(aes(PC1, PC2, color= `Outlier`)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
outmarked %>%
ggplot(aes(PC1, PC2, color= Latitude)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
outmarked
outmarked %>% filter(River=="Willamette") %>%
ggplot(aes(PC1, PC2, color= Latitude)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
outmarked %>% filter(River=="Willamette") %>%
ggplot(aes(PC1, PC2, color= Outlier)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2, color="False"), color="red") +
geom_point(data=GW_will, aes(PC1, PC2, color="True"), color="skyblue")
GW_will
# Zoom in on outlier PCA coordinates
xmin<- GW_will %>% select(PC1) %>% min()
xmax<- GW_will %>% select(PC1) %>% max()
ymin<-GW_will %>% select(PC2) %>% min()
ymax<- GW_will %>% select(PC2) %>% max()
out_region<- samples %>% filter(PC1 > xmin & PC1< xmax & PC2>ymin & PC2<ymax)
out_region
out_region %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
unique(out_region$River)
out_region %>%
ggplot(aes(PC1, PC2, color=River)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
out_region<- samples %>% filter((PC1 > xmin & PC1< xmax & PC2>ymin & PC2<ymax) | River=="Willamette")
out_region %>%
ggplot(aes(PC1, PC2, color=River)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ylim(ymin, ymax) +
xlim(xmin, xmax) +
ggtitle("WGS PCA", subtitle="GW-tagged Samples")
out_region
out_region %>% group_by(River) %>% summarise(avg_lat= mean(Latitude), avg_long= mean(Longitude))
out_region %>% group_by(River) %>% summarise(avg_lat= mean(Latitude), avg_long= mean(Longitude)) %>% arrange(avg_lat)
if_else
?if_else
out_region %>% mutate(River= if_else(River=="Willamette" & grepl('GW', Geno), 'GW_Willamette', River))
out_region<- out_region %>% mutate(River= if_else(River=="Willamette" & grepl('GW', Geno), 'GW_Willamette', River))
unique(out_region$River)
out_region %>% group_by(River) %>% summarise(avg_lat= mean(Latitude), avg_long= mean(Longitude)) %>% arrange(avg_lat)
# Do predicted latitude labels more accurately reflect PCA clustering?
out_region %>% filter(River=="GW_Willamette")
# Do predicted latitude labels more accurately reflect PCA clustering?
out_region %>% filter(River=="GW_Willamette") %>% pull(Geno)
# Do predicted latitude labels more accurately reflect PCA clustering?
gw_will_id<- out_region %>% filter(River=="GW_Willamette") %>% pull(Geno)
lat_pred %>% filter(Geno %in% gw_will_id)
lat_pred %>% filter(Geno %in% gw_will_id) %>% summarise(avg_lat= mean(Prediction))
# Look at table summary of gps coordinates
out_region %>% group_by(River) %>% summarise(avg_lat= mean(Latitude), avg_long= mean(Longitude)) %>% arrange(avg_lat)
# Look at table summary of gps coordinates
out_region %>% group_by(River) %>% summarise(avg_lat= mean(Latitude), avg_long= mean(Longitude)) %>% arrange(avg_lat, avg_long)
lat_pred %>% filter(Geno %in% gw_will_id) %>% summarise(avg_lat= mean(Prediction))
out_region %>% filter(River %in% c("Skykomish", "Puyallup", "Skagit", "Nisqually"))
# Define new neighbors
new_neighbors<- out_region %>% filter(River %in% c("Skykomish", "Puyallup", "Skagit", "Nisqually")) %>% pull(Geno)
# Define new neighbors
new_neighbors<- out_region %>% filter(River %in% c("Skykomish", "Puyallup", "Skagit", "Nisqually", "Yakima")) %>% pull(Geno)
# Define new neighbors
new_neighbors<- out_region %>% filter(River %in% c("Skykomish", "Puyallup", "Skagit", "Nisqually", "Yakima")) %>% pull(Geno)
newNeigh<- samples %>% filter(Geno %in% new_neighbors)
newNeigh
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red") +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue") +
geom_point(data=newNeigh, aes(PC1, PC2), color="lightgreen")
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette GW-tagged Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red") +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue") +
geom_point(data=newNeigh, aes(PC1, PC2), color="lightgreen3")
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red") +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue") +
geom_point(data=newNeigh, aes(PC1, PC2), color="lightgreen3")
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette Samples") +
geom_point(data=nonGW_will, aes(PC1, PC2), color="red") +
geom_point(data=GW_will, aes(PC1, PC2), color="skyblue") +
geom_point(data=newNeigh, aes(PC1, PC2), color="lightgreen")
# Load data and compute difference
lat_pred<- read.csv("predict_GW/predicted_known_aligned.csv")
lat_pred <- lat_pred %>% mutate(Diff= abs(Prediction - Metadata)) %>% arrange(desc(Diff))
# Summarize distributions
lat_pred %>% summary()
# Faceted view of both latitude types
lat_pred %>% pivot_longer(cols = c(Prediction, Metadata), names_to= "Type", values_to= "Latitude" ) %>%
ggplot(aes(Latitude)) + geom_histogram(binwidth = 0.05, fill="skyblue") + facet_grid("Type") + ylab("Count") +
ggtitle("Latitude Distributions for Two Label Types")
?ggtitle
# Faceted view of both latitude types
lat_pred %>% pivot_longer(cols = c(Prediction, Metadata), names_to= "Type", values_to= "Latitude" ) %>%
ggplot(aes(Latitude)) + geom_histogram(binwidth = 0.05, fill="skyblue") + facet_grid("Type") + ylab("Count") +
ggtitle("Latitude Distributions for Two Label Types", subtitle= "Predicted for High Confidence Labels")
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Abs. Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences") +
geom_vline(xintercept=0.5785)
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Abs. Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences") +
geom_vline(xintercept=0.2401510)
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Abs. Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="High Confidence Labels") +
geom_vline(xintercept=0.2401510)
# Inspect samples with large difference
outliers<- lat_pred %>% filter(Diff> 1) %>% pull(Geno)
# Load PCA obj
pca<- readRDS("../../bio_findings/data/aug2021/pca/pca_noInland.RDS")
# Inspect PC %
pc.percent <- pca$varprop*100
# Create df for plotting pca
tab <- data.frame(Geno = pca$sample.id,
PC1 = pca$eigenvect[,1],
PC2 = pca$eigenvect[,2],
PC3 = pca$eigenvect[,3],
PC4 = pca$eigenvect[,4],
PC5 = pca$eigenvect[,5],
stringsAsFactors = FALSE)
# Load meta data
meta<- readRDS("../../bio_findings/data/aug2021/5class_noInland.RDS")
samples<- meta %>%
select(Geno, Latitude, Longitude, River, Class)
# Merge classes and meta
samples<- inner_join(meta, tab)
outliers
# Find outliers
outliers<- samples %>% filter(Geno %in% outliers)
outliers
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="Willamette Samples") +
geom_point(data=outliers, aes(PC1, PC2), color="red") #+
# Plot PC
samples %>%
ggplot(aes(PC1, PC2)) +
geom_point() +
ylab("PC2 (1.1% Var Explained)") +
xlab("PC1 (2.5% Var Explained)") +
ggtitle("WGS PCA", subtitle="High Confidence Label Outliers") +
geom_point(data=outliers, aes(PC1, PC2), color="red") #+
# Faceted view of both latitude types
lat_pred %>% pivot_longer(cols = c(Prediction, Metadata), names_to= "Type", values_to= "Latitude" ) %>%
ggplot(aes(Latitude)) + geom_histogram(binwidth = 0.05, fill="skyblue") + facet_grid("Type") + ylab("Count") +
ggtitle("Latitude Distributions for Two Label Types", subtitle= "Predicted for High Confidence Labels")
# Load data and compute difference
lat_pred<- read.csv("predict_GW/predicted_known_aligned.csv")
lat_pred <- lat_pred %>% mutate(Diff= Prediction - Metadata) %>% arrange(desc(Diff))
# Summarize distributions
lat_pred %>% summary()
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Abs. Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="High Confidence Labels") +
geom_vline(xintercept=0.2401510)
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="High Confidence Labels") +
geom_vline(xintercept=0.09)
# Summarize distributions
lat_pred %>% filter(Diff> -1 & Diff < 1) %>% summary()
# Load data and compute difference
lat_pred<- read.csv("predict_GW/predicted_GW_aligned.csv")
lat_pred <- lat_pred %>% mutate(Diff= Prediction - Metadata) %>% arrange(desc(Diff))
# Faceted view of both latitude types
lat_pred %>% pivot_longer(cols = c(Prediction, Metadata), names_to= "Type", values_to= "Latitude" ) %>%
ggplot(aes(Latitude)) + geom_histogram(binwidth = 0.05, fill="skyblue") + facet_grid("Type") + ylab("Count") +
ggtitle("Latitude Distributions for Two Label Types", subtitle= "Predicted for High Confidence Labels")
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="High Confidence Labels") +
geom_vline(xintercept=0.09)
# Summarize distributions
lat_pred %>% summary()
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="High Confidence Labels") +
geom_vline(xintercept=0.41)
# Visualize difference
lat_pred %>% ggplot(aes(Diff)) + geom_histogram(binwidth=0.05, fill="red3") + ylab("Count") +
xlab("Difference between Prediction and Existing Label") + ggtitle("Distribution of Differences", subtitle="GW Labels") +
geom_vline(xintercept=0.41)
# Summarize distributions
lat_pred %>% filter(Diff> -2 & Diff < 2) %>%summary()
# Summarize distributions
lat_pred %>% filter(Diff> -1 & Diff < 1) %>%summary()