-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswissprot_general_overview.Rmd
1794 lines (1575 loc) · 89.5 KB
/
swissprot_general_overview.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: 'FIGURES: A new census of protein tandem repeats: fun with disorder.'
output:
html_document: default
pdf_document: default
date: "March, 2019"
---
# Housekeeping
```{r echo=FALSE, message=FALSE, warning=FALSE}
# Before executing this file, do: setwd("path/to/your/git/on/swissrepeat/results")
source("local_config.R")
setwd(paste0(local_base_path,"/results"))
rm(list = ls(all = TRUE))
gc()
source("helpers.R")
# colour setup:
#library(RColorBrewer); display.brewer.all() # to display available colour palettes
colour_count = 13 # alternative: length(unique(sp_gathered$Kingdom))
getPalette = colorRampPalette(brewer.pal(9, "Dark2"))
cols1 <- c("#AA3939", "#AA7939", "#29506D", "#2D882D") #http://paletton.com/#uid=7000I0kllllaFw0g0qFqFg0w0aF
cols2 <- c("#FFAAAA", "#FFDBAA", "#718EA4", "#88CC88")
cols3 <- c("#801515", "#805215", "#123652", "#116611")
cols4 <- c("#550000", "#553100", "#042037", "#004400")
save <- FALSE
```
# Data Loading
```{r, echo=FALSE, eval=TRUE}
tr_path = paste0("results", local_path_separator, "tr_annotations", local_path_separator, "tr_annotations.csv")
tr_all = load_tr_annotations(tr_path)
sp_path = paste0("data", local_path_separator, "swissprot_annotations.tsv")
sp_all = load_swissprot(sp_path, tr_all)
# Add meta_data from sp_all to tr_all. -> Do a left join.
tr_all_sp = merge(x = tr_all, y = sp_all, by = "ID", all.x = TRUE)
# Add disorder information from modiDB
discoor_path = paste0("results", local_path_separator, "disorder_annotations", local_path_separator, "mobidb_coordinates.csv")
discoor_all = load_disorder_annotations(discoor_path)
discoor_all$disorder_region_length = (discoor_all$end - discoor_all$start) + 1
discoor_all$center = floor(discoor_all$start + (discoor_all$disorder_region_length/2))
discoor_all_sp = merge(x = discoor_all, y = sp_all, by = "ID", all.x = TRUE)
# Remove eventual regions with incorrect coordinates
discoor_all_sp = discoor_all_sp[(discoor_all_sp$center<discoor_all_sp$Length),]
#Aggregate disordered regions by protein, calculate disorder residues count in a protein
sp_protein= ddply(discoor_all, .(ID), summarize,
disorder_count=(sum(disorder_region_length)))
sp_protein = merge(x = sp_protein, y = sp_all, by = "ID", all.x = TRUE)
aa_ignore = c("B", "X", "Z", "O", "U", "*","-",".","+", "other")
homo_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/empirical_and_expected/swissprot.csv"
homo_all = load_homorepeat_data(homo_path, aa_ignore, "all")
homo_disorder_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/empirical_and_expected/mobidb_consensus.csv"
homo_d_all = load_homorepeat_data(homo_disorder_path, aa_ignore, "disorder")
homo_order_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/empirical_and_expected/mobidb_consensus_inverse.csv"
homo_o_all = load_homorepeat_data(homo_order_path, aa_ignore, "order")
homo_exp_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/expected_on_unbound_sequence/swissprot.csv"
# homo_exp_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/expected_on_unbound_sequence/swissprot_kingdomwise.csv"
# couldn't find the file "swissport_kingdomwise.csv" and don't know where it's generated... however swissprot exists in this directory and seems to work.
homo_exp_all = load_expected_homorepeat_frequencies(homo_exp_path, aa_ignore, "all")
homo_exp_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/expected_on_unbound_sequence/mobidb_consensus.csv"
homo_exp_d = load_expected_homorepeat_frequencies(homo_exp_path, aa_ignore, "disorder")
homo_exp_path = "results/empirical_and_expected_homorepeat_counts/swiss_prot_homorepeat_frequencies/expected_on_unbound_sequence/mobidb_consensus_inverse.csv"
homo_exp_o = load_expected_homorepeat_frequencies(homo_exp_path, aa_ignore, "order")
```
# Tandem Repeats general overview
## Repeat unit length vs number of repeats
Fig. 1a (cnf. Fig 5, Marcotte et al.)
see presentation maria slide 14
```{r, warning=FALSE, eval=TRUE, echo=FALSE, message=FALSE, fig.width=15, fig.height=10}
d = subset(tr_all_sp, pvalue <= 0.01 & l_effective <= 80 & n_effective <= 40)
# Zinc-finger
table(d[grepl(pattern = "Zinc", x = d$protein_name),]$l_effective) # l_effective = 28 has a clear enrichment
# LRR
table(d[grepl(pattern = "LRR", x = d$protein_name),]$l_effective) # l_effective = 24 and 26 has a clear enrichment
# WD40
table(d[grepl(pattern = "WD40", x = d$protein_name),]$l_effective) # l_effective = 24, 26 and 57 has a clear enrichment
```
```{r, warning=FALSE, eval=TRUE, echo=FALSE, message=FALSE, fig.width=15, fig.height=10}
refactor = function(col) {
factor(col, levels = min(col):max(col))
}
d_summary = d %>%
mutate(n_effective_rounded = round(n_effective)) %>%
group_by(l_effective, n_effective_rounded) %>%
summarize(count=n()) %>%
ungroup() %>%
transmute(l_effective = refactor(l_effective),
n_effective_rounded = refactor(n_effective_rounded),
log10count=log10(count))
p = ggplot(d_summary, aes(x=l_effective, y=n_effective_rounded, fill=log10count)) +
geom_raster() +
# scale_fill_gradientn(colors=parula(256), guide = "colourbar") +
scale_fill_gradientn(colors= rev(cividis(256)), guide = "colourbar") +
geom_vline(xintercept = 24, colour = "grey", size = 1) + #LRR
geom_vline(xintercept = 26, colour = "grey", size = 1) + #LRR
geom_label(aes(x = 25, y = 28, label = "LRR"), fill = "white", size = 10)+
geom_vline(xintercept = 28, colour = "grey", size = 1) + # Zn-finger
geom_label(aes(x = 28, y = 33, label = "Zn-finger"), fill = "white", size = 10)+
geom_vline(xintercept = 41, colour = "grey", size = 1)+ #WD40
geom_vline(xintercept = 26, colour = "grey", size = 1)+ #WD40
geom_vline(xintercept = 57, colour = "grey", size = 1)+ #WD40
geom_label(aes(x = 26, y = 38, label = "WD40"), fill = "white", size = 10)+
# geom_label(aes(x = 49, y = 38, label = "WD40"), fill = "white", size = 10)+
geom_label(aes(x = 41, y = 38, label = "WD40"), fill = "white", size = 10)+
geom_label(aes(x = 57, y = 38, label = "WD40"), fill = "white", size = 10)+
labs(x="Repeat Unit Length", #expression(l[effective]),
y="Number of repeats", #expression(n[effective]),
fill=expression(log[10](count))) +
scale_x_discrete(breaks=c(1,seq(0,80,5),80)) +
scale_y_discrete(breaks=c(2,seq(0,40,5),40))
p = beautifier(p)
# + theme(text = element_text(family = "sans", size=48),
# strip.text = element_text(size=30, angle = 0),
# axis.text = element_text(size=25, margin=margin(10,1,2,1,"pt")),
# #panel.background = element_rect(fill="black"),
# panel.grid.major = element_blank(),
# panel.grid.minor = element_blank(),
# legend.key.size = unit(48, "pt"))
p <- paper.figure(p)
p
if (save == TRUE) {
ggsave(paste0(pathImages, "fig1_raster", figureFormat), width=12, height=8, dpi = 300)
}
# check this for color scale: https://hihayk.github.io/scale/#0/20/42/16/72/-50/49/50/D20000/210/0/0
p = ggplot(d_summary, aes(x=l_effective, y=n_effective_rounded)) +
geom_point(aes(color= log10count, size = 10))+
# scale_color_continuous(high = "#AA3939", low = "#2D882D")+
scale_color_continuous(low = "#F9C73F", high = "#A21212")+
labs(x="Repeat Unit Length", #expression(l[effective]),
y="Number of repeats", #expression(n[effective]),
color=expression(log[10](count))) +
scale_x_discrete(breaks=c(1,seq(0,80,5),80)) +
scale_y_discrete(breaks=c(2,seq(0,40,5),40)) +
guides(size = FALSE) # remove size legend
# Mean_Prot_length_vs_Frac_TR
p = beautifier(p, x.axis.text.angle = 0)
p <- paper.figure(p, x.axis.text.angle = 0)
p
if (save == TRUE) {
ggsave(paste0(pathImages, "fig1", figureFormat), width=12, height=8, dpi = 300)
}
# or in 3D
# devtools::install_github("tylermorganwall/rayshader")
library(rayshader)
p = ggplot(d_summary, aes(x=l_effective, y=n_effective_rounded)) +
geom_point(aes(color= log10count))+
# scale_color_continuous(high = "#AA3939", low = "#2D882D")+
scale_color_continuous(low = "#F9C73F", high = "#A21212")+
labs(x="Repeat Unit Length", #expression(l[effective]),
y="Number of repeats", #expression(n[effective]),
color=expression(log[10](count))) +
scale_x_discrete(breaks=c(1,seq(0,80,5),80)) +
scale_y_discrete(breaks=c(2,seq(0,40,5),40)) +
guides(size = FALSE) # remove size legend
p = beautifier(p, x.axis.text.angle = 0) +
theme(legend.position="bottom", legend.box = "horizontal")
plot_gg(p, width = 5, height = 4, scale = 300, multicore = TRUE, windowsize = c(1000,800))
# plot_gg(p, width = 3.5, multicore = TRUE, windowsize = c(800, 800),
# zoom = 0.5, phi = 35, theta = 30, sunangle = 225, soliddepth = -100)
render_camera(theta = 320, phi = 60, zoom = 0.62)
# rgl.postscript(paste0(pathImages, "fig1_3D"), fmt="svg")
render_snapshot(paste0(pathImages, "fig1_3D", figureFormat), clear = TRUE)
```
Fig. 1a: Distribution (Heatmap) of all tandem repeats (TRs) in Swiss-Prot as a function of their repeat unit length $l_{effective} <= 80$ (x-Axis, x1) and their number of repeat units $n_{effective} <= 40$ (x2, y-Axis). Darker colour indicates a larger number of TRs with a specific length and number of repeats. The majority of TRs has short TR units. Yet, there is a blob of domain TRs ($25 < l_{effective} < 50$), with certain TR unit length clearly enriched (e.g., $l_{effective} = 28$, mostly Zn finger TRs.)
## Homo TRs represent only 20% of all TRs
```{r}
# Filter for Proteins with only homo TRs
homo_TRs_summary <-subset(tr_all_sp,
has_homo_tr == T &
has_micro_tr == F &
has_short_tr == F &
has_domain_tr == F &
pvalue <= 0.01)
# Get their average repetition unit number
summary(homo_TRs_summary$n_effective)
# filter for Proteins with short TRs but also others.
homo_TRs_summary <-subset(tr_all_sp,
has_homo_tr == T &
pvalue <= 0.01)
# Get their average repetition unit number
summary(homo_TRs_summary$n_effective)
# fraction of homo TRs in all TRs
(round(nrow(homo_TRs_summary)/nrow(tr_all_sp), 3))
# eukaryotes
(round(nrow(homo_TRs_summary[which(homo_TRs_summary$Superkingdom == "Eukaryota"),])/nrow(homo_TRs_summary), 3))
(round(nrow(homo_TRs_summary[which(homo_TRs_summary$Superkingdom == "Eukaryota"),])/nrow(tr_all_sp), 3))
# humans homo repeats
(round(nrow(homo_TRs_summary[which(homo_TRs_summary$Species == "Homo sapiens (Human)"),])/nrow(tr_all_sp[which(tr_all_sp$Species == "Homo sapiens (Human)"),]), 3))
```
Proteins containing homo TRs have TRs mostly of small size (mean size = 8.8 repeat units). They make up 20\% of all found TRs over all Superkingdoms and 30\% for Human TR. Of all the homo TRs, 91.3\% are from Eukaryotic origin. We couldn't detect a protein which contains only homo TRs and no other type of repeat.
## Micro TRs
```{r}
# Filter for Proteins with only micro TRs
micro_TRs_summary <-subset(tr_all_sp,
has_homo_tr == F &
has_micro_tr == T &
has_short_tr == F &
has_domain_tr == F &
pvalue <= 0.01)
# Get their average repetition unit number
summary(micro_TRs_summary$n_effective)
# filter for Proteins with short TRs but also others.
micro_TRs_summary <-subset(tr_all_sp,
has_micro_tr == T &
pvalue <= 0.01)
# Get their average repetition unit number
summary(micro_TRs_summary$n_effective)
# fraction of homo TRs in all TRs
(round(nrow(micro_TRs_summary)/nrow(tr_all_sp), 3))
# eukaryotes
(round(nrow(micro_TRs_summary[which(micro_TRs_summary$Superkingdom == "Eukaryota"),])/nrow(micro_TRs_summary), 3))
(round(nrow(micro_TRs_summary[which(micro_TRs_summary$Superkingdom == "Eukaryota"),])/nrow(tr_all_sp), 3))
# humans homo repeats
(round(nrow(micro_TRs_summary[which(micro_TRs_summary$Species == "Homo sapiens (Human)"),])/nrow(tr_all_sp[which(tr_all_sp$Species == "Homo sapiens (Human)"),]), 3))
```
Proteins with micro TRs tend to have TRs with a mean of 7 repeat units. When we looked at Proteins which contained only TRs of the type micro, the mean repeat unit number is 3.
Proteins containing micro TRs make up 56\% of the found TRs.
## Small TRs tend to have TRs with less repetition units than those with homo TRs
```{r}
# Filter for Proteins with only short TRs
short_TRs_summary <-subset(tr_all_sp,
has_homo_tr == F &
has_micro_tr == F &
has_short_tr == T &
has_domain_tr == F &
pvalue <= 0.01)
# Get their average repetition unit number
summary(short_TRs_summary$n_effective)
# filter for Proteins with short TRs but also others.
short_TRs_summary <-subset(tr_all_sp,
has_short_tr == T &
pvalue <= 0.01)
# Get their average repetition unit number
summary(short_TRs_summary$n_effective)
# fraction of Short TRs in all TRs
(round(nrow(short_TRs_summary)/nrow(tr_all_sp), 3))
# Protein names which fall in the range of the mean value of short TRs
short_TRs_summary[which(short_TRs_summary$n_effective == 5),]
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$l_effective > 1),] # exclude homorepeats
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$n > 200),] # show only high unit numbers: n>200
# print(short_TRs_summary[order(short_TRs_summary$n, decreasing = FALSE),]) # Serine aspartate from staphylococcus aureus and collagen units from odd-toed ungulates (horses)
# print(short_TRs_summary[which(short_TRs_summary$ID == "Q9KI14"),])
# # Homo sapiens (Human)
# short_TRs_summary <- subset(tr_all_sp, has_short_tr == TRUE & pvalue <= 0.01)
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$l_effective > 1),] # exclude homorepeats
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$n > 200 & short_TRs_summary$Species == "Homo sapiens (Human)"),] # show only high unit numbers: n>200
# print(short_TRs_summary[order(short_TRs_summary$n, decreasing = TRUE),]) # Mucin and Collagen protein units (including Major airway glycoprotein)
#
# # subset as in figure 1a with grey lines indicated
# short_TRs_summary <- subset(tr_all_sp, pvalue <= 0.01 & l_effective <= 80 & n_effective <= 40)
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$l_effective > 28 & short_TRs_summary$l_effective < 50),]
# short_TRs_summary <- short_TRs_summary[which(short_TRs_summary$n_effective <= 40),] # show only high unit numbers: n>200
# print(short_TRs_summary[order(short_TRs_summary$n_effective, decreasing = TRUE),]) #
```
Proteins with small TRs tend to have TRs with less repetition units than those with homo TRs (mean = 6 repeat units). When we looked at Proteins which contained solely TRs of the type small, the mean repeat unit number is 3.
Proteins containing small TRs make up 76\% of the found TRs.
## Domain TRs mostly consist of few units.
```{r}
# Filter for Proteins with only domain TRs
domain_TRs_summary <-subset(tr_all_sp,
has_homo_tr == F &
has_micro_tr == F &
has_short_tr == F &
has_domain_tr == T &
pvalue <= 0.01)
# Get their average repetition unit number
summary(domain_TRs_summary$n_effective)
domain_TRs_summary <- subset(tr_all_sp, pvalue <= 0.01 & l_effective <= 80 & l_effective >1 & n_effective <= 40 & has_domain_tr == TRUE)
domain_TRs_summary <- subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE)
ggplot(domain_TRs_summary, aes(x = ID, y = n_effective))+
geom_point()
domain_TRs_summary[which(domain_TRs_summary$n_effective > 300),]
domain_TRs_summary[which(domain_TRs_summary$ID == "Q5HFY8"),]
domain_TRs_summary <- domain_TRs_summary[order(domain_TRs_summary$n_effective, decreasing = TRUE),]
print(domain_TRs_summary)
# filter for Proteins with domain TRs but also others.
domain_TRs_summary <-subset(tr_all_sp,
has_domain_tr == T &
pvalue <= 0.01)
# Get their average repetition unit number
summary(domain_TRs_summary$n_effective)
# fraction of domain TRs in all TRs
(round(nrow(domain_TRs_summary)/nrow(tr_all_sp), 3))
```
## TRs are not homogenously distributed in terms of their unit lengths and numbers
```{r}
d_all_sp = subset(tr_all_sp, pvalue <= 0.01 & l_effective <= 80 & n_effective <= 40)
d_all_sp_summary <- d_all_sp %>%
mutate(n_effective_rounded = round(n_effective))
head(d_all_sp_summary)
d_all_sp_summary_selection <- d_all_sp_summary[which(d_all_sp_summary$l_effective > 25 & d_all_sp_summary$l_effective < 50),]
print(d_all_sp_summary_selection[order(d_all_sp_summary_selection$protein_name, decreasing = TRUE),]) # ordered by decreasing protein name
# Zinc-finger
print(d_all_sp_summary_selection[grepl(pattern = "Zinc", x = d_all_sp_summary_selection$protein_name),]) # select rows containing "Zinc" in protein_name
zinc_n <- sum(grepl(pattern = "Zinc", x = d_all_sp_summary_selection$protein_name))
zinc_frac <- zinc_n/nrow(d_all_sp_summary_selection)
# LRR
print(d_all_sp_summary_selection[grepl(pattern = "LRR", x = d_all_sp_summary_selection$protein_name),]) # select rows containing "LRR" in protein_name
LRR_n <- sum(grepl(pattern = "LRR", x = d_all_sp_summary_selection$protein_name))
LRR_frac <- LRR_n/nrow(d_all_sp_summary_selection)
# WD40
print(d_all_sp_summary_selection[grepl(pattern = "WD40", x = d_all_sp_summary_selection$protein_name),]) # select rows containing "WD40" in protein_name
WD40_n <- sum(grepl(pattern = "WD40", x = d_all_sp_summary_selection$protein_name))
WD40_frac <- WD40_n/nrow(d_all_sp_summary_selection)
print(paste("Selection of proteins with 25 < repeat length <50",
"fraction of Zinc-finger associated Proteins: ", round(zinc_frac, digits = 3),
"fraction of LRR associated Proteins: ", round(LRR_frac, digits = 3),
"fraction of WD40 associated Proteins: ", round(WD40_frac, digits = 3),
collapse = '\n'))
df <- subset(tr_all_sp, pvalue <= 0.01) # subset(tr_all_sp, pvalue <= 0.01 & l_effective <= 80 & n_effective <= 40)
#some dummy data
# df <- data.frame(ID = as.factor(c("ID1", "ID2", "ID3", "ID4", "ID5", "ID6", "ID7", "ID8", "ID9")),
# n_effective = as.numeric(c(2.558824, 2.520000, 4.875000, 2.875000, 3.750000, 2.000000, 2.000000, 2.000000, 23.875000)),
# Superkingdom = as.character(c("Eukaryota", "Eukaryota", "Eukaryota", "Bacteria", "Bacteria", "Bacteria", "Archeae", "Archeae", "Viruses")))
p1 <- ggplot(df, aes(x = ID, y = n_effective, facet = Superkingdom))+
facet_wrap(facets = "Superkingdom")+
geom_point()+
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
strip.text.x = element_blank())+
scale_x_discrete(labels = NULL)+
labs(x = "Protein ID", y = "Repeat unit number")
p1 <- beautifier(p1)
p1 <- paper.figure(p1)
p1
if( save) {
ggsave(paste0(pathImages, "TR_distribution_unit_numbers", figureFormat), width=12, height=8, dpi = 300)
}
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Bacteria" & n_effective > 250)) # Uncharacterized PE-PGRS family protein PE_PGRS54 of Mycobacterium tuberculosis, Cell surface glycoprotein 1 of Clostridium thermocellum, Staphylococcus aureus surface protein A and Serine-aspartate repeat-containing protein F of Staphylococcus aureus and epidermis respectively
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Eukaryota" & n_effective > 300)) # highest value belongs to Eremothecium gossypii protein of Mediator of RNA polymerase II transcription subunit 15
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Viruses" & n_effective > 300)) # Collagen-like protein 7 of Mimiviridae family
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Viruses" & n_effective > 180)) # different Collagen-like proteins of mimiviridae
p2 <- ggplot(df, aes(x = ID, y = l_effective, facet = Superkingdom))+
facet_wrap(facets = "Superkingdom")+
geom_point()+
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
strip.text.x = element_blank())+
scale_x_discrete(labels = NULL)+
labs(x = "Protein ID", y = "Repeat unit length")
p2 <- beautifier(p2)
p2 <- paper.figure(p2)
p2
if( save) {
ggsave(paste0(pathImages, "TR_distribution_unit_length", figureFormat), width=12, height=8, dpi = 300)
}
p3 <- ggplot(df, aes(x = ID, y = total_repeat_length, facet = Superkingdom))+
facet_wrap(facets = "Superkingdom")+
geom_point()+
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
strip.text.x = element_blank())+
scale_x_discrete(labels = NULL)+
labs(x = "Protein ID", y = "Repeat Length")
p3 <- beautifier(p1)
p3 <- paper.figure(p3)
p3
if( save) {
ggsave(paste0(pathImages, "TR_distribution_total_repeat_length", figureFormat), width=12, height=8, dpi = 300)
}
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Bacteria" & l_effective >= 440)) # hemagglutinin A used for host colonisation by adhesion to extracellular matrix proteins Nelson2003, Han1996
print(subset(tr_all_sp, pvalue <= 0.01 & has_domain_tr == TRUE & Superkingdom == "Eukaryota" & l_effective >= 900)) # (Anchorage 1 protein) (Nesprin homolog) in C. elegans and (MUC-11) (FcgammaBP) in Human
```
Fig1a reveals multpile peaks showing that some unit lengths are particularly frequent. These peaks represent common TRs, with specific TR units used in varying number.
One example is the zinc-finger (xx and xx aa) but also LRR and WD40-like beta propeller
# Fraction of TR vs. Mean protein length (Fig 1a Marcotte et al.)
Show how sequence length and presence of TRs correlate.
```{r, echo=TRUE}
sp = ddply(sp_all, .(origin, Superkingdom, Kingdom, is_chloroplastic, is_mitochondrial),
summarize,
has_tr_fraction=sum(has_tr==TRUE)/length(ID),
has_homo_tr_fraction=sum(has_homo_tr==TRUE)/length(ID),
has_micro_tr_fraction=sum(has_micro_tr==TRUE)/length(ID),
has_short_tr_fraction=sum(has_short_tr==TRUE)/length(ID),
has_domain_tr_fraction=sum(has_domain_tr==TRUE)/length(ID),
mean_sequence_length=mean(Length),
"Prot. count"=length(ID))
p = ggplot(sp, aes(x=mean_sequence_length, y=has_tr_fraction, colour=Superkingdom, size=log10(sp$`Prot. count`))) +
geom_abline(intercept=0, slope=mean(sp$has_tr_fraction)/mean(sp$mean_sequence_length), colour="grey")+
geom_point()+
geom_text_repel(aes(label = origin),
size = 6, # 5 showed no overlap
direction = c("both"),
box.padding = 1,
point.padding = 0.4,
segment.alpha = 0.5,
hjust = 0.7) +
scale_color_manual(values=cols1) +
scale_size_continuous(range=c(2,7),
name=expression(log[10](Prot.count)))+ #scale_colour_brewer(type=2, palette="RdYlBu")
# ggtitle('All tandem repeats')
labs(x="Mean Protein Length",
y="Proportion of TR",
size= expression(log[10](count)))
p = beautifier(p, x.axis.text.angle = 0)
p <- paper.figure(p, x.axis.text.angle = 0)
p
if( save) {
ggsave(paste0(pathImages, "Mean_Prot_length_vs_Frac_TR", figureFormat), width=12, height=8, dpi = 300)
}
```
#### Checking the outliers
```{r}
sp[which(sp$origin == "Mitochondrial (Viridiplantae)"),]
head(sp_all)
unique(sp_all$origin)
tr_all_sp[which(tr_all_sp$origin == "Mitochondrial (Viridiplantae)" & tr_all_sp$is_chloroplastic == TRUE & tr_all_sp$is_mitochondrial == TRUE),]
```
#### Percentage of TRs in all swissprot proteins by Species
Normalized by the number of available Proteins.
```{r}
# reproduce findings from above with different approach to eliminate logic error
has_tr_by_Spe = sp_all %>% # get all proteins with TRs
subset(has_tr == TRUE) %>%
group_by(Species) %>%
count(sort = TRUE)
sp_by_Spe = sp_all %>% # group all proteins (w/ and w/o TRs) by superkingdom
group_by(Species) %>%
count(sort = TRUE)
TR_frac_Spe = merge(x=sp_by_Spe, y=has_tr_by_Spe, by = "Species")
colnames(TR_frac_Spe) = c("Species", "total_number_of_prot", "prot_w_TR")
TR_frac_Spe$frac = TR_frac_Spe$prot_w_TR / TR_frac_Spe$total_number_of_prot # fraction/percentage of proteins with TRs
TR_frac_Spe$frac = round(TR_frac_Spe$frac, digits = 3)
TR_frac_Spe = TR_frac_Spe[order(TR_frac_Spe$frac, decreasing = TRUE),]
print(head(TR_frac_Spe))
highlight <- c("Homo sapiens (Human)", "Mus musculus (Mouse)", "Arabidopsis thaliana (Mouse-ear cress)", "Escherichia coli", "Saccharomyces cerevisiae (Baker's yeast)", "Dictyostelium discoideum (Slime mold)", "Drosophila melanogaster (Fruit fly)", "Caenorhabditis elegans","Danio rerio (Zebrafish) (Brachydanio rerio)")
TR_frac_Spe_highlight <- TR_frac_Spe[which(TR_frac_Spe$Species %in% highlight),]
print(TR_frac_Spe_highlight)
```
Make plot of highlights. x=sequence length, y=fract of Proteins with TRs
```{r}
#subset sp_all to get length of specific species
species_prot_length <- sp_all[which(sp_all$Species %in% highlight), ]
species_prot_length = ddply(species_prot_length, .(Species),
summarize,
mean_sequence_length=mean(Length))
# merge to one data frame with the TR_frac_Spe_highlight
TR_frac_Spe_highlight <- merge(x = TR_frac_Spe_highlight, y = species_prot_length, by = "Species")
# plot x=sequence length, y=fract of Proteins with TRs
p <- ggplot(TR_frac_Spe_highlight, aes(x = TR_frac_Spe_highlight$mean_sequence_length, y = TR_frac_Spe_highlight$frac))+ #TODO: colour by superkingdom
theme_classic()+
theme( text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
strip.text.x = element_text(family = "sans",angle = 0),
strip.text.y = element_text(family = "sans",angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans",angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans",margin=margin(1,1,2,1,"pt")),
axis.ticks.length = unit(0.05, "cm")) +
geom_point(size=3) +
# geom_text(aes(label=Species),hjust=0, vjust=0)+
# geom_text(aes(label=ifelse(PTS>24,as.character(Name),'')),hjust=0,vjust=0)+
geom_label_repel(aes(label = Species),
size = 6,
direction = c("both"),
box.padding = 1,
point.padding = 0.4,
segment.alpha = 0.5,
segment.color = 'grey50',
segment.size = 0.8,
label.size = 0) +
labs(x="Mean Protein Length",
y="Proportion of TR")
p = beautifier(p, x.axis.text.angle = 0)
p <- paper.figure(p, x.axis.text.angle = 0)
p
if( save) {
ggsave(paste0(pathImages, "Perc_TRs_all_sp_prots", figureFormat), width=12, height=8, dpi = 300)
}
```
#### distinct TR regions
subset proteins with more than one distinct TR region, sort them by superkingdom:
```{r}
distinct_region = ddply(tr_all_sp, .(Superkingdom),
summarize,
no_prots = round(length(ID), digits = 3),
no_unique_TRs = round(length(unique(ID)), digits = 3),
no_non_unique_TRs = round(length(ID) - length(unique(ID)), digits = 3),
ratio_unique_TRs = round(length(unique(ID))/length(ID), digits = 3),
ratio_non_unique_TRs = round(1-length(unique(ID))/length(ID), digits = 3)
)
print(distinct_region)
```
pick proteins with >= unique TR regions
```{r }
require(data.table)
# count how many TR per protein
many_unique = setDT(tr_all_sp)[,.N, by=ID]
print(many_unique[order(N, decreasing = T)])
# Left join to sp_all to add superkingdom information
sp_all_many_distinct <- merge(sp_all, many_unique, by = "ID")
print(sp_all_many_distinct[order(sp_all_many_distinct$N, decreasing = T), c(1,24)])
# eventually select only those with a certain amount of distinct TRs
df <- sp_all_many_distinct[which(sp_all_many_distinct$N >0),]
df <- df[order(df$Superkingdom),]
p <- ggplot(data = df, aes(x=df$ID, y=df$N, fill=df$Superkingdom))+
geom_col()+
scale_color_manual(values= cols1)+
ggtitle('Number of distinct TR per Protein coloured by Superkingdom')+
theme(text = element_text(),
legend.position = "bottom",
strip.text.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(x="Proteins",
y="Number of distinct TR")+
scale_fill_discrete(name=expression("Superkingdom")) +
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)
p = beautifier(p)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)
p <- paper.figure(p)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical",
axis.ticks.x = element_blank(),
axis.text.x = element_blank())
p
if( save) {
ggsave(paste0(pathImages, "distinct_TR_per_prot_by_superkingdom", figureFormat), width=12, height=8, dpi = 300)
}
```
It can be seen, that Eukaryotes have often different TRs per protein with some outliers.
```{r}
sp_all_many_distinct[which(sp_all_many_distinct$N >100),]
```
The two big peaks in the graph above are Mucin Proteins.
```{r}
sp_all_many_distinct[which(sp_all_many_distinct$N >50),]
```
Other proteins with many distinct TRs belong to structural and LRR-containing repeats.
If we look at the bacterial proteins
```{r}
sp_all_many_distinct[which(sp_all_many_distinct$Superkingdom == "Bacteria" & sp_all_many_distinct$N >25),]
```
we find many distinct TRs in pathogenesis associated proteins which are responsible for bacterial binding to platelets (Serine-rich adhesin for platelets) and to fibronectin (Extracellular matrix-binding protein ebh).
```{r}
sp_all_many_distinct[which(sp_all_many_distinct$Superkingdom == "Viruses" & sp_all_many_distinct$N >15),]
```
Viral proteins show many distinct TRs in nuclear antigen, transcription factor and structural proteins.
```{r}
sp_all_many_distinct[which(sp_all_many_distinct$Superkingdom == "Archaea" & sp_all_many_distinct$N >7),]
```
Archae show many distinct TRs in DNA break repair proteins and mucin.
## Sequence length in bins vs. fraction of TRs (Fig2a-2 (cnf. Fig 1b Marcotte et al.)
Show how sequence length and presence of TRs correlate.^
```{r, echo=TRUE}
sequence_length_bin <- with(sp_all, cut(Length, breaks = c(0, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1250, 1500, 2000, 50000), dig.lab=12))
sp <- ddply(sp_all, .(Superkingdom, sequence_length_bin),
summarise,
has_tr_fraction=sum(has_tr==TRUE)/length(ID),
has_homo_tr_fraction=sum(has_homo_tr==TRUE)/length(ID),
has_micro_tr_fraction=sum(has_micro_tr==TRUE)/length(ID),
has_short_tr_fraction=sum(has_short_tr==TRUE)/length(ID),
has_domain_tr_fraction=sum(has_domain_tr==TRUE)/length(ID),
n_proteins=length(ID))
sp$has_tr_fraction_binary_proportion_confidence_interval = sqrt(sp$has_tr_fraction*(1-sp$has_tr_fraction)/sp$n_proteins)
# Need to summarize data for blocks of "Length".
# For the error bars, see https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
p = ggplot(sp, aes(x=sequence_length_bin, y=has_tr_fraction, colour=Superkingdom)) +
geom_point(aes(size=0.5))+
geom_errorbar(aes(ymin=has_tr_fraction-has_tr_fraction_binary_proportion_confidence_interval,
ymax=has_tr_fraction+has_tr_fraction_binary_proportion_confidence_interval,
size=0.25),
width=0.3) +
scale_color_manual(values= cols1)+
# ggtitle('Tandem repeat appearance by protein sequence length and Superkingdom')+
theme(text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
legend.position = "bottom",
strip.text.x = element_text(family = "sans", angle = 0),
strip.text.y = element_text(family = "sans", angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans", angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans", margin=margin(1,1,2,1,"pt"))) +
labs(x="Protein Length",
y="Proportion of TR")
p = beautifier(p, x.axis.text.angle = 45, x.axis.text.hjust = 1)
p <- paper.figure(p, x.axis.text.angle = 45, x.axis.text.hjust = 1, x.axis.text.size = 22)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical")
p
if( save) {
ggsave(paste0(pathImages, "fig2a-2", figureFormat), width=12, height=8, dpi = 300)
}
```
```{r significance testing for sequence length vs fraction of TR}
bins <- c(100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1250, 1500, 2000, 50000)
print("Archaea:")
cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")$estimate[1]^2, 3)))
print("Bacteria:")
cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")$estimate[1]^2, 3)))
print("Eukaryota:")
cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")$estimate[1]^2, 3)))
print("Viruses:")
cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")$estimate[1]^2, 3)))
```
## TR length by superkingdom
```{r TR length by superkingdom}
tr_all_sp %>%
subset(has_tr == TRUE) %>%
group_by(Superkingdom) %>%
summarise(Mean_by_TR = sum(l_effective)/length(ID), # normalized by number of TRs
Mean_by_prot = sum(l_effective)/length(unique(ID))) # normalized by number of proteins
```
eukaryotes have on average the longest TRs.
```{r protein length by superkingdom}
sp_all %>%
group_by(Superkingdom) %>%
summarise(prot_length = sum(Length)/length(ID))
```
eukaryotes have second longest proteins. Viruses have longest proteins.
## Micro Tandem Repeats -> Supplementary (incl. small and domain)
```{r, echo=FALSE}
p = ggplot(sp, aes(x=sequence_length_bin, y=has_homo_tr_fraction, colour=Superkingdom))
p = p +
geom_point(aes(size=0.5))+
geom_errorbar(aes(ymin=has_homo_tr_fraction-has_tr_fraction_binary_proportion_confidence_interval,
ymax=has_homo_tr_fraction+has_tr_fraction_binary_proportion_confidence_interval,
size=0.25),
width=0.3) +
scale_color_manual(values= cols1)+
ggtitle('Homo Tandem Repeats')+
theme(text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
legend.position = "bottom",
strip.text.x = element_text(family = "sans", angle = 0),
strip.text.y = element_text(family = "sans", angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans", angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans", margin=margin(1,1,2,1,"pt"))) +
labs(x="Protein Length",
y="Proportion with homo TR")
p = beautifier(p, x.axis.text.angle = 45, x.axis.text.hjust = 1)
p <- paper.figure(p, x.axis.text.angle = 45, x.axis.text.hjust = 1, x.axis.text.size = 22)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical")
p
if( save) {
ggsave(paste0(pathImages, "fig2a-3", figureFormat), width=12, height=8, dpi = 300)
}
p = ggplot(sp, aes(x=sequence_length_bin, y=has_micro_tr_fraction, colour=Superkingdom))
p = p +
geom_point(aes(size=0.5))+
geom_errorbar(aes(ymin=has_micro_tr_fraction-has_tr_fraction_binary_proportion_confidence_interval,
ymax=has_micro_tr_fraction+has_tr_fraction_binary_proportion_confidence_interval,
size=0.25),
width=0.3) +
scale_color_manual(values= cols1)+
ggtitle('Micro Tandem Repeats')+
theme(text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
legend.position = "bottom",
strip.text.x = element_text(family = "sans", angle = 0),
strip.text.y = element_text(family = "sans", angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans", angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans", margin=margin(1,1,2,1,"pt"))) +
labs(x="Protein Length",
y="Proportion with micro TR")
p = beautifier(p, x.axis.text.angle = 45, x.axis.text.hjust = 1)
p <- paper.figure(p, x.axis.text.angle = 45, x.axis.text.hjust = 1, x.axis.text.size = 22)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical")
p
if( save) {
ggsave(paste0(pathImages, "fig2a-4", figureFormat), width=12, height=8, dpi = 300)
}
p = ggplot(sp, aes(x=sequence_length_bin, y=has_short_tr_fraction, colour=Superkingdom))
p = p +
geom_point(aes(size=0.5))+
geom_errorbar(aes(ymin=has_short_tr_fraction-has_tr_fraction_binary_proportion_confidence_interval,
ymax=has_short_tr_fraction+has_tr_fraction_binary_proportion_confidence_interval,
size=0.25),
width=0.3) +
scale_color_manual(values= cols1)+
ggtitle('Small Tandem Repeats')+
theme(text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
legend.position = "bottom",
strip.text.x = element_text(family = "sans", angle = 0),
strip.text.y = element_text(family = "sans", angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans", angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans", margin=margin(1,1,2,1,"pt"))) +
labs(x="Protein Length",
y="Proportion with small TR")
p = beautifier(p, x.axis.text.angle = 45, x.axis.text.hjust = 1)
p <- paper.figure(p, x.axis.text.angle = 45, x.axis.text.hjust = 1, x.axis.text.size = 22)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical")
p
if( save) {
ggsave(paste0(pathImages, "fig2a-5", figureFormat), width=12, height=8, dpi = 300)
}
p = ggplot(sp, aes(x=sequence_length_bin, y=has_domain_tr_fraction, colour=Superkingdom))
p = p +
geom_point(aes(size=0.5))+
geom_errorbar(aes(ymin=has_domain_tr_fraction-has_tr_fraction_binary_proportion_confidence_interval,
ymax=has_domain_tr_fraction+has_tr_fraction_binary_proportion_confidence_interval,
size=0.25),
width=0.3) +
scale_color_manual(values= cols1)+
ggtitle('Domain Tandem Repeats')+
theme(text = element_text(),
legend.text = element_text(family = "sans", face='italic', hjust=0),
legend.position = "bottom",
strip.text.x = element_text(family = "sans", angle = 0),
strip.text.y = element_text(family = "sans", angle = 270, margin = margin(r=30)),
axis.text.x = element_text(family = "sans", angle = 90, margin=margin(1,1,2,1,"pt")),
axis.text.y = element_text(family = "sans", margin=margin(1,1,2,1,"pt"))) +
labs(x="Protein Length",
y="Proportion with domain TR")
p = beautifier(p, x.axis.text.angle = 45, x.axis.text.hjust = 1)
p <- paper.figure(p, x.axis.text.angle = 45, x.axis.text.hjust = 1, x.axis.text.size = 22)+
guides(colour=guide_legend(override.aes = list(size = 1.5)),
size=FALSE)+
theme(legend.position = "bottom", legend.box = "vertical")
p
if( save) {
ggsave(paste0(pathImages, "fig2a-6", figureFormat), width=12, height=8, dpi = 300)
}
```
Fig. 2a-2) Shown is the fraction of TRs in the Superkingdoms as a function of protein sequence bins.
```{r significance testing for sequence length vs fraction of TR by TR-type}
bins <- c(100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1250, 1500, 2000, 50000)
print("--------------------------------------")
print("HOMO TRs:")
print("--------------------------------------")
print("Archaea:")
cor.test(bins, sp$has_homo_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")$estimate[1]^2, 3)))
print("Bacteria:")
cor.test(bins, sp$has_homo_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")$estimate[1]^2, 3)))
print("Eukaryota:")
cor.test(bins, sp$has_homo_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")$estimate[1]^2, 3)))
print("Viruses:")
cor.test(bins, sp$has_homo_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")$estimate[1]^2, 3)))
print("--------------------------------------")
print("--------------------------------------")
print("MICRO TRs:")
print("--------------------------------------")
print("Archaea:")
cor.test(bins, sp$has_micro_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")$estimate[1]^2, 3)))
print("Bacteria:")
cor.test(bins, sp$has_micro_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")$estimate[1]^2, 3)))
print("Eukaryota:")
cor.test(bins, sp$has_micro_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")$estimate[1]^2, 3)))
print("Viruses:")
cor.test(bins, sp$has_micro_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")$estimate[1]^2, 3)))
print("--------------------------------------")
print("--------------------------------------")
print("SMALL TRs:")
print("--------------------------------------")
print("Archaea:")
cor.test(bins, sp$has_short_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")$estimate[1]^2, 3)))
print("Bacteria:")
cor.test(bins, sp$has_short_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")$estimate[1]^2, 3)))
print("Eukaryota:")
cor.test(bins, sp$has_short_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")$estimate[1]^2, 3)))
print("Viruses:")
cor.test(bins, sp$has_short_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")$estimate[1]^2, 3)))
print("--------------------------------------")
print("--------------------------------------")
print("DOMAIN TRs:")
print("--------------------------------------")
print("Archaea:")
cor.test(bins, sp$has_domain_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Archaea")], method = "spearman")$estimate[1]^2, 3)))
print("Bacteria:")
cor.test(bins, sp$has_domain_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Bacteria")], method = "spearman")$estimate[1]^2, 3)))
print("Eukaryota:")
cor.test(bins, sp$has_domain_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Eukaryota")], method = "spearman")$estimate[1]^2, 3)))
print("Viruses:")
cor.test(bins, sp$has_domain_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")
print(paste("rho^2:", round(cor.test(bins, sp$has_tr_fraction[which(sp$Superkingdom == "Viruses")], method = "spearman")$estimate[1]^2, 3)))
print("--------------------------------------")
```
# Proteins with >= 4 distinct TR regions:
```{r}
# select proteins which have >4 distinct TR regions
many_distinct_regions = tr_all_sp %>% # take all TR,
count(ID) %>% # count how often a specific Prot. occurs in the list of all TRs,
filter(n >= 4) # take only those who appear >4 times -> have more than 4 distinct TRs
print(many_distinct_regions)
# index tr_all_sp to display only those with >4 distinct TR regions
tr_all_sp_many_distinct_regions <- tr_all_sp[which(tr_all_sp$ID %in% many_distinct_regions$ID), ]
### sorted by Superkingdom
sort_by_SK <- tr_all_sp_many_distinct_regions %>%
count(Superkingdom, sort = TRUE)
print(sort_by_SK)
# normalize by total number of total protein entries per Superkingdom
total_entries_per_SK <- tr_all_sp %>%
count(Superkingdom)
sort_by_SK <- merge(x= sort_by_SK , y= total_entries_per_SK, by = "Superkingdom")
sort_by_SK$norm <- sort_by_SK$n.x/sort_by_SK$n.y
sort_by_SK <- sort_by_SK[order(sort_by_SK$norm, decreasing = TRUE),]
print(head(sort_by_SK))
```
In Eukaryotes, 43% (90026 absolute count) of all
proteins with TRs had 4 (or more) distinct TR regions.
```{r}
### sorted by species
sort_by_species <- tr_all_sp_many_distinct_regions %>%
count(Species, sort = TRUE)
#total_entries_per_species[which(total_entries_per_species$Species == "Homo sapiens (Human)"),]
# normalize by total number of total protein entries per species
total_entries_per_species <- tr_all_sp %>%
count(Species)
sort_by_species <- merge(x= sort_by_species, y= total_entries_per_species, by = "Species")
# sort_by_species[which(sort_by_species$Species == "Homo sapiens (Human)"),]
sort_by_species$norm <- sort_by_species$n.x/sort_by_species$n.y
sort_by_species <- sort_by_species[order(sort_by_species$norm, decreasing = TRUE),]
print(head(sort_by_species))
```
The here listes species have in all collected Prots in Swissprot KB TRs with >4 distinct TRs.
```{r}
### Sorted by TR type all superkingdoms
total_TRs <- tr_all_sp %>%
count(has_tr, sort = TRUE)
many_distinct_regions_TR_overallfractions = ddply(tr_all_sp_many_distinct_regions, .(Superkingdom),
summarize,
has_tr_fraction=round(sum(has_tr==TRUE)/total_TRs$n, digits = 3), #not representative
has_homo_tr_fraction=round(sum(has_homo_tr==TRUE)/total_TRs$n, digits = 3),
has_micro_tr_fraction=round(sum(has_micro_tr==TRUE)/total_TRs$n, digits = 3),
has_short_tr_fraction=round(sum(has_short_tr==TRUE)/total_TRs$n, digits = 3),
has_domain_tr_fraction=round(sum(has_domain_tr==TRUE)/total_TRs$n, digits = 3))
print(many_distinct_regions_TR_overallfractions)
```
Of all eukaryotic proteins which have >=4 TRs, 21.5% are micro TRs, 22.6% are short TRs and 11.5% are domain TRs
```{r}
many_distinct_regions_TR_sum = ddply(tr_all_sp_many_distinct_regions, .(Superkingdom),
summarize,
has_tr_sum=sum(has_tr==TRUE),
has_homo_tr_sum=sum(has_homo_tr==TRUE),
has_micro_tr_sum=sum(has_micro_tr==TRUE),
has_short_tr_sum=sum(has_short_tr==TRUE),
has_domain_tr_sum=sum(has_domain_tr==TRUE))
print(many_distinct_regions_TR_sum)
```
the TR-types differe within the proteins containing >4 TRs. -> that's a possible reason that tr_sum has less counts than micro+short+domain TRs toghether. has_TR is True as soon as one of the other is TRUE.
```{r}
many_distinct_regions_TR_overallsum_unsplit <- colSums(as.data.frame(many_distinct_regions_TR_sum[,2:5]))
many_distinct_regions_TR_overallfractions_unsplit <- many_distinct_regions_TR_overallsum_unsplit[2:4]/many_distinct_regions_TR_overallsum_unsplit[1]
print(round(many_distinct_regions_TR_overallfractions_unsplit, digits = 3))