-
Notifications
You must be signed in to change notification settings - Fork 0
/
TFBS_report.Rmd
1787 lines (1368 loc) · 75.7 KB
/
TFBS_report.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: "What is going on with the binding site set?"
output:
html_document:
code_folding: hide
fig_caption: yes
highlight: zenburn
self_contained: yes
theme: cerulean
toc: yes
toc_depth: 3
toc_float: yes
# number_sections: true
date: '`r Sys.Date()`'
author: 'Claire Rioualen'
---
```{r setup, include = FALSE}
setwd(".")
knitr::opts_chunk$set(echo = TRUE, include = TRUE, warning = FALSE, message = FALSE, cache = FALSE, eval = TRUE, results = 'asis', fig.width=10, fig.height=7, fig.align = 'left')
#------------------
library(DT)
library(readxl)
library(tidyverse)
#------------------
library(gridExtra)
library(patchwork)
library(ggpubr)
#------------------
library(UpSetR)
library(ComplexUpset)
library(viridis)
# library(GGally)
library(cowplot)
library(plotly)
source(file = "utils.r")
dir_releases <- "_Databases/RegulonDB/releases"
dir_results <- "_Results"
```
# BindingSiteSet.txt {.tabset}
## Releases
Comparison of the BindingSiteSet.txt file between the last releases.
| Release version | Date |
|---------------------|----------------|
| 10.6 | 2019 July |
| 10.6.3 | - |
| 10.7 | 2020 April |
| 10.8 | 2020 October |
| 10.9 | 2021 April |
| 10.10 | 2022 February |
| 11.0 | 2022 August |
| 11.0.1 (not public) | 2022 September |
| 11.0.2 (not public) | 2022 September |
Notes:
* V10.6 excluded because it doesn't include TU_ID, only TU names which are not unique; otherwise it's almost the same as v10.7 which is included
* Some formatting is done in order to uniformize columns accross versions (uppercase/lowercase in confidence levels, word or symbol +- for strand and effect, etc)
* Starting v11.0.1 there are 2 evidence columns (site evidence and function evidence), here I merged them so I can compare with older versions
Comments on evidence and confidence issues:
* Version 10.6 did not include confirmed TFBS **error query? corregido por Cesar en la versión 10.7**
* Version 10.7 seems right
* Version 10.8 seem to have too many confirmed TFBSs: **erroneous cross-validations CV(SM) and CV(GEA) were added to all TFBS, sometimes even duplicated**
* Version 10.9 loses most evidence information: **?**
* Version 10.10 and 11.0 have mostly weak sites, and many NAs: **only function evidence is taken into account (not site)**
* Version 11.0.1 does not have confirmed TFBSs: **only site evidence is taken into account (not function)**
* Version 11.0.2 seems about right? **congruent with version 10.7**
```{r binding-sites-data-per-version}
## V10.6 excluded because it doesn't include TU_ID, only TU names which are not unique; otherwise it's almost the same as v10.7 which is included
## Some formatting is done in order to uniformize columns like strand and confidence (uppercase/lowercase, word or symbol +- for the strand, etc)
## Starting v11.0.1 there are 2 evidence columns, here I just merge them so I can compare with older versions
dir_versions <- c("10.7", "10.8", "10.9", "10.10", "11.0", "11.0.1", "11.0.2")
tfbs_sets <- list()
tfbs_versions <- c()
for(v in dir_versions){
version_tag <- paste0("v", v)
set <- read.delim(paste0(dir_releases, "/", v, "/BindingSiteSet.tsv"),
comment.char = "#", header = T, stringsAsFactors = F, na.strings = c("", "NA")) %>%
dplyr::mutate(version = version_tag) %>%
dplyr::mutate(strand = ifelse(strand == "reverse", "-", ifelse(strand == "forward", "+", NA))) %>%
dplyr::mutate(confidence = tolower(confidence)) %>%
dplyr::rowwise() %>%
dplyr::mutate(evidence = ifelse("evidence_function" %in% colnames(.), concat_uniq2(evidence, evidence_function), evidence)) %>%
dplyr::mutate(coords = paste0(start, "_", stop))
assign(paste0("tfbs_set_", version_tag), set)
tfbs_sets[[version_tag]] <- set
tfbs_versions <- c(tfbs_versions, version_tag)
}
all_tfbs <- bind_rows(tfbs_sets) %>%
dplyr::mutate(version = factor(version, levels = tfbs_versions)) %>%
dplyr::mutate(effect = factor(effect, levels = c("+", "-", "?"))) %>%
dplyr::mutate(confidence = factor(confidence, levels = c("weak", "strong", "confirmed")))
all_tfbs_by_evidence <- all_tfbs %>%
tidyr::separate_rows(evidence, sep = ",") %>%
dplyr::mutate(evidence = gsub("\\[|\\]", "", evidence)) %>% #,
tidyr::separate(evidence, c("evidence_code", "evidence_level", "evidence_name"), sep = "\\|")
```
## Overall number of TFBSs
```{r total-tfbs, fig.height=4, fig.width=6}
tfbs_summary <- all_tfbs %>%
dplyr::group_by(version) %>%
dplyr::summarise(total = n()) %>%
dplyr::arrange(version)
TFBS_num <- simple_bar(tfbs_summary, "version", "total") +
scale_fill_viridis(discrete = T) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "Release version", y = "Number of TFBSs", title = "")
TFBS_num
DT::datatable(tfbs_summary, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
Comments:
* Sudden increase with 488 new entries in version 10.9
## TFBS IDs
### TFBS IDs shared between versions
```{r tfbs-ids-upset}
tfbs_ids <- list()
for (v in tfbs_versions) {
tfbs_ids[[v]] <- unique( (get(paste0("tfbs_set_", v)))$TFBS_ID)
}
UpSetR::upset(fromList(tfbs_ids), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
queries = list(list(query = intersects, params = list("v10.7"), color = "red", active = T),
list(query = intersects, params = list("v10.7", "v10.8"), color = "red", active = T),
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T))
)
```
Comments:
* The oldest versions have **less** entries but **more** unique TFBS IDs
* 421 TFBS IDs **disappear** from version 10.8 until now (red bar)
* There are only 21 new IDs present in version 10.9 to 11.0.2 despite the sudden increase in total entries (blue bar)
### Duplicated TFBS IDs
```{r tfbs-ids-dupli}
tfbs_ids_dupli <- all_tfbs %>%
dplyr::group_by(version, TFBS_ID) %>%
dplyr::summarise(occurrences = n()) %>%
group_by(version, occurrences) %>%
summarise(tfbs_number = n())%>%
dplyr::mutate(occurrences = factor(occurrences))
###
dodge <- ggplot(tfbs_ids_dupli, aes(fill = occurrences, y = tfbs_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "", y = "Number of unique TFBS IDs", title = "TFBS ID duplication in BindingSiteSet.txt across versions")
dodge2 <- ggplot(tfbs_ids_dupli %>% dplyr::filter(!occurrences %in% c("1", "2", "3", "4")), aes(fill = occurrences, y = tfbs_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14),
legend.position = "none") +
labs(x = "", y = "Number of unique TFBS IDs", title = "...minimum 5 copies")
dodge / dodge2
```
### Which TFBS IDs are most duplicated?
```{r which-dupli-tfbs-id}
## TFBS IDs that have at least 10 entries in a given version
tfbs_ids_dupli_max <- all_tfbs %>%
dplyr::group_by(version, TFBS_ID) %>%
dplyr::summarise(occurrences = n()) %>%
dplyr::filter(occurrences >=10) %>%
dplyr::arrange(desc(occurrences)) %>%
pivot_wider(names_from = version,
values_from = c(occurrences))
DT::datatable(tfbs_ids_dupli_max, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## Coordinates
```{r coords-shared}
coordinates <- list()
for (v in tfbs_versions) {
coordinates[[v]] <- unique( (get(paste0("tfbs_set_", v)))$coords)
}
UpSetR::upset(fromList(coordinates), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
queries = list(
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8"), color = "red", active = T)
)
)
```
```{r coords-dupli}
coords_dupli <- all_tfbs %>%
dplyr::group_by(version, coords) %>%
dplyr::summarise(occurrences = n()) %>%
group_by(version, occurrences) %>%
summarise(coords_number = n())%>%
dplyr::mutate(occurrences = factor(occurrences))
###
dodge <- ggplot(coords_dupli, aes(fill = occurrences, y = coords_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "", y = "Number of unique TFBS IDs", title = "TFBS ID duplication in BindingSiteSet.txt across versions")
dodge2 <- ggplot(coords_dupli %>% dplyr::filter(!occurrences %in% c("1", "2", "3", "4")), aes(fill = occurrences, y = coords_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14),
legend.position = "none") +
labs(x = "", y = "Number of unique TFBS IDs", title = "...minimum 5 copies")
dodge / dodge2
```
### Which coordinates are most duplicated?
```{r which-dupli-coords}
## coords that have at least 10 entries in a given version
coords_dupli_max <- all_tfbs %>%
dplyr::group_by(version, coords) %>%
dplyr::summarise(occurrences = n()) %>%
dplyr::filter(occurrences >=10) %>%
dplyr::arrange(desc(occurrences)) %>%
pivot_wider(names_from = version,
values_from = c(occurrences))
DT::datatable(coords_dupli_max, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## Distance to TSS
```{r tfbs-dist-tss}
ggplot(all_tfbs, aes(x = distance_TSS, y = version, fill = version)) +
ggridges::geom_density_ridges(color = "white") +
ggridges::theme_ridges() +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme(legend.position = "none") +
xlim(-1000, 1000)
```
## Distance to first gene
```{r tfbs-dist-gene}
ggplot(all_tfbs, aes(x = distance_gene, y = version, fill = version)) +
ggridges::geom_density_ridges(color = "white") +
ggridges::theme_ridges() +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme(legend.position = "none") +
xlim(-1000, 1000)
```
## Effect
```{r tfbs-effect, fig.width=10}
tfbs_effect_long <- all_tfbs %>%
group_by(version, effect) %>%
summarise(value = n())
dodge <- ggplot(tfbs_effect_long, aes(fill = effect, y = value, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "", y = "Number of TFBS", title = "")
stack <- ggplot(tfbs_effect_long, aes(fill = effect, y = value, x = version)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "", y = "Number of TFBS", title = "")
line <- ggplot(tfbs_effect_long, aes(group = effect, y = value, x = version)) +
geom_line(aes(color = effect)) +
geom_point(size = 2, aes(color = effect)) +
scale_color_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "Release version", y = "Number of TFBS", title = "")
## ggplotly to make it interactive
# fig0 <- ggplotly(TFBS_num)
fig1 <- ggplotly(dodge)
fig2 <- ggplotly(stack)
fig3 <- ggplotly(line)
subplot(fig1, fig2, fig3, nrows=3)
```
```{r tfbs-effect-summary}
effect_summary <- all_tfbs %>%
group_by(version, effect) %>%
summarise(value = n()) %>%
data.frame() %>%
pivot_wider(names_from = version, values_from = c(value)) %>%
arrange(effect)
DT::datatable(effect_summary, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## Evidence
```{r tfbs-evidence}
tfbs_evidence_long <- all_tfbs_by_evidence %>%
group_by(version, evidence_code, evidence_name) %>%
summarise(value = n())
evidence_palette <- random_palette(length(unique(all_tfbs_by_evidence$evidence_code)))
##----
dodge <- ggplot(tfbs_evidence_long, aes(fill = evidence_code, y = value, x = version, group = evidence_name)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_manual(values = evidence_palette, drop = F, na.value = "gray") +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "", y = "Number of TFBSs", title = "")
stack <- ggplot(tfbs_evidence_long, aes(fill = evidence_code, y = value, x = version, group = evidence_name)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_manual(values = evidence_palette, drop = F, na.value = "gray") +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "", y = "Number of evidence", title = "")
line <- ggplot(tfbs_evidence_long, aes(group = evidence_name, y = value, x = version)) +
geom_line(aes(color = evidence_code)) +
scale_color_manual(values = evidence_palette, drop = F, na.value = "gray") +
geom_point(size = 2, aes(color = evidence_code)) +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "Release version", y = "Number of TFBS", title = "")
fig0 <- ggplotly(TFBS_num)
fig1 <- ggplotly(dodge)
fig2 <- ggplotly(stack)
fig3 <- ggplotly(line)
subplot(fig0, fig1, fig2, fig3, nrows=4)
```
```{r tfbs-evidence-table}
tfbs_evidence_table <- all_tfbs_by_evidence %>%
group_by(evidence_code, evidence_name) %>%
summarise(version = concat_uniq(version))
DT::datatable(tfbs_evidence_table, rownames= FALSE, options = list(searching = TRUE, lengthChange = FALSE, pageLength = 10))
```
```{r tfbs-evidence-upset}
tfbs_evidence_shared <- list()
for (v in tfbs_versions) {
tfbs_evidence_shared[[v]] <- unique((all_tfbs_by_evidence %>% dplyr::filter(version == v))$evidence_code)
}
UpSetR::upset(fromList(tfbs_evidence_shared), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
# queries = list(list(query = intersects, params = list("v10.7"), color = "red", active = T),
# list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T))
)
## Revise congruency between table and upset plot (table has CE listed as only present in 10.8, shjould have 10.7 too)
```
## Confidence
```{r tfbs-confidence, fig.width=10}
tfbs_confidence_long <- all_tfbs %>%
group_by(version, confidence) %>%
summarise(value = n())
dodge <- ggplot(tfbs_confidence_long, aes(fill = confidence, y = value, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "", y = "Number of TFBS", title = "")
stack <- ggplot(tfbs_confidence_long, aes(fill = confidence, y = value, x = version)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "", y = "Number of TFBS", title = "")
line <- ggplot(tfbs_confidence_long, aes(group = confidence, y = value, x = version)) +
geom_line(aes(color = confidence)) +
geom_point(size = 2, aes(color = confidence)) +
scale_color_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "Release version", y = "Number of TFBS", title = "")
## ggplotly to make it interactive
# fig0 <- ggplotly(TFBS_num)
fig1 <- ggplotly(dodge)
fig2 <- ggplotly(stack)
fig3 <- ggplotly(line)
subplot(fig1, fig2, fig3, nrows=3)
```
```{r evidence-level-tfbs-ta2b}
confidence_summary <- all_tfbs %>%
group_by(version, confidence) %>%
summarise(value = n()) %>%
mutate(confidence = ifelse(is.na(confidence), "null", as.character(confidence))) %>%
data.frame() %>%
pivot_wider(names_from = version, values_from = c(value)) %>%
mutate(across(starts_with('v'), ~replace_na(.,0))) %>%
bind_rows(summarise(.,
across(where(is.numeric), sum),
across(where(is.character), ~"total"))) %>%
mutate(confidence = factor(confidence, levels = c("weak", "strong", "confirmed", "null", "total"))) %>%
arrange(confidence)
DT::datatable(confidence_summary, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## RI IDs
```{r ri-ids-mapping}
ri_ids <- list()
for (v in tfbs_versions) {
ri_ids[[v]] <- unique( (get(paste0("tfbs_set_", v)))$RI_ID)
}
UpSetR::upset(fromList(ri_ids), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
queries = list(
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9", "v10.10"), color = "red", active = T),
list(query = intersects, params = list("v10.7", "v10.8"), color = "red", active = T)
)
)
```
### Duplicate RI IDs
```{r ris-ids-dupli}
ris_ids_dupli <- all_tfbs %>%
dplyr::group_by(version, RI_ID) %>%
dplyr::summarise(occurrences = n()) %>%
group_by(version, occurrences) %>%
summarise(ris_number = n())%>%
dplyr::mutate(occurrences = factor(occurrences))
###
dodge <- ggplot(ris_ids_dupli, aes(fill = occurrences, y = ris_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "", y = "Number of unique RI IDs", title = "RI ID duplication in BindingSiteSet.txt across versions")
dodge2 <- ggplot(ris_ids_dupli %>% dplyr::filter(!occurrences %in% c("1")), aes(fill = occurrences, y = ris_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14),
legend.position = "none") +
labs(x = "", y = "Number of unique RI IDs", title = "...minimum 2 copies")
dodge / dodge2
```
## TFs
```{r tfs-shared, fig.height = 6}
tf_ids <- list()
for (v in tfbs_versions) {
tf_ids[[v]] <- unique( (get(paste0("tfbs_set_", v)))$TF_ID)
}
UpSetR::upset(fromList(tf_ids), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TF IDs",
queries = list(
list(query = intersects, params = list("v10.8", "v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T),
list(query = intersects, params = list("v10.7"), color = "red", active = T))
)
tf_ids_gone <- rownames(fromList(tf_ids) %>% filter(v10.7 == 1 & v11.0.2 == 0))
tf_names <- list()
for (v in tfbs_versions) {
tf_names[[v]] <- unique( (get(paste0("tfbs_set_", v)))$TF_name)
}
UpSetR::upset(fromList(tf_names), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TF names",
queries = list(
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
tf_names_gone <- rownames(fromList(tf_names) %>% filter(v10.7 == 1 & v11.0.2 == 0))
```
* 5 TF ID disappear: `r tf_ids_gone` (red)
* 2 TF names disappear: `r tf_names_gone` (red)
## Promoters
```{r promoter-shared}
promoter_name <- list()
for (v in tfbs_versions) {
promoter_name[[v]] <- unique( (get(paste0("tfbs_set_", v)))$promoter)
}
UpSetR::upset(fromList(promoter_name), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique promoter names",
queries = list(
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
```
## TUs
```{r tus-shared, fig.height = 6}
tu_ids <- list()
for (v in tfbs_versions) {
tu_ids[[v]] <- unique( (get(paste0("tfbs_set_", v)))$TU_ID)
}
UpSetR::upset(fromList(tu_ids), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TU IDs",
queries = list(
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
tu_names <- list()
for (v in tfbs_versions) {
tu_names[[v]] <- unique( (get(paste0("tfbs_set_", v)))$TU_name)
}
UpSetR::upset(fromList(tu_names), sets = tfbs_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TU names",
queries = list(
list(query = intersects, params = list("v10.8", "v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
```
## Mapping v10.7 vs v11.0.2
Notes:
* TFBSs from v10.7 and v11.0.2 are mapped by **TFBS_ID** and **promoter** name
* TFBS_IDs are not unique, eg. a given TFBS_ID can be associated with several promoters and TUs
* Some RI_IDs seem to have changed, all other parameters equal (ex. seems like Fis TFBS_ID ECK120011288 was associated with RI_ID ECK120034675, now ECK125300661)
* Older versions of BindingSiteSet.txt did not come with a TU_ID column, and TU_name is not unique, and is sometimes missing
The following table displays the differences.
**Many (most?) differences seem to be caused by different promoter names**
Ex.
* in 10.7 micFp is regulated by Lrp (TFBS ID ECK120011644)
* in 11.0.2 micFp1 and micFp2 are both regulated by the same TF and TFBS, and are linked to 2 distinct TUs (both TUs are named micF but have distinct IDs)
* **all three entries have the same evidence**
```{r tfbs-mapping}
## Join versions 10.7 and 11.0.2 by TFBS_ID and promoter name
tfbs_join_107_1102 <- tfbs_set_v10.7 %>%
dplyr::full_join(tfbs_set_v11.0.2, by = c("TFBS_ID", "promoter"), suffix = c("_10.7", "_11.0.2")) %>%
dplyr::arrange(TFBS_ID) %>%
dplyr::select(TFBS_ID, promoter, starts_with("TF_name"), starts_with("TU"), starts_with("coords"), starts_with("evidence_1"), starts_with("confidence"))
# select(TFBS_ID, promoter, everything())
tfbs_matches_107_1102 <- tfbs_join_107_1102 %>% na.omit
tfbs_differences_107_1102 <- dplyr::setdiff(tfbs_join_107_1102, tfbs_matches_107_1102)
write.table(tfbs_join_107_1102, file = paste0(dir_results, "/TFBS_full_join_107_1102.tsv"), quote = F, row.names = F, col.names = T, sep = "\t")
write.table(tfbs_differences_107_1102, file = paste0(dir_results, "/TFBS_differences_107_1102.tsv"), quote = F, row.names = F, col.names = T, sep = "\t")
DT::datatable(tfbs_differences_107_1102, rownames= FALSE, options = list(searching = TRUE, lengthChange = FALSE, pageLength = 5,
columnDefs = list(list(width = '200px', targets = c(11,12)))
))
```
<!-- These are the entries that appear after version 10.8: -->
```{r tfbs-frfom-10-9, eval = F, include = F}
tfbs_new_from_10.9 <- all_tfbs_RI_TU %>%
dplyr::filter(is.na(evidence_10.6) & is.na(confidence_10.6) &
is.na(evidence_10.6.3) & is.na(confidence_10.6.3) &
is.na(evidence_10.7) & is.na(confidence_10.7) &
is.na(evidence_10.8) & is.na(confidence_10.8))
write.table(tfbs_new_from_10.9, file = "TFBS_new_10.9.tsv", quote = F, row.names = F, col.names = T, sep = "\t")
# DT::datatable(tfbs_new_from_10.9, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 5))
```
<!-- These are the entries that are "confirmed" in version 10.8: -->
```{r tfbs-confirmed-10-8, eval = F, include = F}
tfbs_confirmed_10.8 <- all_tfbs_RI_TU %>%
dplyr::filter(confidence_10.8 == "Confirmed")
write.table(tfbs_confirmed_10.8, file = "TFBS_confirmed_10.8.tsv", quote = F, row.names = F, col.names = T, sep = "\t")
# DT::datatable(tfbs_confirmed_10.8, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 5))
```
# network_tf_gene.txt {.tabset}
```{r network-tf-gene-data1}
dir_versions <- c("10.6.3", "10.7", "10.8", "10.9", "11.0", "11.0.1")
tfgnw_sets <- list()
tfgnw_versions <- c()
for(v in dir_versions){
version_tag <- paste0("v", v)
set <- read.delim(paste0(dir_releases, "/", v, "/network_tf_gene.tsv"),
comment.char = "#", header = T, stringsAsFactors = F, na.strings = c("", "NA")) %>%
dplyr::mutate(effect = ifelse(effect == "repressor", "-", ifelse(effect == "activator", "+", ifelse(effect == "unknown", "?", effect)))) %>%
dplyr::mutate(version = version_tag) %>%
dplyr::rowwise() %>%
dplyr::mutate(evidence = ifelse("evidence_function" %in% colnames(.), concat_uniq2(evidence, evidence_function), evidence)) %>%
dplyr::mutate(pairs = paste0(TF_name, "_", gene_name))
assign(paste0("tfgnw_set_", version_tag), set)
tfgnw_sets[[version_tag]] <- set
tfgnw_versions <- c(tfgnw_versions, version_tag)
}
all_tfgnw <- bind_rows(tfgnw_sets) %>%
dplyr::mutate(version = factor(version, levels = tfgnw_versions)) %>%
dplyr::mutate(effect = factor(effect, levels = c("+", "-", "?"))) %>%
dplyr::mutate(confidence = tolower(confidence)) %>%
dplyr::mutate(confidence = factor(confidence, levels = c("weak", "strong", "confirmed")))
all_tfgnw_by_evidence <- all_tfgnw %>%
tidyr::separate_rows(evidence, sep = ",") %>%
dplyr::mutate(evidence = trimws(gsub("\\[|\\]", "", evidence))) %>%
dplyr::mutate(evidence_code = "",
evidence_level = "",
evidence_name = "") %>%
dplyr::rowwise() %>%
dplyr::mutate(evidence_code = ifelse(grepl("\\|", evidence), stringr::str_split(evidence, "\\|")[[1]][1], evidence),
evidence_level = ifelse(grepl("\\|", evidence), stringr::str_split(evidence, "\\|")[[1]][2], NA),
evidence_name = ifelse(grepl("\\|", evidence), stringr::str_split(evidence, "\\|")[[1]][3], NA)
)
```
**NB: additional TAB characters at the end of each line cause parsing issues**
## Releases
Comparison of the network_tf_gene.txt file between the last releases.
| Release version | Date |
|---------------------|----------------|
| 10.6 (NA) | 2019 July |
| 10.6.3 | - |
| 10.7 | 2020 April |
| 10.8 | 2020 October |
| 10.9 | 2021 April |
| 10.10 (NA) | 2022 February |
| 11.0 | 2022 August |
| 11.0.1 (not public) | 2022 September |
```{r total-tfgnw, fig.height=4, fig.width=6}
tfgnw_summary <- all_tfgnw %>%
dplyr::group_by(version) %>%
dplyr::summarise(total = n()) %>%
dplyr::arrange(version)
tfgnw_num <- simple_bar(tfgnw_summary, "version", "total") +
scale_fill_viridis(discrete = T) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "Release version", y = "Number of TF-gene entries", title = "")
tfgnw_num
DT::datatable(tfgnw_summary, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## TF-gene pairs
```{r pairs-shared}
pairs <- list()
for (v in tfgnw_versions) {
pairs[[v]] <- unique( (get(paste0("tfgnw_set_", v)))$pairs)
}
UpSetR::upset(fromList(pairs), sets = tfgnw_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
# queries = list(
# list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T),
# list(query = intersects, params = list("v10.7", "v10.8"), color = "red", active = T)
# )
)
```
```{r pairs-dupli}
coords_dupli <- all_tfgnw %>%
dplyr::group_by(version, pairs) %>%
dplyr::summarise(occurrences = n()) %>%
group_by(version, occurrences) %>%
summarise(pairs_number = n())%>%
dplyr::mutate(occurrences = factor(occurrences))
###
dodge <- ggplot(coords_dupli, aes(fill = occurrences, y = pairs_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14)) +
labs(x = "", y = "Number of unique TF-gene pairs", title = "TF-gene pairs duplication in network_tf_gene.txt across versions")
dodge2 <- ggplot(coords_dupli %>% dplyr::filter(!occurrences %in% c("1", "2", "3", "4")), aes(fill = occurrences, y = pairs_number, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14),
legend.position = "none") +
labs(x = "", y = "Number of unique TF-gene pairs", title = "...minimum 5 copies")
dodge / dodge2
```
### Which pairs are most duplicated?
```{r which-dupli-pairs}
## pairs that have at least 10 entries in a given version
pairs_dupli_max <- all_tfgnw %>%
dplyr::group_by(version, pairs) %>%
dplyr::summarise(occurrences = n()) %>%
dplyr::filter(occurrences >=10) %>%
dplyr::arrange(desc(occurrences)) %>%
pivot_wider(names_from = version,
values_from = c(occurrences))
DT::datatable(pairs_dupli_max, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## TFs
```{r tfs-shared-tfgnw}
tf_names <- list()
for (v in tfgnw_versions) {
tf_names[[v]] <- unique( (get(paste0("tfgnw_set_", v)))$TF_name)
}
UpSetR::upset(fromList(tf_names), sets = tfgnw_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TF names",
# queries = list(list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
```
## Genes
```{r genes-shared-tfgnw}
gene_names <- list()
for (v in tfgnw_versions) {
gene_names[[v]] <- unique( (get(paste0("tfgnw_set_", v)))$gene_name)
}
UpSetR::upset(fromList(gene_names), sets = tfgnw_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
sets.x.label = "Number of unique TF names",
# queries = list(list(query = intersects, params = list("v10.7", "v10.8", "v10.9"), color = "red", active = T))
)
```
## Effect
```{r tfgnw-effect, fig.width=10}
tfgnw_effect_long <- all_tfgnw %>%
group_by(version, effect) %>%
summarise(value = n())
dodge <- ggplot(tfgnw_effect_long, aes(fill = effect, y = value, x = version)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "", y = "Number of tfgnw", title = "")
stack <- ggplot(tfgnw_effect_long, aes(fill = effect, y = value, x = version)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "", y = "Number of tfgnw", title = "")
line <- ggplot(tfgnw_effect_long, aes(group = effect, y = value, x = version)) +
geom_line(aes(color = effect)) +
geom_point(size = 2, aes(color = effect)) +
scale_color_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "Release version", y = "Number of tfgnw", title = "")
## ggplotly to make it interactive
# fig0 <- ggplotly(tfgnw_num)
fig1 <- ggplotly(dodge)
fig2 <- ggplotly(stack)
fig3 <- ggplotly(line)
subplot(fig1, fig2, fig3, nrows=3)
```
```{r tfgnw-effect-summary}
effect_summary <- all_tfgnw %>%
group_by(version, effect) %>%
summarise(value = n()) %>%
data.frame() %>%
pivot_wider(names_from = version, values_from = c(value)) %>%
arrange(effect)
DT::datatable(effect_summary, rownames= FALSE, options = list(searching = FALSE, lengthChange = FALSE, pageLength = 10))
```
## Evidence
```{r tfgnw-evidence}
tfgnw_evidence_long <- all_tfgnw_by_evidence %>%
group_by(version, evidence_code) %>%
summarise(value = n(), evidence_name = concat_uniq(evidence_name)) ## ojo que solo la 11.0.1 tiene evidence name
evidence_palette <- random_palette(length(unique(all_tfgnw_by_evidence$evidence_code)))
##----
dodge <- ggplot(tfgnw_evidence_long, aes(fill = evidence_code, y = value, x = version, group = evidence_code)) +
geom_bar(position = position_dodge(preserve = "single"), stat = "identity") +
scale_fill_manual(values = evidence_palette, drop = F, na.value = "gray") +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "right") +
labs(x = "", y = "Number of tfgnws", title = "")
stack <- ggplot(tfgnw_evidence_long, aes(fill = evidence_code, y = value, x = version, group = evidence_code)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_manual(values = evidence_palette, drop = F, na.value = "gray") +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "", y = "Number of evidence", title = "")
line <- ggplot(tfgnw_evidence_long, aes(group = evidence_code, y = value, x = version)) +
geom_line(aes(color = evidence_code)) +
scale_color_manual(values = evidence_palette, drop = F, na.value = "gray") +
geom_point(size = 2, aes(color = evidence_code)) +
# scale_fill_viridis(discrete = T, na.value = "gray", drop = F) +
theme_minimal() +
theme(axis.text = element_text(size = 14), axis.title.y = element_text(size = 14), title = element_text(size = 14), legend.position = "none") +
labs(x = "Release version", y = "Number of tfgnw", title = "")
fig0 <- ggplotly(tfgnw_num)
fig1 <- ggplotly(dodge)
fig2 <- ggplotly(stack)
fig3 <- ggplotly(line)
subplot(fig0, fig1, fig2, fig3, nrows=4)
```
```{r tfgnw-evidence-table}
tfgnw_evidence_table <- all_tfgnw_by_evidence %>%
group_by(evidence_code) %>%
summarise(value = n(), evidence_name = concat_uniq(evidence_name), version = concat_uniq(version)) ## ojo que solo la 11.0.1 tiene evidence name
DT::datatable(tfgnw_evidence_table, rownames= FALSE, options = list(searching = TRUE, lengthChange = FALSE, pageLength = 10))
## to do remove empty string from evidence table
```
```{r tfgnw-evidence-upset}
tfgnw_evidence_shared <- list()
for (v in tfgnw_versions) {
tfgnw_evidence_shared[[v]] <- unique((all_tfgnw_by_evidence %>% dplyr::filter(version == v))$evidence_code)
}
UpSetR::upset(fromList(tfgnw_evidence_shared), sets = tfgnw_versions, order.by = "freq", keep.order = T,
text.scale = c(2,2,2,2,2,2),
# queries = list(list(query = intersects, params = list("v10.7"), color = "red", active = T),
# list(query = intersects, params = list("v10.9", "v10.10", "v11.0", "v11.0.1", "v11.0.2"), color = "blue", active = T))
)
## Revise congruency between table and upset plot (table has CE listed as only present in 10.8, shjould have 10.7 too)
```
## Confidence
```{r tfgnw-confidence, fig.width=10}
tfgnw_confidence_long <- all_tfgnw %>%
group_by(version, confidence) %>%
summarise(value = n())