-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
2028 lines (1891 loc) · 66.2 KB
/
README.Rmd
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Plots and Scripts for: Many purported pseudogenes in bacterial genomes are bonafide genes"
author:
- Nicholas P. Cooley, Department of Biomedical Informatics, University of Pittsburgh
date: "`r Sys.Date()`"
output:
github_document: default
html_document: default
knit: (function(inputFile, encoding) {
rmarkdown::render(inputFile,
encoding = encoding,
output_format = "all")
})
---
# Pseudogenes!
This github repo contains data and scripts necessary to recreate the plots present in the manuscript **Many purported pseudogenes in bacterial genomes are bonafide genes**. The data present in this repo are mostly lightweight summary tables capable of fitting within github size restrictions. Scripts used to generate large initial data sets on the Open Science Grid are present in the `OSG_Jobs` folder, while the data sets generated from those jobs have been deposited on zenodo under the following DOIs:
* [10.5281/zenodo.8360505](https://zenodo.org/record/8360505) - Assemblies generated Figure 3 in this repo.
* [10.5281/zenodo.8361514](https://zenodo.org/record/8361514) - Annotations and parsed data for Figure 3 in this repo.
* [10.5281/zenodo.8356318](https://zenodo.org/record/8356318) - Summary data that is too large for github, but necessary to knit this README and it's associated figures, enumerated in the `.gitignore` file for this repo.
* [10.5281/zenodo.8366931](https://zenodo.org/record/8366931) - Assemblies generated for Figure 4 in this repo.
* [10.5281/zenodo.8378433](https://zenodo.org/record/8378433) - Annotations and parsed data for Figure 4 in this repo, as well as assemblies annotations and parsed data for Figure 5 in this repo.
* [10.5281/zenodo.10621232](https://zenodo.org/records/10621233) - Assemblies, annotations and comparison data used in the generation of figure 6.
* [10.5281/zenodo.10622275](https://zenodo.org/records/10622276) - Assemblies and raw assembly data, part 1.
* [10.5281/zenodo.10625339](https://zenodo.org/records/10625340) - Assemblies and raw assembly data, part 2.
Pseudogenizations due to internal stops or frameshifts can represent one of at least three separate phenomena in assembled genomes, 1) recent evolutionary changes that can serve as an observational marker of how pressure is affecting functions and tools within a genome, 2) an error introduced into an assembly via error modes inherent to the sequencing platform or the assembly process, or 3) an inaccurate annotation of a programmed frameshift or non-canonical amino acid inclusion in lieu of a stop codon. Without confirmation such as Sanger sequencing, it can be unclear which of these options any individual pseudogene actually represents. The wide variety of platform and assembler choices available to data submitters additionally introduces the possibility for stochasticity in the rates at which pseudogenes are `TRUE` or `FALSE` depending on the combination of choices made in data collection and generation.
It would take an enormous effort to wholesale Sanger sequence even a modest number of the pseudogenes present in RefSeq or Genbank. It is not even clear that that type of experiment is necessary. However, some interrogations of the diverse data present in RefSeq, GenBank, and the SRA are possible and potentially useful. Metadata can be scraped from the SRA and we can generate direct observations of how relative counts of pseudogenes are related to extractable pieces of data, such as reported assembler, platforms (sequencing technology) for available SRA runs, submission year, reported assembly status, contig N50 over total length, and genus. These direct observations can be coupled with causal inference via Tetrad to predict causal links between metadata categories and relative pseudogene counts.
We can additionally reassemble available reads under a variety of conditions, and assemble reads simulated under varying coverages and qualities to interrogate factors that can affect the pseudogene content of finished assemblies.
PNGs of the manuscript figures are embedded in this document below, while better quality PDFs are included in the the `README_files/figure-gfm/` folder of this repo.
```{r libraries, include = TRUE, echo = FALSE}
# Libraries
suppressMessages(library(knitr))
suppressMessages(library(SynExtend))
suppressMessages(library(magick))
suppressMessages(library(pdftools))
suppressMessages(library(VennDiagram))
suppressMessages(library(igraph))
suppressMessages(library(plotrix))
# suppressMessages(library(kableExtra))
# Sasha's distinct colors, hexcodes,
# from:
# https://sashamaps.net/docs/resources/20-colors/
ColVec1 <- c('#e6194B', '#3cb44b', '#ffe119', '#4363d8', '#f58231', '#42d4f4', '#f032e6', '#fabed4', '#469990', '#dcbeff', '#9A6324', '#fffac8', '#800000', '#aaffc3', '#000075', '#a9a9a9', '#ffffff', '#000000')
ColVec2 <- paste0(ColVec1,
"33")
ColVec3 <- paste0(ColVec1,
"15")
```
```{r options, include = TRUE, echo = FALSE}
# chunk options
opts_chunk$set(eval = TRUE,
comment = "#",
fig.align = "center",
# out.width = "100%",
dev = c("png", "pdf"))
```
```{r adhoc functions, include = TRUE, echo = FALSE}
# adhoc VennDiagram function:
# hack apart and rebuild the venn diagram functions to not use grobs
# and GG plot
AdHocVenn <- function(InputList,
sigdigs = 2L,
ReturnFile = NULL,
PARSET = c(4,3,2,0.75),
SHADECOLS = NULL) {
A <- InputList[[1]]
B <- InputList[[2]]
C <- InputList[[3]]
D <- InputList[[4]]
list_names <- names(InputList)
n12 <- intersect(A, B)
n13 <- intersect(A, C)
n14 <- intersect(A, D)
n23 <- intersect(B, C)
n24 <- intersect(B, D)
n34 <- intersect(C, D)
n123 <- intersect(n12, C)
n124 <- intersect(n12, D)
n134 <- intersect(n13, D)
n234 <- intersect(n23, D)
n1234 <- intersect(n123, D)
area1 <- length(A)
area2 <- length(B)
area3 <- length(C)
area4 <- length(D)
arean12 <- length(n12)
arean13 <- length(n13)
arean14 <- length(n14)
arean23 <- length(n23)
arean24 <- length(n24)
arean34 <- length(n34)
arean123 <- length(n123)
arean124 <- length(n124)
arean134 <- length(n134)
arean234 <- length(n234)
arean1234 <- length(n1234)
a6 <- arean1234
a12 <- arean123 - a6
a11 <- arean124 - a6
a5 <- arean134 - a6
a7 <- arean234 - a6
a15 <- arean12 - a6 - a11 - a12
a4 <- arean13 - a6 - a5 - a12
a10 <- arean14 - a6 - a5 - a11
a13 <- arean23 - a6 - a7 - a12
a8 <- arean24 - a6 - a7 - a11
a2 <- arean34 - a6 - a5 - a7
a9 <- area1 - a4 - a5 - a6 - a10 - a11 - a12 - a15
a14 <- area2 - a6 - a7 - a8 - a11 - a12 - a13 - a15
a1 <- area3 - a2 - a4 - a5 - a6 - a7 - a12 - a13
a3 <- area4 - a2 - a5 - a6 - a7 - a8 - a10 - a11
ellipse_positions <- matrix(nrow = 4,
ncol = 7)
colnames(ellipse_positions) <- c('x',
'y',
'a',
'b',
'rotation',
'fill.mapping',
'line.mapping')
ellipse_positions[1,] <- c(0.65, 0.47, 0.35, 0.20, 45, 2, 2)
ellipse_positions[2,] <- c(0.35, 0.47, 0.35, 0.20, 135, 1, 1)
ellipse_positions[3,] <- c(0.50, 0.57, 0.33, 0.15, 45, 4, 4)
ellipse_positions[4,] <- c(0.50, 0.57, 0.35, 0.15, 135, 3, 3)
Poly_Set <- vector(mode = "list",
length = nrow(ellipse_positions))
for (m1 in seq_len(nrow(ellipse_positions))) {
Poly_Set[[m1]] <- VennDiagram::ell2poly(x = ellipse_positions[m1, 1L],
y = ellipse_positions[m1, 2L],
a = ellipse_positions[m1, 3L],
b = ellipse_positions[m1, 4L],
rotation = ellipse_positions[m1, 5L],
n.sides = 3000L)
}
# create the labels
label_matrix <- matrix(nrow = 15,
ncol = 3)
colnames(label_matrix) <- c('label', 'x', 'y');
label_matrix[1, ] <- c(a1, 0.350, 0.77)
label_matrix[2, ] <- c(a2, 0.500, 0.69)
label_matrix[3, ] <- c(a3, 0.650, 0.77)
label_matrix[4, ] <- c(a4, 0.310, 0.67)
label_matrix[5, ] <- c(a5, 0.400, 0.58)
label_matrix[6, ] <- c(a6, 0.500, 0.47)
label_matrix[7, ] <- c(a7, 0.600, 0.58)
label_matrix[8, ] <- c(a8, 0.690, 0.67)
label_matrix[9, ] <- c(a9, 0.180, 0.58)
label_matrix[10, ] <- c(a10, 0.320, 0.42)
label_matrix[11, ] <- c(a11, 0.425, 0.38)
label_matrix[12, ] <- c(a12, 0.575, 0.38)
label_matrix[13, ] <- c(a13, 0.680, 0.42)
label_matrix[14, ] <- c(a14, 0.820, 0.58)
label_matrix[15, ] <- c(a15, 0.500, 0.28)
# processedLabels <- paste(signif(label_matrix[, 'label'] / sum(label_matrix[, 'label']) * 100,
# digits = sigdigs),
# '%',
# sep='')
processedLabels <- paste0(formatC(x = label_matrix[, 'label'] / sum(label_matrix[, 'label']) * 100,
digits = sigdigs,
format = "f"),
"%")
# print(processedLabels)
# print(label_matrix[, "label"])
# find the location and plot all the category names
# cat_pos_x <- c(0.18, 0.82, 0.35, 0.65)
cat_pos_x <- c(0.12, 0.89, 0.35, 0.65)
# cat_pos_y <- c(0.58, 0.58, 0.77, 0.77)
cat_pos_y <- c(0.79, 0.79, 0.89, 0.89)
par(mar = PARSET)
plot(x = 0,
y = 0,
type = "n",
xlim = c(0, 1),
ylim = c(0.1, 1),
main = "",
xlab = "",
ylab = "",
frame.plot = FALSE,
axes = FALSE,
yaxs = "i",
xaxs = "i")
# the polygons are not plotted in the direct order of the input list
INPUT_COLS <- c(2,1,4,3)
for (m1 in seq_along(Poly_Set)) {
if (!is.null(SHADECOLS)) {
polygon(x = Poly_Set[[m1]]$x,
y = Poly_Set[[m1]]$y,
col = SHADECOLS[INPUT_COLS[m1]])
} else {
polygon(x = Poly_Set[[m1]]$x,
y = Poly_Set[[m1]]$y)
}
}
for (m1 in seq_along(processedLabels)) {
text(x = label_matrix[m1, 2L],
y = label_matrix[m1, 3L],
labels = processedLabels[m1],
cex = 0.75)
}
# these are in the wrong spots from the initial function
for(m1 in seq_along(list_names)) {
text(x = cat_pos_x[m1],
y = cat_pos_y[m1],
labels = list_names[m1],
cex = 0.75)
}
}
# Function to plot color bar
color.bar <- function(lut,
min1,
max1 = -min1,
min2,
max2 = -min2,
mina,
maxa,
minb,
maxb,
nticks = 10,
ticks1 = seq(min1,
max1,
len = nticks),
ticks2 = seq(min2,
max2,
len = nticks),
ticksa = seq(mina,
maxa,
len = nticks),
ticksb = seq(minb,
maxb,
len = nticks),
title='') {
scale <- (length(lut)-1)/(max1-min1)
# dev.new(width = 1.75,
# height = 5)
plot(c(0,5),
c(min1,max1),
type = 'n',
bty = 'n',
xaxt = 'n',
xlab = '',
yaxt = 'n',
ylab = '')
# text(x = 2.5,
# y = max1 + 1,
# cex = 0.5,
# labels = title)
mtext(text = title,
side = 3,
cex = 0.5)
axis(side = 2,
at = ticks1,
labels = paste0(formatC(ticks1, digits = 2),
" (",
formatC(ticks2, digits = 2),
")"),
las = 1,
cex = 0.5)
axis(side = 4,
at = ticks1,
labels = paste0(formatC(ticksa, digits = 2),
" (",
formatC(ticksb, digits = 2),
")"),
las = 1,
cex = 0.5)
for (i in 1:(length(lut)-1)) {
y = (i-1)/scale + min1
rect(0.25,
y,
4.75,
y+1/scale,
col = lut[i],
border = NA)
}
}
```
### Figure 1:
A reasonable *a priori* expectation is that two assemblies that represent only very recently diverged genomes should contain very similar numbers of pseudogenes. We can plot reported count differences between pseudogenes by type against ANI and show that there are cases of very closely related genomes with considerably different pseudogene repertoires by count.
```{r pg-incongruency, include = TRUE, echo = FALSE}
#| dev = c('png', 'pdf'), fig.width = 3.5, fig.height = 7, fig.align = "center",
#| fig.cap = "Pseudogenes often show orthologous relationships with non-pseudogenes"
load(file = "InputData/Counts_Orthos_v02.RData",
verbose = FALSE)
# as calculated ANI approaches 100 (i.e. zero distance)
# it is assumed that relative counts of pseudogenization events will converge
# at least one pair -- with bad ANI -- is represented only by non-pair groups
dat3 <- dat3[dat3$AllPairs > 0, ]
layout(mat = matrix(data = c(1,1,1,1,6,
2,2,2,2,3,
2,2,2,2,3,
2,2,2,2,3,
4,4,4,4,5,
4,4,4,4,5,
4,4,4,4,5),
nrow = 7,
byrow = TRUE))
# top histogram
wx <- (dat3$Congruent_FS_Pairs > 0 | dat3$Incongruent_FS_Pairs > 0) &
(dat3$Congruent_IS_Pairs > 0 | dat3$Incongruent_IS_Pairs > 0) &
dat3$ANI >= 95
# sum(wx)
# 10362 # points shown!
z1 <- density(dat3$ANI[wx])
par(bg = "white",
mgp = c(2.5, 1.75, 0),
mar = c(0,3,3,1))
brks <- seq(from = floor(min(dat3$ANI)),
to = 100,
by = 0.05)
tophist <- hist(dat3$ANI,
breaks = brks,
plot = FALSE)
xlim1 <- which(tophist$breaks == 95)
xlim2 <- which(tophist$breaks == 100)
barplot(tophist$density,
axes = FALSE,
space = 0,
xlim = c(xlim1, xlim2),
xaxs = "i",
xpd = FALSE)
# plot(x = z1$x,
# y = z1$y,
# xlim = c(95, 100),
# ylim = c(0, 1.5),
# xaxs = "i",
# yaxs = "i",
# lty = 1,
# type = "l",
# xlab = "",
# ylab = "",
# axes = FALSE)
# segments(x0 = 99.99,
# x1 = 99.99,
# y0 = 0.015,
# y1 = 1.29)
# polygon(x = z1$x,
# y = z1$y,
# col = ColVec2[4L])
# incongruent frameshifts
par(bg = "white",
mgp = c(2.0, 1, 0),
mar = c(2.75,3,1,1))
# plot(x = dat3$ANI * 0.01,
# # xlab = "Average Nucleotide Identity (%)", # no xlab on this plot
# xlim = c(0.95, 1.0),
# xlab = "",
# y = (dat3$Incongruent_FS_Pairs / dat3$AllPairs),
# ylab = "Incongruent frameshift pairs",
# ylim = c(0, 0.02),
# pch = 16,
# xaxs = "i",
# yaxs = "i",
# # xaxt = "n",
# yaxt = "n",
# xaxt = "n",
# cex = 0.5,
# col = ColVec2[1L])
# wx <- dat3$Congruent_FS_Pairs > 0 | dat3$Incongruent_FS_Pairs > 0
val_cex <- log10(dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx] + 1) / 2
plot(y = dat3$Incongruent_FS_Pairs[wx] / (dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx]),
x = dat3$ANI[wx],
pch = 16,
ylim = c(0, 1),
xlim = c(95, 100),
col = ColVec2[1L],
xlab = "",
ylab = "Incongruent frameshifts (%)",
xaxs = "i",
yaxs = "i",
yaxt = "n",
# xaxt = "n",
# cex = 0.5,
cex = val_cex)
yaxisseq <- seq(from = 0,
to = 1,
by = 0.2)
axis(side = 2,
at = yaxisseq,
labels = paste0(yaxisseq * 100))
points(x = c(95.25, 95.6, 96.05),
y = c(.1, .1, .1),
cex = sort(c(range(val_cex),
mean(range(val_cex)))),
pch = 16)
text(x = c(95.25, 95.6, 96.05),
y = c(.155, .155, .155),
labels = trunc(sort(c(range(dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx] + 1),
mean(dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx] + 1)))),
srt = 45,
adj = 0,
cex = 0.95)
rect(xleft = 95.1,
ybottom = 0.0275,
ytop = .25,
xright = 96.5,
col = NULL)
# xaxisseq <- seq(from = 95,
# to = 100,
# by = 1)
# axis(side = 1,
# at = xaxisseq,
# labels = paste0(xaxisseq,
# "%"))
# axis(side = 1,
# at = seq(from = 0.9,
# to = 1.0,
# by = 0.02),
# labels = NA)
spfit1 <- smooth.spline(y = dat3$Incongruent_FS_Pairs[wx] / (dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx]),
x = dat3$ANI[wx],
df = 10,
w = dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx])
spfit3 <- predict(spfit1)
lines(x = spfit3$x,
y = spfit3$y,
col = "black")
spfit3$y[length(spfit3$y)] -> val_fit1
# 0.2158595
# upper right histogram
# bw default is for historic and backwards compatibility
par(bg = "white",
mgp = c(2.0, 1.15, 0),
mar = c(2.75,0,1,1))
brks <- seq(from = 0, to = 1, by = 0.01)
yhist <- hist((dat3$Incongruent_FS_Pairs[wx] / (dat3$Congruent_FS_Pairs[wx] + dat3$Incongruent_FS_Pairs[wx]))[dat3$ANI >= 95],
breaks = brks,
plot = FALSE)
barplot(yhist$density,
axes = TRUE,
space = 0,
horiz = TRUE,
ylim = c(0, 100),
xaxp = c(0, 0, 101),
yaxp = c(0, 0, 101),
yaxs = "i",
xaxt = "n",
xpd = FALSE)
# z1 <- density(dat3$Incongruent_FS_Pairs / dat3$AllPairs, bw = "SJ")
# brks <- seq(from = 0,
# to = max(dat3$Incongruent_FS_Pairs / dat3$AllPairs),
# by = 0.00025)
# yhist <- hist((dat3$Incongruent_FS_Pairs / dat3$AllPairs)[dat3$ANI >= 95],
# breaks = brks,
# plot = FALSE)
# ylim1 <- which(yhist$breaks == 0.02)
# ylim2 <- which(yhist$breaks == 0)
# barplot(yhist$density,
# axes = FALSE,
# space = 0,
# horiz = TRUE,
# ylim = c(3, ylim1), # full disclosure, i don't know why this ylim needs to be adjusted this way ... but yaxs ends up cutting off the most dense bar without this and yaxp
# xpd = FALSE,
# yaxp = c(0, 0, ylim1))
# plot(x = z1$y,
# y = z1$x,
# # xlim = c(90, 100),
# ylim = c(0, 0.02),
# xaxs = "i",
# yaxs = "i",
# lty = 1,
# type = "l",
# xlab = "",
# ylab = "",
# axes = FALSE)
# segments(x0 = 10,
# x1 = 10,
# y0 = 0.00,
# y1 = 0.02)
# segments(x0 = 0,
# x1 = 15500,
# y0 = 0.00001,
# y1 = 0.00001)
# polygon(x = c(z1$y, 0),
# y = c(z1$x, 0),
# col = ColVec2[1L])
# incongruent internal stops
par(bg = "white",
mgp = c(2.0, 1, 0),
mar = c(3,3,1,1))
# wx <- dat3$Congruent_IS_Pairs > 0 | dat3$Incongruent_IS_Pairs > 0
val_cex <- log10(dat3$Congruent_IS_Pairs[wx] + dat3$Incongruent_IS_Pairs[wx] + 1) / 2
plot(x = dat3$ANI[wx],
xlab = "Average Nucleotide Identity (%)",
xlim = c(95, 100),
y = dat3$Incongruent_IS_Pairs[wx] / (dat3$Congruent_IS_Pairs[wx] + dat3$Incongruent_IS_Pairs[wx]),
ylab = "Incongruent internal stops (%)",
ylim = c(0, 1),
pch = 16,
xaxs = "i",
yaxs = "i",
yaxt = "n",
# xaxt = "n",
# cex = 0.5,
cex = val_cex,
col = ColVec2[2L])
yaxisseq <- seq(from = 0,
to = 1,
by = .2)
axis(side = 2,
at = yaxisseq,
labels = paste0(yaxisseq * 100))
points(x = c(95.25, 95.6, 96.05),
y = c(.1, .1, .1),
cex = sort(c(range(val_cex),
mean(range(val_cex)))),
pch = 16)
text(x = c(95.25, 95.6, 96.05),
y = c(.155, .155, .155),
labels = trunc(sort(c(range(dat3$Congruent_IS_Pairs[wx] + dat3$Incongruent_IS_Pairs[wx] + 1),
mean(dat3$Congruent_IS_Pairs[wx] + dat3$Incongruent_IS_Pairs[wx] + 1)))),
srt = 45,
adj = 0,
cex = 0.95)
rect(xleft = 95.1,
ybottom = 0.0275,
ytop = .25,
xright = 96.5,
col = NULL)
spfit1 <- smooth.spline(x = dat3$ANI[wx],
y = (dat3$Incongruent_IS_Pairs[wx] / (dat3$Incongruent_IS_Pairs[wx] + dat3$Congruent_IS_Pairs[wx])),
df = 10,
w = dat3$Incongruent_IS_Pairs[wx] + dat3$Congruent_IS_Pairs[wx])
spfit3 <- predict(spfit1)
lines(x = spfit3$x,
y = spfit3$y,
col = "black")
spfit3$y[length(spfit3$y)] -> val_fit2
# 0.08220196
# lower right histogram
par(bg = "white",
mgp = c(2.0, 1.15, 0),
mar = c(3,0,1,1))
z1 <- density((dat3$Incongruent_IS_Pairs / dat3$AllPairs), bw = "SJ")
brks <- seq(from = 0, to = 1, by = 0.01)
yhist <- hist((dat3$Incongruent_IS_Pairs[wx] / (dat3$Congruent_IS_Pairs[wx] + dat3$Incongruent_IS_Pairs[wx]))[dat3$ANI >= 95],
breaks = brks,
plot = FALSE)
barplot(yhist$density,
axes = TRUE,
space = 0,
horiz = TRUE,
ylim = c(0, 100), # full disclosure, i don't know why this ylim needs to be adjusted this way ... but yaxs ends up cutting off the most dense bar without this and yaxp
xaxp = c(0, 0, 101),
yaxp = c(0, 0, 101),
yaxs = "i",
xaxt = "n",
xpd = FALSE)
# # enforce same bin size to match top plot,
# # scale is 1/4 on the y axis
# brks <- seq(from = 0,
# to = max(dat3$Incongruent_FS_Pairs / dat3$AllPairs),
# by = 0.00025 / 4)
# yhist <- hist((dat3$Incongruent_IS_Pairs / dat3$AllPairs)[dat3$ANI >= 95],
# breaks = brks,
# plot = FALSE)
# ylim1 <- which(yhist$breaks == 0.005)
# ylim2 <- which(yhist$breaks == 0)
# barplot(yhist$density,
# axes = FALSE,
# space = 0,
# horiz = TRUE,
# ylim = c(3, ylim1), # full disclosure, i don't know why this ylim needs to be adjusted this way ... but yaxs ends up cutting off the most dense bar without this and yaxp
# xpd = FALSE,
# yaxp = c(0, 0, ylim1))
# plot(x = z1$y,
# y = z1$x,
# ylim = c(0, 0.005),
# xaxs = "i",
# yaxs = "i",
# lty = 1,
# type = "l",
# xlab = "",
# ylab = "",
# axes = FALSE)
# segments(x0 = 10,
# x1 = 10,
# y0 = 0.00,
# y1 = 0.015)
# segments(x0 = 0,
# x1 = 21000,
# y0 = 0.00001,
# y1 = 0.00001)
# # segments(x0 = 0.02,
# # x1 = 0.23,
# # y0 = 0.005,
# # y1 = 0.005,
# # xpd = TRUE)
# polygon(x = c(z1$y, 0),
# y = c(z1$x, 0),
# col = ColVec2[2L])
cat(paste("\nframeshift spline fit at 100 ==", val_fit1, "\n",
"internal stop split fit at 100 ==", val_fit2))
```
We can calculate the number of very close pairs (pairs with an ANI >= 99.9), where the rates of pseudogenization imply that one partner has more pseudogenes than expected. The code snippet below shows how this can be accomplished for both internal stops and frameshifts.
```{r rejection-rates, include = TRUE, echo = TRUE}
# from the data file: InputData/Counts_Orthos_v02.RData
# match up the total coding counts to the pair partners
mat1 <- match(x = dat3$id1,
table = as.integer(rownames(adjusted_counts)))
mat2 <- match(x = dat3$id2,
table = as.integer(rownames(adjusted_counts)))
dat3$features1 <- adjusted_counts$all_coding[mat1]
dat3$features2 <- adjusted_counts$all_coding[mat2]
size <- ifelse(test = dat3$is1 > dat3$is2,
yes = dat3$features1,
no = dat3$features2) # features in assembly with more IS
rate <- ifelse(test = dat3$is1 < dat3$is2,
yes = dat3$is1/dat3$features1,
no = dat3$is2/dat3$features2) # rate of IS in assembly with fewer IS
num <- ifelse(test = dat3$is1 > dat3$is2,
yes = dat3$is1,
no = dat3$is2) # number of IS in assembly with more IS
reject <- num > qbinom(0.99, size, rate)
# sum(dat3$ANI >= 99.9)
cat("Rejections by Internal Stops == ")
mean(reject[dat3$ANI >= 99.9])
size <- ifelse(test = dat3$fs1 > dat3$fs2,
yes = dat3$features1,
no = dat3$features2) # features in assembly with more FS
rate <- ifelse(test = dat3$fs1 < dat3$fs2,
yes = dat3$fs1/dat3$features1,
no = dat3$fs2/dat3$features2) # rate of FS in assembly with fewer FS
num <- ifelse(test = dat3$fs1 > dat3$fs2,
yes = dat3$fs1,
no = dat3$fs2) # number of FS in assembly with more FS
reject <- num > qbinom(0.99, size, rate)
# sum(dat3$ANI >= 99.9)
cat("Rejections by Frameshifts == ")
mean(reject[dat3$ANI >= 99.9])
```
### Figure 2:
The incomplete nature of the metadata available in public repositories makes direct modeling from that metadata unwise. Causal inference can be applied to that data however, and we can plot out how distributions of relative pseudogene counts by label groups appear to be dissimilar.
```{r inference-and-observation, include = TRUE, echo = FALSE}
#| dev = c('png', 'pdf'), fig.width = 7, fig.height = 7, fig.align = "center",
#| fig.cap = "Causal inference and observational distributions of pseudogenes"
load(file = "InputData/TetradEdges.RData",
verbose = FALSE)
load(file = "InputData/Technology_Observations_v01.RData",
verbose = FALSE)
g <- graph_from_data_frame(d = df,
directed = TRUE)
E(g)$weight <- df$weight
# V(g)$name <- gsub(pattern = " ",
# replacement = "\n",
# x = V(g)$name)
# available nodes:
avl_nodes <- colnames(tetradtable_v04)
avl_nodes <- gsub(x = avl_nodes,
pattern = "_",
replacement = " ")
# submitter controlled: 4
# sequencing/assembly outcome, non-pseudo related: 5
# pseudos: 6
node_cols <- ColVec1[c(4,5,4,4,4,6,6,6,5,5)]
# node_cols <- ColVec1[c(1,2,1,1,1,3,3,3,2,2)]
pres_nodes <- attr(V(g), "names")
ColVec5 <- ColVec1[match(x = df$type,
table = unique(df$type))]
weights2 <- df$weight * 100
# weights2[weights2 == 100] <- 99
ColVec6 <- paste0(ColVec5,
formatC(x = weights2,
width = 2,
flag = 0,
format = "d"))
ColVec6[weights2 == 100] <- ColVec5[weights2 == 100]
## dropping igraph plots because erik has this in keynote
# layout(mat = matrix(data = c(1,1,1,1,
# 1,1,1,1,
# 2,2,3,3,
# 2,2,3,3,
# 4,4,5,5,
# 4,4,5,5),
# ncol = 4,
# byrow = TRUE))
# l <- layout_with_sugiyama(g)
# l <- matrix(data = c(1.5, 2.5, 1.0, 4.0, 1.0, 4.5, 3.0, -1.0, 6.0,
# 2.0, 3.0, 3.0, 3.0, 1.0, 1.0, 2.0, 2.0, 2.0),
# ncol = 2)
# l <- layout_with_dh(g)
# set.seed(1986)
# par(mgp = c(2,1,0),
# mar = c(1,1,1,1),
# bg = "white")
# plot(g,
# layout=l,
# # vertex.shape = "rectangle",
# # vertex.size = (strwidth(attr(V(g), "names")) + strwidth("oo")) * 25,
# # vertex.size2 = strheight("I") * 2 * 15,
# vertex.shape = "circle",
# # vertex.size = max((strwidth(attr(V(g), "names")) + strwidth("o")) * 20),
# # vertex.size = seq_along(attr(V(g), "names")) * 5,
# vertex.size = 40,
# vertex.label.cex = .8,
# vertex.color = node_cols[match(x = pres_nodes,
# table = avl_nodes)],
# # edge.arrow.size = 1,
# edge.color = ColVec6,
# # edge.width = 2,
# vertex.frame.width = 0,
# vertex.label.color = "black")
# legend("bottomleft",
# # legend = unique(df$type),
# legend = c("causal", "causal*"),
# lty = 1,
# lwd = 2,
# col = ColVec1[seq_along(unique(df$type))],
# cex = 1,
# bg = NA,
# bty = "n")
layout(mat = matrix(data = 1:4,
nrow = 2,
byrow = TRUE))
## assemblers
PIN <- 562
t1 <- tapply(X = dat1$IS_per_MB[dat1$TaxID == PIN],
INDEX = dat1$Assembler[dat1$TaxID == PIN],
FUN = c)
t1 <- t1[order(lengths(t1), decreasing = TRUE)]
t1 <- t1[-2L]
t2 <- tapply(X = dat1$FS_per_MB[dat1$TaxID == PIN],
INDEX = dat1$Assembler[dat1$TaxID == PIN],
FUN = c)
t2 <- t2[order(lengths(t2), decreasing = TRUE)]
t2 <- t2[-2L]
# frameshifts first
# top left
par(mar = c(3,3,1,0.75),
mgp = c(1.85, 0.65, 0),
cex.lab = 1,
cex.axis = 1,
cex.main = 1,
cex.sub = 1,
bg = "white")
plot(x = 0,
y = 0,
type = "n",
xlab = "",
ylab = "Cumulative Frequency",
xlim = c(0, 40),
ylim = c(0, 1),
main = "",
xaxs = "i",
yaxs = "i")
for (m1 in seq_len(7L)) {
points(x = sort(t2[[m1]]),
y = seq_along(t2[[m1]]) / length(t2[[m1]]),
col = ColVec1[m1],
pch = 46)
}
par(mar = c(3,3,1,0.75),
mgp = c(1.85, 0.65, 0),
cex.lab = 1,
cex.axis = 1,
cex.main = 1,
cex.sub = 1,
bg = "white")
plot(x = 0,
y = 0,
type = "n",
xlab = "",
ylab = "",
xlim = c(0, 25),
ylim = c(0, 1),
main = "",
xaxs = "i",
yaxs = "i")
for (m1 in seq_len(7L)) {
points(x = sort(t1[[m1]]),
y = seq_along(t1[[m1]]) / length(t1[[m1]]),
col = ColVec1[m1],
pch = 46)
}
legend(x = 14.5,
y = 0.50,
# legend = names(t1)[seq_len(7L)],
legend = c("SPAdes",
"Platanus",
"CLC",
"Abyss",
"Shovill",
"A5",
"Unicycler"),
pch = 20,
col = ColVec1[seq_len(7L)],
cex = 1,
bg = NA,
bty = "n")
## platform
PIN <- 562
t1 <- tapply(X = dat1$IS_per_MB[dat1$TaxID == PIN],
INDEX = dat1$Technology[dat1$TaxID == PIN],
FUN = c)
t1 <- t1[order(lengths(t1), decreasing = TRUE)]
t2 <- tapply(X = dat1$FS_per_MB[dat1$TaxID == PIN],
INDEX = dat1$Technology[dat1$TaxID == PIN],
FUN = c)
t2 <- t2[order(lengths(t2), decreasing = TRUE)]
# frameshifts first
# bottom left
par(mar = c(3,3,1,0.75),
mgp = c(1.85, 0.65, 0),
cex.lab = 1,
cex.axis = 1,
cex.main = 1,
cex.sub = 1,
bg = "white")
plot(x = 0,
y = 0,
type = "n",
xlab = "Frameshifts per Mbp",
ylab = "Cumulative Frequency",
xlim = c(0, 40),
ylim = c(0, 1),
main = "",
xaxs = "i",
yaxs = "i")
for (m1 in seq_len(7L)) {
points(x = sort(t2[[m1]]),
y = seq_along(t2[[m1]]) / length(t2[[m1]]),
col = ColVec1[m1],
pch = 46)
}
par(mar = c(3,3,1,0.75),
mgp = c(1.85, 0.65, 0),
cex.lab = 1,
cex.axis = 1,
cex.main = 1,
cex.sub = 1,
bg = "white")
plot(x = 0,
y = 0,
type = "n",
xlab = "Internal stops per Mbp",
ylab = "",
xlim = c(0, 25),
ylim = c(0, 1),
main = "",
xaxs = "i",
yaxs = "i")
for (m1 in seq_len(7L)) {
points(x = sort(t1[[m1]]),
y = seq_along(t1[[m1]]) / length(t1[[m1]]),
col = ColVec1[m1],
pch = 46)
}
legend(x = 12.5,
y = 0.50,
# legend = names(t1)[seq_len(7L)],
# legend = c("Ill. 1x",
# "Ill + ONT",
# "PB",
# "Ill. >=2x",
# "Ill. + PB",
# "Ion Torrent"),
legend = c("Illumina 1x",
"Illumina + ONT",
"PacBio",
"Illumina 2x",
"Illumina + PacBio",
"ONT",
"Ion Torrent"),
pch = 20,
col = ColVec1[seq_len(7L)],
cex = 1,
bg = NA,
bty = "n")
```
### Tetrad Table for Figure 2:
```{r inference-and-observation-table, include = TRUE, echo = FALSE}
kable(df)
```
### Figure 3:
Reassembly of reads on the SRA from within a single genus using different assemblers shows unique distributions as assembler is varied.
```{r influence-of-assembler, include = TRUE, echo = FALSE}
#| dev = c('png', 'pdf'), fig.width = 7, fig.height = 7, fig.align = "center",
#| fig.cap = "Within a species, different assemblers provide unique distributions of pseudogenes"
load(file = "InputData/Neisseria_v02.RData",
verbose = FALSE)
load(file = "InputData/Neisseria_v03.RData",
verbose = FALSE)
U_Assembler <- unique(dat1$Assembler)
s1 <- names(which(table(dat1$BioSample) == 4L))
dat1 <- dat1[dat1$BioSample %in% s1, ]
print(paste(nrow(dat1) / 4, "total source reads with completed reassemblies for all chosen assemblers."))
ISperMB <- (dat1$IS / dat1$AssemblySize) * 1000000
FSperMB <- (dat1$FR / dat1$AssemblySize) * 1000000
# negative vals mean reported counts are higher than reassembled counts
ISdev <- ISperMB - dat2$ISperMB[match(x = dat1$BioSample,
table = dat2$BioSample)]
FSdev <- FSperMB - dat2$FSperMB[match(x = dat1$BioSample,
table = dat2$BioSample)]
layout(mat = matrix(data = 1:4,
nrow = 2))
# top left, no x axis label
par(mar = c(3,3,2,1),
mgp = c(1.5, 0.75, 0),
cex.lab = 0.85,
cex.axis = 0.85,
cex.main = 1,
cex.sub = 1,
bg = "white")
plot(x = 0,
y = 0,
type = "n",
xlab = "Frameshifts per Mbp",
ylab = "Cumulative Frequency",
ylim = c(0, 1),
xlim = c(40, 60),
xaxs = "i",
yaxs = "i")
legend("bottomright",
# legend = U_Assembler,
# legend = c("MEGAHIT", "SKESA", "SPAdes", "Unicycler"),
legend = c("MEGAHIT", "SPAdes", "Unicycler", "SKESA"),
lty = 1,
# col = ColVec1[seq_along(U_Assembler)],
col = ColVec1[c(1,3,4,2)],
cex = 0.75,
bg = NA,
bty = "n")
# text(y = .9,
# x = 42,
# labels = bquote(bold("A")),
# cex = 1.6)
for (m1 in seq_along(U_Assembler)) {
pv3 <- dat1$Assembler == U_Assembler[m1]
lines(x = sort(FSperMB[pv3]),