/
statistical_analysis.Rmd
3094 lines (2655 loc) · 120 KB
/
statistical_analysis.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: "statistical_analysis"
author: "MartinGarlovsky"
date: "2021-04-01"
output:
workflowr::wflow_html:
code_folding: hide
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```
### Load packages
```{r}
library(tidyverse)
library(UpSetR)
library(eulerr)
library(readxl)
library(tidybayes)
library(kableExtra)
library(ggpubr)
library(edgeR)
library(pheatmap)
library(ComplexHeatmap)
library(boot)
library(DT)
library(pals)
library(knitrhooks) # install with devtools::install_github("nathaneastwood/knitrhooks")
output_max_height() # a knitrhook option
# set colourblind friendly palette
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
my_data_table <- function(df){
datatable(
df, rownames = FALSE,
autoHideNavigation = TRUE,
extensions = c("Scroller", "Buttons"),
options = list(
dom = 'Bfrtip',
deferRender = TRUE,
scrollX = TRUE, scrollY = 400,
scrollCollapse = TRUE,
buttons =
list('csv', list(
extend = 'pdf',
pageSize = 'A4',
orientation = 'landscape',
filename = 'Dpseudo_respiration')),
pageLength = 50
)
)
}
```
### Load data
* Files downloaded from [FlyBase.org](http://flybase.org/):
+ Genes to Transcript to Protein IDs
+ Gene names and gene symbols, GO terms, chromosomal location (`LOCATION_ARM`)
+ [All 168 ribosomal proteins, including paralogs](https://flybase.org/reports/FBgg0000130.html)
* List of all putative Sfps identified by [Wigby et al. (2020). *Phil. trans. B*](https://royalsocietypublishing.org/doi/10.1098/rstb.2020.0072)
* Previous *D. melanogaster* sperm proteomes:
+ [DmSP1](http://www.nature.com/articles/ng1915)
+ [DmSP2](http://www.sciencedirect.com/science/article/pii/S1874391910002538), comprising 1108 proteins, combined with the DmSP1
* New data generated:
+ Experiment 1: All identified proteins and abundance data
+ Experiment 2: Abundance data for proteins from 'NoHalt', 'Halt' controls or 'PBST' treatment
+ Experiment 3: Abundance data for proteins from 'PBS' control or 'NaCl' treatment
```{r}
# gene conversion table from FlyBase.org
gene2tran2prot <- read.csv('data/FlyBase/fbgn_fbtr_fbpp_fb_2021_01.csv')
# gene IDs and GO terms (by importing gene conversion table FBgns to flybase)
flybase_results <- read.delim('data/FlyBase/flybase_all-genes.csv', sep = ',') %>%
dplyr::select(-H_SAPIENS_ORTHOLOGS, -NAME) %>%
dplyr::rename(FBgn = X.SUBMITTED.ID)
# Dmel ribosomes - all and those found in sperm
Dm_ribosomes <- read_delim('data/FlyBase/FlyBase_ribosomes_169.txt') %>%
dplyr::select(FBgn = `#SUBMITTED ID`, H_SAPIENS_ORTHOLOGS:SYMBOL, -SPECIES_ABBREVIATION)
# List of SFPs collated by Wigby et al. 2020 Phil. Trans. B.
wigbySFP <- read.csv('data/dmel_SFPs_wigby_etal2020.csv')
# only high confidence Sfps
SFPs <- wigbySFP %>%
filter(category == 'highconf')
# Dmel Sperm proteome 1/2 from Wasbrough et al. 2010 J. Prot.
DmSPI <- read.csv('data/DmSPii_Supp.Table3.csv') %>%
filter(Proteome.Overlap == 'DmSPI' | Proteome.Overlap == 'Current Study and DmSPI')
DmSPII <- read.csv('data/DmSPii_Supp.Table3.csv') %>%
filter(Proteome.Overlap == 'Current Study' | Proteome.Overlap == 'Current Study and DmSPI')
DmSP2 <- read.csv('data/DmSPii_Supp.Table3.csv')
### new data ###
DmSPIII <- read_excel('data/DmSP3_Xlinked_Ribosomes.xlsx', sheet = 1) %>%
dplyr::rename(CG.no = `CG#`)
# Protein abundance data
DmSPintensity <- read_excel('data/KB_10MSE_sperm_Edited.xlsx', sheet = 1) %>%
dplyr::rename(FBgn = `Ensembl Gene ID`)
# Halt/NoHalt/PBST treatment experiment
PBST_dat <- readxl::read_excel('data/Halt_NoHalt_PBST.xlsx') %>%
left_join(read_csv('data/HaltNohaltPBST_uniprot.csv')) %>%
left_join(read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt'),
by = c('FBgn' = 'X.SUBMITTED.ID')) %>%
distinct(Accession, .keep_all = TRUE)
# NaCl wash data
salt_dat <- read.csv('data/040721_PBS_NaCl_1PeptideLFQ.csv',
na.strings = c("NA", "NaN", " ", '')) %>%
dplyr::rename(FBgn = Ensembl.Gene.ID)
```
### Overlap between new datasets
We performed three LC-MS experiments on purified sperm samples. For experiment 1, we combine the IDs from two algorithms (i) identifying proteins and (ii) from protein quantitation. We then combine all IDs across the three experiments to compile a complete list of all proteins IDd in the current study.
```{r, fig.height=4, fig.width=4}
### Additional abundance data
# Data processed for identification was processed separately for quantification. Differences in algorithms results in a slight disparity in the number of protein identifications.
ab_fbgn <- data.frame(FBgn = unlist(str_split(DmSPintensity$FBgn, pattern = '; '))) %>% na.omit()
# upset(fromList(list(DmSPIII.id = DmSPIII$FBgn,
# DmSPIII.ab = ab_fbgn$FBgn)))
# proteins IDd in DmSP3 (identification + abundance data)
DmSP_exp1 <- data.frame(FBgn = unique(c(DmSPIII$FBgn, ab_fbgn$FBgn))) %>%
left_join(flybase_results %>% dplyr::select(FBgn, SYMBOL))
## compare ids in each dataset
# upset(fromList(list(exp1 = DmSP_exp1$FBgn,
# PBST = PBST_dat$FBgn,
# Salt = salt_dat$FBgn)))
# euler diagram
#pdf('figures/current_study_overlap.pdf', height = 4, width = 4)
plot(euler(c('exp1' = 392, "exp2" = 247, "exp3" = 416,
'exp1&exp2' = 74,
'exp1&exp3' = 169,
'exp2&exp3' = 240,
'exp1&exp2&exp3' = 1009)
),
quantities = TRUE,
fills = list(fill = viridis::plasma(n = 3), alpha = .5))
#dev.off()
# combine all new data
DmSPIII.2 <- data.frame(FBgn = unique(
c(DmSP_exp1$FBgn, PBST_dat$FBgn, salt_dat$FBgn))) %>%
separate_rows(FBgn) %>%
left_join(flybase_results %>% dplyr::select(FBgn, SYMBOL)) %>%
distinct(FBgn, .keep_all = TRUE)
```
## Overlap between DmSP-1, -2, and -3 {.tabset}
Here we look at the overlap between proteins IDd in the current study (n = `r nrow(DmSPIII.2)`) with the previous releases of the DmSP (n = `r nrow(DmSP2)`. The current study increases the number of identified proteins significantly.
### DmSP1 vs. DmSP2 vs. DmSP3
```{r, fig.height=3, fig.width=3}
# upset plot to get numbers in each group
listInput <- list(DmSP.1 = DmSPI$FBgn,
DmSP.2 = DmSPII$FBgn,
DmSP.3 = DmSPIII.2$FBgn)
#upset(fromList(listInput), order.by = 'degree')
# Eulerr diagram
DmSP_overlap <- plot(euler(c('DmSP1' = 68, "DmSP2" = 538, "Current Study" = 2069,
'DmSP1&DmSP2' = 8,
'DmSP1&Current Study' = 84,
'DmSP2&Current Study' = 229,
'DmSP1&DmSP2&Current Study' = 181)),
quantities = TRUE,
fills = list(fill = viridis::viridis(n = 3), alpha = .5))
#pdf('figures/DmSP1-2-3_overlap.pdf', height = 4, width = 4)
DmSP_overlap
#dev.off()
# extract genes in each category
x <- upset(fromList(listInput))
intersect_dat <- x$New_data %>% rownames_to_column()
x1 <- unlist(listInput, use.names = FALSE)
x1 <- x1[ !duplicated(x1) ]
# in all 3
all_3 <- intersect_dat %>% filter(DmSP.1 == 1, DmSP.2 == 1, DmSP.3 == 1)
# in 1 and 2
in1_2 <- intersect_dat %>% filter(DmSP.1 == 1, DmSP.2 == 1, DmSP.3 == 0)
# in 1 and 3
in1_3 <- intersect_dat %>% filter(DmSP.1 == 1, DmSP.2 == 0, DmSP.3 == 1)
# in 2 and 3
in2_3 <- intersect_dat %>% filter(DmSP.1 == 0, DmSP.2 == 1, DmSP.3 == 1)
# 1 only
only1 <- intersect_dat %>% filter(DmSP.1 == 1, DmSP.2 == 0, DmSP.3 == 0)
# 1 only
only2 <- intersect_dat %>% filter(DmSP.1 == 0, DmSP.2 == 1, DmSP.3 == 0)
# 1 only
only3 <- intersect_dat %>% filter(DmSP.1 == 0, DmSP.2 == 0, DmSP.3 == 1)
```
### Cumulative number ID'd
Here we combine the list of all proteins identified in the current study with the DmSP2 to compile the DmSP3. We calculated average abundances across experiments, excluding the PBST treatment values, which had a significant effect on the abundance of a large number of proteins ([see below](#PBST)). We also create our ‘high-confidence’ DmSP3, excluding proteins identified by fewer than 2 unique peptides or identified in fewer than 2 biological replicates across all experiments.
```{r, fig.height=3, fig.width=3}
# new column names for abundance data
exp_names <- c('REP1.1', 'REP1.2', 'REP1.3',
'Halt1', 'Halt2', 'Halt3',
'NoHalt1', 'NoHalt2', 'NoHalt3',
'NaCl1.1', 'NaCl1.2', 'NaCl2.1', 'NaCl2.2',
'NaCl3.1', 'NaCl3.2', 'NaCl4.1', 'NaCl4.2',
'PBS1.1', 'PBS1.2', 'PBS2.1', 'PBS2.2',
'PBS3.1', 'PBS3.2', 'PBS4.1', 'PBS4.2',
'NaCl1', 'NaCl2', 'NaCl3', 'NaCl4',
'PBS1', 'PBS2', 'PBS3', 'PBS4')
# Make the combined DmSP table
DmSP3 <- tibble(
# combine IDs for DmSP1, DmSP2, and current study
FBgn = c(DmSPI$FBgn, DmSPII$FBgn, DmSPIII.2$FBgn)) %>%
left_join(read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt'),
by = c('FBgn' = 'X.SUBMITTED.ID')) %>%
separate_rows(FBgn) %>%
distinct(FBgn, .keep_all = TRUE) %>%
# variable indicating which study each protein is identified in
mutate(Sperm_Proteome = case_when(FBgn %in% x1[as.numeric(all_3$rowname)] ~ 'DmSP1_2_3',
FBgn %in% x1[as.numeric(in1_2$rowname)] ~ 'DmSP1_2',
FBgn %in% x1[as.numeric(in1_3$rowname)] ~ 'DmSP1_3',
FBgn %in% x1[as.numeric(in2_3$rowname)] ~ 'DmSP2_3',
FBgn %in% x1[as.numeric(only1$rowname)] ~ 'DmSP1',
FBgn %in% x1[as.numeric(only2$rowname)] ~ 'DmSP2',
FBgn %in% x1[as.numeric(only3$rowname)] ~ 'DmSP3')) %>%
# Add abundance data from experiment 1 and calculate mean abundance
left_join(DmSPintensity %>%
dplyr::select(FBgn, unique.one = `# Unique Peptides`, contains('ed):')) %>%
mutate(reps.one = rowSums(dplyr::select(., contains('ed):')) > 0),
mn.one = rowMeans(dplyr::select(., contains('ed):')), na.rm = TRUE))
) %>%
# Add abundance data from experiment 2 excluding PBST treatment and calculate mean abundance
left_join(PBST_dat %>% dplyr::select(FBgn, unique.two = `# Unique Peptides`, 45:50) %>%
mutate(reps.two = rowSums(dplyr::select(., contains('Ab')) > 0),
mn.two = rowMeans(dplyr::select(., contains('Ab')), na.rm = TRUE))
) %>%
# Add abundance data from experiment 3 and calculate mean abundance
left_join(salt_dat %>% dplyr::select(FBgn, unique.three = X..Unique.Peptides, 55:70) %>%
mutate(repl1 = rowSums(dplyr::select(., 3:4), na.rm = TRUE),
repl2 = rowSums(dplyr::select(., 5:6), na.rm = TRUE),
repl3 = rowSums(dplyr::select(., 7:8), na.rm = TRUE),
repl4 = rowSums(dplyr::select(., 9:10), na.rm = TRUE),
repl5 = rowSums(dplyr::select(., 11:12), na.rm = TRUE),
repl6 = rowSums(dplyr::select(., 13:14), na.rm = TRUE),
repl7 = rowSums(dplyr::select(., 15:16), na.rm = TRUE),
repl8 = rowSums(dplyr::select(., 17:18), na.rm = TRUE)) %>%
mutate(reps.three = rowSums(dplyr::select(., contains('repl')) > 0),
mn.three = rowMeans(dplyr::select(., contains('repl')), na.rm = TRUE))
) %>%
distinct(FBgn, .keep_all = TRUE) %>%
# Add variables indicating protein confidence
mutate(
# number of replicates each protein found in separately for each experiment and combined
comb.reps = case_when(reps.one >= 2 | reps.two >= 2 | reps.three >= 2 ~ 'confident',
rowSums(dplyr::select(., starts_with('reps')),
na.rm = TRUE) >= 2 ~ 'found',
TRUE ~ 'no.reps'),
# number of unique peptides each protein identified by separately for each experiment and combined
comb.peps = case_when(unique.one >= 2 | unique.two >= 2 | unique.three >= 2 ~ 'confident',
rowSums(dplyr::select(., starts_with('un')),
na.rm = TRUE) >= 2 ~ 'found',
TRUE ~ 'no.peps'),
# ranked abundance separately for each experiment
perc.one = percent_rank(mn.one) * 100,
perc.two = percent_rank(mn.two) * 100,
perc.three = percent_rank(mn.three) * 100) %>%
# rename abundance columns
rename_at(all_of(
colnames(dplyr::select(., starts_with('Abun'), starts_with('repl')))), ~ exp_names) %>%
mutate(
# calculate mean abundance across all experiments
grand.mean = rowMeans(dplyr::select(., REP1.1:REP1.3, Halt1:NoHalt3, NaCl1:PBS4), na.rm = TRUE),
# ranked abundance across all experiments
mean.perc = percent_rank(grand.mean) * 100,
# add variable for presence in list of putative Sfps
Sfp = case_when(FBgn %in% SFPs$FBgn ~ 'SFP.high',
FBgn %in% wigbySFP$FBgn ~ 'SFP.low',
TRUE ~ 'Sperm.only')) %>%
drop_na(FBgn)
# #write to file
# DmSP3 %>%
# mutate(DmSP2 = if_else(FBgn %in% DmSP2$FBgn, TRUE, FALSE)) %>%
# #filter(comb.reps == 'found' | comb.peps != 'no.peps') %>% dim
# #write_csv('output/DmSP_which_proteome.csv')
# write FBgn to file for GO analysis
#DmSP3 %>% dplyr::select(FBgn) %>% write_csv('output/GO_lists/DmSP3_3177.csv')
# number identified by two or more unique peptides in a single experiment
#DmSP3 %>% filter(comb.peps == 'confident') %>% dim
# number identified in two or more replicates across any experiment
#DmSP3 %>% filter(comb.reps != 'no.reps') %>% dim
# Confident proteins in current study
DmSPnew_conf <- DmSP3 %>%
filter(comb.peps != 'no.peps' | comb.reps != 'no.reps')
# combined DmSP1+2+DmSP3 (confident)
DmSP_comb <- DmSP3 %>%
filter(comb.peps != 'no.peps' | comb.reps != 'no.reps' | FBgn %in% DmSP2$FBgn)
# plot cumulative total IDs
cum_plot <- DmSP3 %>%
mutate(SP = str_sub(Sperm_Proteome, start = 5)) %>%
separate(SP, into = c('one', 'two', 'three'), sep = '_', extra = 'merge') %>%
pivot_longer(cols = c(one, two, three)) %>%
drop_na(value) %>% distinct(FBgn, .keep_all = TRUE) %>%
group_by(value) %>%
dplyr::count() %>% ungroup %>%
mutate(cum_sum = cumsum(n)) %>%
ggplot(aes(x = value, y = cum_sum)) +
geom_col() +
geom_bar(stat = 'identity', aes(y = n, fill = value)) +
scale_fill_viridis_d() +
scale_x_discrete(labels = c('1' = 'DmSP1',
'2' = 'DmSP2',
'3' = 'DmSP3')) +
labs(y = 'No. identified proteins') +
theme_bw() +
theme(legend.position = 'none',
axis.title.x = element_blank()) +
#ggsave(filename = 'figures/cumulative_IDs.pdf', width = 3, height = 3) +
NULL
cum_plot
```
### Coefficient of variation
For each experiment we calculate the coefficient of variation across replicates (log10 protein abundance).
```{r, fig.height=4, fig.width=4}
cv <- function(x) sd(x, na.rm = TRUE)/mean(x, na.rm = TRUE)
# get all experiments
allexp <- apply(log10(DmSP3 %>% dplyr::select(REP1.1:REP1.3, Halt1:NoHalt3, NaCl1:PBS4)), FUN = cv, 1)
CV_dat <- DmSP3 %>%
dplyr::select(FBgn,
REP1.1:REP1.3,
Halt1:NoHalt3,
NaCl1:PBS4) %>%
pivot_longer(cols = 2:18) %>%
mutate(log_val = log10(value),
experiment = case_when(grepl('REP', name) ~ 'Experiment 1',
grepl('Halt', name) ~ 'Experiment 2',
TRUE ~ 'Experiment 3'),
treatment = case_when(grepl('REP', name) ~ 'exp1',
grepl('^Halt', name) ~ 'exp2.1',
grepl('No', name) ~ 'exp2.2',
grepl('NaCl', name) ~ 'exp3.1',
TRUE ~ 'exp3.2'))
# calculate medians
CV_dat %>%
group_by(FBgn, experiment) %>%
summarise(CV = cv(log_val)) %>%
bind_rows(data.frame(FBgn = DmSP3$FBgn,
experiment = 'All',
CV = allexp)) %>%
group_by(experiment) %>%
summarise(N = n(),
md = median(CV, na.rm = TRUE),
sd = sd(CV, na.rm = TRUE))
CV_plot <- CV_dat %>%
group_by(FBgn, experiment) %>%
summarise(CV = cv(log_val)) %>%
ggplot(aes(x = experiment, y = CV, fill = experiment)) +
geom_boxplot(notch = TRUE) +
scale_fill_viridis_d(option = 'plasma') +
theme_bw() +
theme(legend.position = '',
axis.title.x = element_blank()) +
NULL
CV_plot
```
### Top 20 most abundant proteins
```{r, fig.height=3, fig.width=3}
DmSP3 %>%
arrange(desc(grand.mean)) %>%
head(20) %>% #write_csv('output/Top20DmSP3.csv')
mutate(NAME = if_else(NAME == '-', ANNOTATION_SYMBOL, NAME)) %>%
dplyr::select(FBgn, Name = NAME, `Ranked abundance (%)` = mean.perc) %>%
mutate(across(3, ~round(.x, 1))) %>%
my_data_table()
```
# Chromosomal distribution {.tabset}
We retrieved chromosomal location of all genes in the genome from [FlyBase.org](http://flybase.org/) (n = `r read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt') %>% dplyr::select(FBgn = X.SUBMITTED.ID, LOCATION_ARM) %>% distinct(FBgn, .keep_all = TRUE) %>% nrow`) and summarised the total number of genes on each chromosome. We then counted the observed number of sperm genes (n = `r n_distinct(DmSP3$FBgn)`) on each chromosome, and calculated the expected number based on the total number of sperm proteins identified. Finally, we calculated $\chi^2$ statistics for each chromosome and the associated p-values. We excluded the Y chromosome due to the small numbers of proteins. We used the Bejamini-Hochberg false discovery rate procedure to correct for multiple testing.
```{r, fig.height=3, fig.width=5}
# Total number of genes on each chromosome - to work out 'expected'
TotalGeneNumber <-
# here I parsed the ~22k proteins from the Dmel uniprot proteome and submitted to FlyBase.org
# I then remove any duplicate genes (i.e. some proteins have multiple isoforms)
read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt') %>%
dplyr::select(FBgn = X.SUBMITTED.ID, LOCATION_ARM) %>%
distinct(FBgn, .keep_all = TRUE) %>%
filter(LOCATION_ARM %in% c('2L', '2R', '3L', '3R', '4', 'X', 'Y')) %>%
group_by(LOCATION_ARM) %>%
summarise(N = n()) %>%
mutate(pr.total.genes = N/sum(N))
# Number of sperm genes on each chromosome - 'observed'
gene.no <- DmSP3 %>%
# replace DmSP3 with DmSP2 to compare results with previous studies
# DmSP2 %>%
# left_join(read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt'),
# by = c('FBgn' = 'X.SUBMITTED.ID')) %>%
distinct(FBgn, .keep_all = TRUE) %>%
filter(LOCATION_ARM %in% c('2L', '2R', '3L', '3R', '4', 'X', 'Y')) %>%
group_by(LOCATION_ARM) %>%
summarise(obs.genes = n())
# Calculate observed and expected no. genes in each comparison on each chromosome to do X^2 test
chm_dist <- gene.no %>%
inner_join(TotalGeneNumber %>%
dplyr::rename(all.genes = N)) %>%
# remove Chm 4 and Y due to low numbers of genes present
filter(LOCATION_ARM != 'Y') %>%
# Calculate X^2 statistics
mutate(exp.genes = round(n_distinct(DmSP3$FBgn) * pr.total.genes, 1), # expected no. genes
obs.exp = obs.genes/exp.genes, # observed / expected no. genes
X2 = (obs.genes - exp.genes)^2/exp.genes, # calculate X^2 stat
pval = 1 - (pchisq(X2, df = 1))) # get pvalue
# FDR corrected pval
chm_dist$FDR <- p.adjust(chm_dist$pval, method = 'fdr')
# plot chromosomal distribution
chm_plot <- chm_dist %>%
mutate(sigLabel = case_when(FDR < 0.001 ~ "***",
FDR < 0.01 & FDR > 0.001 ~ "**",
FDR < 0.05 & FDR > 0.01 ~ "*",
TRUE ~ ''),
Chromosome = fct_relevel(LOCATION_ARM, 'X', '2L', '2R', '3L', '3R', '4')) %>%
mutate(chm_n = paste0(Chromosome, '\n(', all.genes, ')')) %>%
ggplot(aes(x = Chromosome, y = obs.exp, fill = Chromosome)) +
geom_histogram(stat = 'identity') +
geom_hline(yintercept = 1, linetype = "dashed", colour = "black") +
#scale_fill_viridis_d(direction = -1) +
scale_fill_brewer(palette = 'Spectral') +
labs(x = "Chromosome", y = "observed/expected\n no. genes") +
theme_bw() +
theme(legend.position = 'none',
legend.text = element_text(size = 10),
strip.text.y = element_text(face = "italic")) +
geom_text(aes(label = sigLabel),
size = 5, colour = "black") +
geom_text(aes(y = -0.05, label = paste0(obs.genes, '/', exp.genes)),
size = 5, colour = "black") +
#ggsave(filename = 'figures/chm_dist.pdf', width = 4, height = 3) +
NULL
```
## Plot
The X and 3R chromosomes have significantly fewer sperm genes than expected with a FDR cut-off < 0.05.
```{r, fig.height=3, fig.width=5}
chm_plot
```
## Y-linked genes
We identified 9 Y chromosome genes. All above the DmSP3 average abundance:
```{r}
DmSP3 %>%
filter(LOCATION_ARM == 'Y') %>%
distinct(FBgn, .keep_all = TRUE) %>%
dplyr::select(FBgn, Name = NAME, `Ranked abundance (%)` = mean.perc) %>%
arrange(desc(`Ranked abundance (%)`)) %>% #write_csv('output/Ylinked_DmSP3.csv')
kable(digits = 1) %>%
kable_styling(full_width = FALSE)
```
# Gene age
As with chromosomal distribution, we calculated the observed and expected number of genes in each age class (retrieved from http://gentree.ioz.ac.cn/index.php and recoded as in [Patlar et al. (2021). *Evolution*](https://onlinelibrary.wiley.com/doi/abs/10.1111/evo.14297)), calculated $\chi^2$ statistics and the associated p-values, and used the Bejamini-Hochberg false discovery rate procedure to correct for multiple testing.
```{r}
gene_age <- read.csv('data/dm6_ver78_age.csv') %>%
left_join(read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt'),
by = c('FBgn' = 'X.SUBMITTED.ID')) %>%
distinct(FBtr, .keep_all = TRUE) %>%
mutate(sp_prot = if_else(FBgn %in% DmSP3$FBgn, 'Sperm', 'Other'),
# recode age class
gene_class = case_when(branch == 0 ~ 'ancient',
branch <= 2 ~ 'sophophora',
branch <= 3 ~ 'mel_group',
branch <= 4 ~ 'mel_sub',
TRUE ~ 'recent'),
gene_class = fct_relevel(gene_class,
'ancient', 'sophophora', 'mel_group', 'mel_sub',
'recent'))
#xtabs(~ gene_class + sp_prot, data = gene_age)
# Total number of genes in each age class - to work out 'expected'
TotalGeneNumber.ageclass <- gene_age %>%
#filter(sp_prot == 'Sperm') %>%
group_by(gene_class) %>%
dplyr::count(name = 'N') %>%
mutate(pr.total.genes = N/nrow(gene_age))
# Number of sperm genes in each age class - 'observed'
gene.no.ageclass <- gene_age %>%
filter(sp_prot == 'Sperm') %>%
group_by(gene_class) %>%
dplyr::count(name = 'obs.genes')
# Calculate observed and expected no. genes in each comparison on each chromosome to do X^2 test
age_dist <- gene.no.ageclass %>%
inner_join(TotalGeneNumber.ageclass %>%
dplyr::rename(all.genes = N)) %>%
# Calculate X^2 statistics
mutate(exp.genes = round(nrow(gene_age %>% filter(sp_prot == 'Sperm')) *
pr.total.genes, 1), # expected no. genes
obs.exp = obs.genes/exp.genes, # observed / expected no. genes
X2 = (obs.genes - exp.genes)^2/exp.genes, # calculate X^2 stat
pval = 1 - (pchisq(X2, df = 1))) # get pvalue
# FDR corrected pval
age_dist$FDR <- p.adjust(age_dist$pval, method = 'fdr')
# plot chromosomal distribution
age_plot <- age_dist %>%
mutate(sigLabel = case_when(FDR < 0.001 ~ "***",
FDR < 0.01 & FDR > 0.001 ~ "**",
FDR < 0.05 & FDR > 0.01 ~ "*",
TRUE ~ '')) %>%
mutate(age_n = paste0(gene_class, '\n(', all.genes, ')')) %>%
ggplot(aes(x = gene_class, y = obs.exp, fill = gene_class)) +
geom_histogram(stat = 'identity') +
geom_hline(yintercept = 1, linetype = "dashed", colour = "black") +
scale_fill_viridis_d() +
scale_x_discrete(labels = c('ancient' = 'Ancient', 'sophophora' = 'Sophophora',
'mel_group' = expression(paste(italic('D. mel'), ' gr.')),
'mel_sub' = expression(paste(italic('D. mel'), ' subgr.')),
'recent' = 'Recent')) +
labs(x = "Age", y = "observed/expected\n no. genes") +
theme_bw() +
theme(legend.position = 'none',
legend.text = element_text(size = 10),
strip.text.y = element_text(face = "italic")) +
geom_text(aes(label = sigLabel),
size = 5, colour = "black") +
geom_text(aes(y = -0.05, label = paste0(obs.genes, '/', exp.genes)),
size = 5, colour = "black") +
#ggsave(filename = 'figures/age_dist.pdf', width = 4, height = 3) +
NULL
```
## Plot
```{r, fig.height=3, fig.width=5}
age_plot
```
## New/recent genes in the DmSP3
```{r}
gene_age %>%
filter(gene_class == 'recent' & sp_prot == 'Sperm') %>% #write_csv('output/Recent_DmSP3.csv')
dplyr::select(FBgn, Name = NAME, Symbol = SYMBOL, Chromosome = LOCATION_ARM) %>%
mutate(Name = if_else(Name == '-', Symbol, Name)) %>%
arrange(Symbol) %>%
kable() %>%
kable_styling(full_width = FALSE)
```
# OMIM {.tabset}
We used the precomputed list of human disease orthologs from [FlyBase.org](http://flybase.org/) to retrieve [OMIM](omim.org) hits for proteins in the DmSP3.
```{r}
OMIM <- read.csv('data/FlyBase/DmSP3_OMIM.csv', na.strings = c('')) %>%
dplyr::rename(FBgn = X..Dmel_gene_ID)
Hsap_hom <- read.delim('data/FlyBase/FlyBase_Hsap_homologs.txt', na.strings = c('NA', '', '-')) %>%
dplyr::rename(FBgn = X.SUBMITTED.ID)
# # number of human homologs
# Hsap_hom %>%
# drop_na(H_SAPIENS_ORTHOLOGS) %>%
# distinct(FBgn) %>%
# count()
# # number of fly genes with more than one human homolog (disease vs not)
# OMIM %>%
# mutate(OMIM = if_else(is.na(OMIM_Phenotype_IDs), 'No', 'Yes')) %>%
# group_by(FBgn, OMIM) %>%
# summarise(N = n_distinct(Human_gene_symbol)) %>%
# group_by(OMIM, N) %>% count %>%
# mutate(N_genes = if_else(N > 1, '> 1', '1')) %>%
# ggplot(aes(x = OMIM, y = n, fill = N_genes)) +
# geom_col(position = 'fill') +
# scale_fill_manual(values = cbPalette[2:1]) +
# scale_y_continuous(labels = scales::percent) +
# theme_bw() +
# #theme(legend.title = element_blank()) +
# NULL
# # total number of homologs per Dmel gene
# Hsap_hom %>%
# separate_rows(H_SAPIENS_ORTHOLOGS, sep = ' <newline> ') %>%
# mutate(homolog = if_else(is.na(H_SAPIENS_ORTHOLOGS) == TRUE, 'no', 'yes')) %>%
# group_by(FBgn, homolog) %>% count() %>%
# mutate(N_genes = case_when(n > 1 & homolog == 'yes' ~ '> 1',
# n == 1 & homolog == 'yes' ~ '1',
# TRUE ~ 'No')) %>%
# group_by(N_genes) %>% count()
# # number of genes with disease phenotype
# Hsap_hom %>%
# mutate(omim = case_when(FBgn %in% OMIM$FBgn[is.na(OMIM$OMIM_Phenotype_IDs) == FALSE] ~ 'omim',
# TRUE ~ 'no')) %>%
# group_by(omim) %>% count()
# # number of human diseases per Dmel gene
# OMIM %>%
# drop_na(OMIM_Phenotype_IDs) %>%
# left_join(Hsap_hom, by = 'FBgn') %>%
# group_by(FBgn) %>%
# count() %>%
# mutate(N_genes = if_else(n > 1, '> 1', '1')) %>%
# group_by(N_genes) %>% count()
omim_1 <- data.frame(homolog = c('No', '1', '> 1'),
n = c(1974, 785, 417),
row = 'A') %>%
ggplot(aes(x = n, y = row, fill = homolog)) +
geom_col(position = 'fill') +
scale_fill_manual(values = cbPalette[3:1],
name = "Disease\nhomolog") +
scale_x_continuous(labels = scales::percent) +
theme_bw() +
theme(#legend.title = element_blank(),
legend.position = 'bottom',
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
annotate("text", x = c(0.3, 0.75, 0.93), y = 1, label = c(1974, 785, 417),
size = 5) +
#ggsave(filename = 'figures/OMIM_no.pdf', width = 2, height = 4) +
NULL
omim_no <- OMIM %>%
mutate(OMIM = if_else(is.na(OMIM_Phenotype_IDs), 'zNo', 'Yes')) %>%
group_by(FBgn, OMIM) %>%
summarise(N = n_distinct(Human_gene_symbol)) %>%
arrange(OMIM) %>%
group_by(FBgn) %>%
slice(1) %>%
ungroup() %>%
mutate(N_genes = case_when(N > 1 & OMIM == 'Yes' ~ '> 1',
N == 1 & OMIM == 'Yes' ~ '1',
TRUE ~ 'No')) %>%
group_by(OMIM, N_genes) %>%
dplyr::count() %>%
mutate(row = 'A')
omim_1 <- omim_no %>%
ggplot(aes(x = n, y = row, fill = N_genes)) +
geom_col(position = 'fill') +
scale_fill_manual(values = cbPalette[3:1],
name = "Disease\nhomolog") +
scale_x_continuous(labels = scales::percent) +
theme_bw() +
theme(#legend.title = element_blank(),
legend.position = 'bottom',
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
annotate("text", x = c(0.25, 0.66, 0.91), y = 1, label = rev(omim_no$n),
size = 5) +
#ggsave(filename = 'figures/OMIM_no.pdf', width = 2, height = 4) +
NULL
## all FBgns with associated disease phenotype
# OMIM %>%
# drop_na(OMIM_Phenotype_IDs) %>%
# distinct(FBgn, .keep_all = TRUE) #%>% write_csv('output/OMIM_results/all_FBgns.csv')
# # % genes with no disease ortholog
# OMIM %>%
# drop_na(OMIM_Phenotype_IDs) %>%
# distinct(FBgn) %>% dplyr::count() / n_distinct(OMIM$FBgn)
omim_plot <- plot(euler(c('DmSP3' = length(DmSP3$FBgn),
'DmSP3&Human\nhomologs' = 2598,
'DmSP3&Human\nhomologs&Disease\nhomologs' = 1202)),
quantities = TRUE,
fills = list(fill = viridis::viridis(n = 3), alpha = .8))
```
## Number of OMIM orthologs
```{r, fig.height=3, fig.width=3}
#pdf('figures/OMIM_orths.pdf', height = 4, width = 4)
omim_plot
#dev.off()
```
## Human homologs
```{r}
#pdf('figures/OMIM_plot.pdf', height = 6, width = 4)
gridExtra::grid.arrange(omim_plot, omim_1,
layout_matrix = rbind(c(1, 1),
c(1, 1),
c(2, 2)))
#dev.off()
```
```{r, fig.height=3, fig.width=3}
# chrom location of disease orthologs
omim.no <- OMIM %>%
drop_na(OMIM_Phenotype_IDs) %>%
left_join(read.delim('data/FlyBase/uniprot2FlyBase_chrm.txt'),
by = c('FBgn' = 'X.SUBMITTED.ID')) %>%
distinct(FBgn, .keep_all = TRUE) %>%
filter(LOCATION_ARM %in% c('2L', '2R', '3L', '3R', '4', 'X', 'Y')) %>%
group_by(LOCATION_ARM) %>%
summarise(obs.genes = n())
# Calculate observed and expected no. genes to do X^2 test
omim_dist <- omim.no %>%
inner_join(TotalGeneNumber %>%
dplyr::rename(all.genes = N)) %>%
# remove Chm 4 and Y due to low numbers of genes present
filter(LOCATION_ARM != 'Y') %>%
# Calculate X^2 statistics
mutate(exp.genes = round(1202 * pr.total.genes, 1), # expected no. genes
obs.exp = obs.genes/exp.genes, # observed / expected no. genes
X2 = (obs.genes - exp.genes)^2/exp.genes, # calculate X^2 stat
pval = 1 - (pchisq(X2, df = 1))) # get pvalue
# FDR corrected pval
omim_dist$FDR <- p.adjust(omim_dist$pval, method = 'fdr')
```
## Chromosomal distribution table
```{r}
# table of results
omim_dist %>%
dplyr::select(Chromosome = LOCATION_ARM, Observed = obs.genes, Expected = exp.genes,
Chi2 = X2, FDR) %>%
kable(digits = 2) %>%
kable_styling(full_width = FALSE)
# Parse Phenotype ID numbers and rank order
top_IDs <- data.frame(ID = gsub('\\[.*', '',
x = unlist(str_split(OMIM$OMIM_Phenotype_IDs.name.,
pattern = '],'))),
DESCRIPTION = gsub('.*\\[', '',
x = unlist(str_split(OMIM$OMIM_Phenotype_IDs.name.,
pattern = '],')))) %>%
mutate(DESCRIPTION = gsub(']', '', x = DESCRIPTION))
n_ids <- top_IDs %>%
group_by(ID) %>% dplyr::count() %>%
arrange(desc(n)) %>%
filter(ID != '')
# n_ids %>% group_by(n) %>% dplyr::count() %>%
# arrange(-n) %>%
# mutate(n_genes = n * nn)
# top_IDs[grep(paste(unlist(n_ids[1:34, 'ID']), collapse="|"), x = top_IDs$ID), ] %>%
# group_by(DESCRIPTION) %>%
# dplyr::count() %>%
# arrange(desc(n)) %>% print(n = 34) #%>% write_csv('output/OMIM_results/OMIM_tophits.csv')
# # grep top 17 IDs
# OMIM[grep(paste(c(top_IDs$ID[1:34]), collapse="|"),
# x = OMIM$OMIM_Phenotype_IDs.name.), ] %>%
# dplyr::select(-c(3:7)) %>%
# distinct(OMIM_Phenotype_IDs.name., .keep_all = TRUE)
## write tophits to files - 1 per phenotype
# for(i in 1:34) {
#
# db = OMIM[grep(n_ids$ID[i], x = OMIM$OMIM_Phenotype_IDs.name.), ]
#
# write_csv(db,
# paste0('output/OMIM_results/',
# gsub(' ', '_',
# str_replace_all(top_IDs$DESCRIPTION[i], "[[:punct:]]", " ")),
# '.csv'))
#
# }
### Ribosomal hits
# OMIM %>%
# drop_na(OMIM_Phenotype_IDs) %>%
# filter(FBgn %in% Dm_ribosomes$FBgn)
```
# Ribosomal proteins
We downloaded the 169 *D. melanogaster* ribosomal proteins curated by [FlyBase.org](https://flybase.org/reports/FBgg0000130) to compare the number, abundance, and distribution of ribosomal proteins found in the DmSP3. We also searched for other recent proteomics studies from other tissues or cell types in *D. melanogaster* and downloaded the supplementary materials containing the full lists of proteins to extract the ribosomal proteins identified in each study to compare to the DmSP3.
```{r}
# rename the ribosomal data set and add data on presence in the sperm proteome and chromosomal location
all_rib <- Dm_ribosomes %>%
# label genes based on presence in sperm proteome
mutate(sp_prot = case_when(
FBgn %in% c(DmSP3 %>% filter(comb.peps == 'confident') %>% pull(FBgn)) ~ 'Sperm.conf',
FBgn %in% c(DmSP3 %>% pull(FBgn)) ~ 'Sperm',
TRUE ~ 'Other'),
# define ribosomal class (small/large; cytoplasmic/mitochondrial)
CLASS = case_when(grepl('^RpL', x = SYMBOL) ~ 'CYT_LARGE',
grepl('^RpS', x = SYMBOL) ~ 'CYT_SMALL',
grepl('^mRpL', x = SYMBOL) ~ 'MIT_LARGE',
SYMBOL == 'sta' ~ 'CYT_SMALL',
TRUE ~ 'MIT_SMALL'),
loc = str_sub(CLASS, start = 1, 1),
size = str_sub(CLASS, start = 5, 5),
paralog = str_remove(SYMBOL, "[^0-9]+$"))
# # write supp table
# DmSP3 %>% filter(FBgn %in% all_rib$FBgn) %>% write_csv('output/DmSP_ribosomes.csv')
# # number of ribosomal proteins found in sperm by type
# all_rib %>%
# filter(sp_prot != 'Other') %>%
# group_by(loc) %>% count
#### Compare DmSP's
# upset(fromList(list(DmSP1 = intersect(DmSPI$FBgn, all_rib$FBgn),
# DmSP2 = intersect(DmSP2$FBgn, all_rib$FBgn),
# Current.study = intersect(DmSPIII.2$FBgn, all_rib$FBgn))))
# # Compare experiments
# upset(fromList(list(DmSP3 = all_rib %>% filter(sp_prot != 'Other') %>% pull(FBgn),
# PBSTd = all_rib %>% filter(FBgn %in% PBST_dat$FBgn) %>% pull(FBgn),
# SALTd = all_rib %>% filter(FBgn %in% salt_dat$FBgn) %>% pull(FBgn))))
## Load external data
# Li et al. 2020 (Cell) - brain
li_brain <- read_xlsx('data/Fly_Proteomes_LumosFusion/mmc2_Li_etal_2020.xlsx') %>%
dplyr::select(Accession = `UniProt Accession`, Species, UP = `Unique Peptides`) %>%
left_join(read.csv('data/Fly_Proteomes_LumosFusion/Li_etal_2020_uniprot2FBgn.csv')) %>%
filter(Species == 'DROME')
# Cao et al. 2020 (Cell Reports) - embryo
cao_embryo <- read.csv('data/Fly_Proteomes_LumosFusion/mmc2_Cao_etal_2020.csv') %>%
dplyr::rename(FBgn = 'FlyBase.ID')
# McDonough-Goldstein et al. 2020 (Scientific Reports) - oocyte
mcdonough_oocyte <- read_excel('data/Fly_Proteomes_LumosFusion/McDonough_etal_2021.xlsx') %>%
dplyr::select(FBgn = Description, UP = `Number of Unique Peptides`, starts_with('Abundance'))
colnames(mcdonough_oocyte)[3:8] <- paste0(rep(c('V', 'M'), each = 3), 1:3)
# Hopes et al. 2021 (Nucleic Acids Research)
hopes <- read.csv('data/Fly_Proteomes_LumosFusion/Hopes_etal_2021.csv') %>%
dplyr::rename(Accession = 'Inf_Accession.Information_BestAccession') %>%
left_join(read.csv('data/Fly_Proteomes_LumosFusion/Hopes_etal_2021_Accession2FBgn.csv'),
by = 'Accession')
# # overlap between datasets
# upset(fromList(list(
# DmSP3 = all_rib %>% filter(sp_prot != 'Other') %>% pull(FBgn),
# Oocyte = all_rib %>% filter(FBgn %in% mcdonough_oocyte$FBgn) %>% pull(FBgn),
# Brain = all_rib %>% filter(FBgn %in% li_brain$FBgn) %>% pull(FBgn),
# Embryo = all_rib %>% filter(FBgn %in% cao_embryo$FBgn) %>% pull(FBgn),
# Hopes = all_rib %>% filter(FBgn %in% hopes$FBgn) %>% pull(FBgn))))
plot(venn(c(#'DmSP3' = 168, 'Oocyte' = 168, 'Brain' = 168, 'Embryo' = 168,
'Hopes' = 2,
'Hopes&Embryo' = 4, 'Embryo&Oocyte' = 3, 'Hopes&Brain' = 1, 'DmSP3&Hopes' = 1,
'Oocyte&Hopes' = 1,
'Embryo&Hopes&Oocyte' = 58, 'Embryo&Oocyte&DmSP3' = 2, 'Embryo&Hopes&DmSP3' = 2,
'Oocyte&DmSP3&Brain' = 1, 'Embryo&Oocyte&Brain' = 1,
'Embryo&Hopes&Oocyte&DmSP3' = 14, 'Embryo&Hopes&Oocyte&Brain' = 13,
'Embryo&Hopes&DmSP3&Brain' = 5, 'Embryo&Oocyte&DmSP3&Brain' = 2,
'Hopes&Oocyte&DmSP3&Brain' = 1,
'Embryo&Hopes&Oocyte&DmSP3&Brain' = 55)),
quantities = TRUE)
# combine data
ribo_comb <- list(
DmSP3 = all_rib %>% filter(sp_prot != 'Other') %>% pull(FBgn),
Oocyte = all_rib %>% filter(FBgn %in% mcdonough_oocyte$FBgn) %>% pull(FBgn),
Brain = all_rib %>% filter(FBgn %in% li_brain$FBgn) %>% pull(FBgn),
Embryo = all_rib %>% filter(FBgn %in% cao_embryo$FBgn) %>% pull(FBgn)) %>%
reshape2::melt() %>%
dplyr::select(FBgn = value, Proteome = L1) %>%
left_join(all_rib %>% dplyr::select(FBgn, CLASS))
# perform Chi2 test
rib.test <- ribo_comb %>%
group_by(Proteome, CLASS) %>%
count() %>%
left_join(all_rib %>%
group_by(CLASS) %>% count(name = 'All')) %>%
mutate(obs.exp = n/All, # observed / expected no. genes
X2 = (n - All)^2/All, # calculate X^2 stat
pval = 1 - (pchisq(X2, df = 1))) # get pvalue
# FDR corrected pval
rib.test$FDR <- p.adjust(rib.test$pval, method = 'fdr')
rib_plot <- rib.test %>%
mutate(sigLabel = case_when(FDR < 0.001 ~ "***",
FDR < 0.01 & FDR > 0.001 ~ "**",
FDR < 0.05 & FDR > 0.01 ~ "*",
TRUE ~ ''),
Proteome = fct_relevel(Proteome, 'embryo', 'oocyte', 'brain', 'sperm')) %>%
ggplot(aes(x = CLASS, y = n, fill = Proteome)) +
geom_col(position = 'dodge') +
scale_fill_brewer(palette = 'RdBu', direction = -1) +
scale_x_discrete(labels = c('CYT_LARGE' = 'Cyt. large', 'CYT_SMALL' = 'Cyt. small',
'MIT_LARGE' = 'Mt. large', 'MIT_SMALL' = 'Mt. small')) +
labs(x = "Class", y = "obs. no. genes") +
theme_bw() +
theme(legend.position = 'bottom',
legend.title = element_blank()) +
geom_text(aes(label = sigLabel),
size = 5, colour = "black", position = position_dodge(width = .9)) +
geom_segment(aes(x = 0.6, y = 54, xend = 1.4, yend = 54), lty = 2) +
geom_segment(aes(x = 1.6, y = 38, xend = 2.4, yend = 38), lty = 2) +
geom_segment(aes(x = 2.6, y = 47, xend = 3.4, yend = 47), lty = 2) +
geom_segment(aes(x = 3.6, y = 29, xend = 4.4, yend = 29), lty = 2) +
#ggsave(filename = 'figures/ribo_comp.pdf', width = 4, height = 3) +
NULL
```
## Compare tissue/cell types
We calculated $\chi^2$ statistics with the null expectation that each tissue or cell type would have complete representation of all 168 ribosomal proteins. We also tested whether the overlap between ribosomal proteins in brain and sperm was greater than expected using Fisher's exact test.
```{r, fig.height=4, fig.width=10}
## overlap
# upset(fromList(list(Ribosomes = all_rib %>% pull(FBgn),
# DmSP3 = all_rib %>% filter(sp_prot != 'Other') %>% pull(FBgn),
# Brain = all_rib %>% filter(FBgn %in% li_brain$FBgn) %>% pull(FBgn))))
rib_br_sp <- plot(euler(c('Ribosomes' = 169,
'Ribosomes&Brain' = 15,
'Ribosomes&DmSP3' = 19,
'Ribosomes&Brain&DmSP3' = 64)),
quantities = TRUE,
fills = list(fill = c(NA, RColorBrewer::brewer.pal(name = 'RdBu', n = 4)[4:3]),
alpha = 1))
gridExtra::grid.arrange(rib_plot, rib_br_sp, nrow = 1)
# # test overlap between brain and testes
# broom::tidy(fisher.test(matrix(c(169, 19, 15, 63), nrow = 2), alternative = "greater"))
```
## Paralog switching
There are 93 cytoplasmic ribosomal proteins on FlyBase.org, including 13 paralogs (for 80 per protein).
```{r}
paralogs <- read.csv('data/FlyBase/FlyBase_Ribosome_Paralogs.csv') %>%
dplyr::select(-c(Location, Strand, Paralog_Location:DIOPT_score))
p_genes <- paralogs %>%
filter(FBgn %in% all_rib$FBgn, !str_detect(GeneSymbol, '^m')) %>%
filter(Paralog_FBgn_ID %in% all_rib$FBgn, !str_detect(Paralog_GeneSymbol, '^m')) %>%
mutate(base_gene = str_remove(GeneSymbol, "[^0-9]+$"),
para_gene = str_remove(Paralog_GeneSymbol, "[^0-9]+$")) %>%