/
3_Enrichment_MutantVsWT.Rmd
911 lines (811 loc) · 26 KB
/
3_Enrichment_MutantVsWT.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
---
title: "Enrichment Analysis: Mutant Vs Wild-Type"
author: "Steve Pederson"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: workflowr::wflow_html
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
autodep = TRUE,
echo = TRUE,
warning = FALSE,
message = FALSE,
fig.align = "center"
)
```
# Setup
```{r loadPackages}
library(tidyverse)
library(magrittr)
library(edgeR)
library(scales)
library(pander)
library(goseq)
library(msigdbr)
library(AnnotationDbi)
library(RColorBrewer)
library(ngsReports)
library(UpSetR)
library(pheatmap)
```
```{r setOpts}
theme_set(theme_bw())
panderOptions("table.split.table", Inf)
panderOptions("table.style", "rmarkdown")
panderOptions("big.mark", ",")
```
```{r samplesAndLabels}
samples <- read_csv("data/samples.csv") %>%
distinct(sampleName, .keep_all = TRUE) %>%
dplyr::select(sample = sampleName, sampleID, genotype) %>%
mutate(
genotype = factor(genotype, levels = c("WT", "Het", "Hom")),
mutant = genotype %in% c("Het", "Hom"),
homozygous = genotype == "Hom"
)
genoCols <- samples$genotype %>%
levels() %>%
length() %>%
brewer.pal("Set1") %>%
setNames(levels(samples$genotype))
```
```{r loadFits}
dgeList <- here::here("data/dgeList.rds") %>% read_rds()
cpmPostNorm <- here::here("data/cpmPostNorm.rds") %>% read_rds()
entrezGenes <- dgeList$genes %>%
dplyr::filter(!is.na(entrezid)) %>%
unnest(entrezid) %>%
dplyr::rename(entrez_gene = entrezid)
```
```{r topTables}
deTable <- here::here("output", "psen2VsWT.csv") %>%
read_csv() %>%
mutate(
entrezid = dgeList$genes$entrezid[gene_id]
)
```
```{r formatP}
formatP <- function(p, m = 0.0001){
out <- rep("", length(p))
out[p < m] <- sprintf("%.2e", p[p<m])
out[p >= m] <- sprintf("%.4f", p[p>=m])
out
}
```
# Introduction
Enrichment analysis for this dataset present some challenges.
Despite normalisation to account for gene length and GC bias, some appeared to still be present in the final results.
In addition, the confounding of incomplete rRNA removal with genotype may lead to other distortions in both DE genes and ranking statistics.
Two steps for enrichment analysis will be undertaken.
1. Testing for enrichment within *discrete sets of DE genes* as defined in the previous steps
2. Testing for enrichment using the complete set of results using `fry`.
Testing for enrichment *within discrete gene sets* will be performed using `goseq` as this allows for the incorporation of a single covariate as a predictor of differential expression.
GC content, gene length and correlation with rRNA removal can all be supplied as separate covariates.
For enrichment within larger gene lists, `fry` can take into account inter-gene correlations.
Values supplied will be logCPM for each gene/sample after being adjusted for GC and length biases.
# Databases used for testing
Data was sourced using the `msigdbr` package.
The initial database used for testing was the Hallmark Gene Sets, with mappings from gene-set to EntrezGene IDs performed by the package authors.
## Hallmark Gene Sets
```{r hm}
hm <- msigdbr("Danio rerio", category = "H") %>%
left_join(entrezGenes) %>%
dplyr::filter(!is.na(gene_id)) %>%
distinct(gs_name, gene_id, .keep_all = TRUE)
hmByGene <- hm %>%
split(f = .$gene_id) %>%
lapply(extract2, "gs_name")
hmByID <- hm %>%
split(f = .$gs_name) %>%
lapply(extract2, "gene_id")
```
Mappings are required from gene to pathway, and Ensembl identifiers were used to map from gene to pathway, based on the mappings in the previously used annotations (Ensembl Release 98).
A total of `r comma(length(hmByGene))` Ensembl IDs were mapped to pathways from the hallmark gene sets.
## KEGG Gene Sets
```{r kg}
kg <- msigdbr("Danio rerio", category = "C2", subcategory = "CP:KEGG") %>%
left_join(entrezGenes) %>%
dplyr::filter(!is.na(gene_id)) %>%
distinct(gs_name, gene_id, .keep_all = TRUE)
kgByGene <- kg %>%
split(f = .$gene_id) %>%
lapply(extract2, "gs_name")
kgByID <- kg %>%
split(f = .$gs_name) %>%
lapply(extract2, "gene_id")
```
The same mapping process was applied to KEGG gene sets.
A total of `r comma(length(kgByGene))` Ensembl IDs were mapped to pathways from the KEGG gene sets.
## Gene Ontology Gene Sets
```{r goSummaries}
goSummaries <- url("https://uofabioinformaticshub.github.io/summaries2GO/data/goSummaries.RDS") %>%
readRDS() %>%
mutate(
Term = Term(id),
gs_name = Term %>% str_to_upper() %>% str_replace_all("[ -]", "_"),
gs_name = paste0("GO_", gs_name)
)
minPath <- 3
```
```{r go}
go <- msigdbr("Danio rerio", category = "C5") %>%
left_join(entrezGenes) %>%
dplyr::filter(!is.na(gene_id)) %>%
left_join(goSummaries) %>%
dplyr::filter(shortest_path >= minPath) %>%
distinct(gs_name, gene_id, .keep_all = TRUE)
goByGene <- go %>%
split(f = .$gene_id) %>%
lapply(extract2, "gs_name")
goByID <- go %>%
split(f = .$gs_name) %>%
lapply(extract2, "gene_id")
```
For analysis of gene-sets from the GO database, gene-sets were restricted to those with `r minPath` or more steps back to the ontology root terms.
A total of `r comma(length(goByGene))` Ensembl IDs were mapped to pathways from restricted database of `r comma(length(goByID))` GO gene sets.
```{r gsSizes}
gsSizes <- bind_rows(hm, kg, go) %>%
dplyr::select(gs_name, gene_symbol, gene_id) %>%
chop(c(gene_symbol, gene_id)) %>%
mutate(
gs_size = vapply(gene_symbol, length, integer(1)),
de_id = lapply(
X = gene_id,
FUN = intersect,
y = dplyr::filter(deTable, DE)$gene_id
),
de_size = vapply(de_id, length, integer(1))
)
```
# Enrichment in the DE Gene Set
The first step of analysis using `goseq`, regardless of the gene-set, is estimation of the probability weight function (PWF) which quantifies the probability of a gene being considered as DE based on a single covariate.
As GC content and length should have been accounted for during conditional-quantile normalisation, these were not required for any bias.
However, the *gene-level correlations with rRNA contamination* were instead used a predictor of bias in selection of a gene as being DE.
```{r rawFqc}
rawFqc <- list.files(
path = here::here("data/0_rawData/FastQC/"),
pattern = "zip",
full.names = TRUE
) %>%
FastqcDataList()
gc <- getModule(rawFqc, "Per_sequence_GC") %>%
group_by(Filename) %>%
mutate(Freq = Count / sum(Count)) %>%
ungroup()
gcDev <- gc %>%
left_join(getGC(gcTheoretical, "Drerio", "Trans")) %>%
mutate(
sample = str_remove(Filename, "_R[12].fastq.gz"),
resid = Freq - Drerio
) %>%
left_join(samples) %>%
group_by(sample) %>%
summarise(
ss = sum(resid^2),
n = n(),
sd = sqrt(ss / (n - 1))
)
```
```{r riboCors}
riboVec <- structure(gcDev$sd, names = gcDev$sample)
riboCors <- cpm(dgeList, log = TRUE) %>%
apply(1, function(x){
cor(x, riboVec[names(x)])
})
```
Values were calculated as per the previous steps, using the logCPM values for each gene, with the sample-level standard deviations from the theoretical GC distribution being used as a measure of rRNA contamination.
For estimation of the probability weight function, squared correlations were used to place negative and positive correlations on the same scale.
This accounts for genes which are both negatively & positively biased by the presence of excessive rRNA.
Clearly, the confounding of genotype with rRNA means that some genes driven by the genuine biology may be down-weighted under this approach.
```{r riboPwf, fig.height=4, fig.width=4, fig.cap="*Using this approach, it was clear that correlation with rRNA proportions significantly biased the probability of a gene being considered as DE.*"}
riboPwf <- deTable %>%
mutate(riboCors = riboCors[gene_id]^2) %>%
dplyr::select(gene_id, DE, riboCors) %>%
distinct(gene_id, .keep_all = TRUE) %>%
with(
nullp(
DEgenes = structure(
as.integer(DE), names = gene_id
),
genome = "danRer10",
id = "ensGene",
bias.data = riboCors,
plot.fit = FALSE
)
)
plotPWF(riboPwf, main = "Bias from rRNA proportions")
```
All gene-sets were then tested using this PWF.
## Hallmark Gene Sets
```{r hmRiboGoSeq}
hmRiboGoseq <- goseq(riboPwf, gene2cat = hmByGene) %>%
as_tibble %>%
dplyr::filter(numDEInCat > 0) %>%
mutate(
adjP = p.adjust(over_represented_pvalue, method = "bonf"),
FDR = p.adjust(over_represented_pvalue, method = "fdr")
) %>%
dplyr::select(-contains("under")) %>%
dplyr::rename(
gs_name = category,
PValue = over_represented_pvalue
)
```
No gene-sets achieved significance in the DE genes with the lowest FDR being `r percent(min(hmRiboGoseq$FDR))`
## KEGG Gene Sets
```{r kgRiboGoseq}
kgRiboGoseq <- goseq(riboPwf, gene2cat = kgByGene) %>%
as_tibble %>%
dplyr::filter(numDEInCat > 0) %>%
mutate(
adjP = p.adjust(over_represented_pvalue, method = "bonf"),
FDR = p.adjust(over_represented_pvalue, method = "fdr")
) %>%
dplyr::select(-contains("under")) %>%
dplyr::rename(
gs_name = category,
PValue = over_represented_pvalue
)
```
```{r kgRiboGoseqTable}
kgRiboGoseq %>%
dplyr::slice(1:5) %>%
mutate(
p = formatP(PValue),
adjP = formatP(adjP),
FDR = formatP(FDR)
) %>%
dplyr::select(
`Gene Set` = gs_name,
DE = numDEInCat,
`Set Size` = numInCat,
PValue,
`p~bonf~` = adjP,
`p~FDR~` = FDR
) %>%
pander(
justify = "lrrrrr",
caption = paste(
"The", nrow(.), "most highly-ranked KEGG pathways.",
"Bonferroni-adjusted p-values are the most stringent and give high",
"confidence when below 0.05."
)
)
```
Notably, the KEGG gene-set for Ribosomal genes was detected as enriched in the set of DE genes, with no other KEGG gene-sets being considered significant.
## GO Gene Sets
```{r goRiboGoseq}
goRiboGoseq <- goseq(riboPwf, gene2cat = goByGene) %>%
as_tibble %>%
dplyr::filter(numDEInCat > 0) %>%
mutate(
adjP = p.adjust(over_represented_pvalue, method = "bonf"),
FDR = p.adjust(over_represented_pvalue, method = "fdr")
) %>%
dplyr::select(-contains("under")) %>%
dplyr::rename(
gs_name = category,
PValue = over_represented_pvalue
)
```
```{r goRiboGoseqTable}
goRiboGoseq %>%
dplyr::filter(adjP < 0.05) %>%
mutate(
p = formatP(PValue),
adjP = formatP(adjP),
FDR = formatP(FDR)
) %>%
dplyr::select(
`Gene Set` = gs_name,
DE = numDEInCat,
`Set Size` = numInCat,
PValue,
`p~bonf~` = adjP,
`p~FDR~` = FDR
) %>%
pander(
justify = "lrrrrr",
caption = paste(
"*The", nrow(.), "most highly-ranked GO terms.",
"Bonferroni-adjusted p-values are the most stringent and give high",
"confidence when below 0.05, with all terms here reaching this threshold.",
"However, most terms once again indicate the presence of rRNA.*"
)
)
```
# Enrichment Testing on the Complete Set of Genes
## Hallmark Gene Sets
```{r hmFry}
hmFry <- cpmPostNorm %>%
fry(
index = hmByID,
design = dgeList$design,
contrast = "mutant",
sort = "directional"
) %>%
rownames_to_column("gs_name") %>%
as_tibble()
```
```{r}
hmFry %>%
dplyr::filter(
PValue < 0.01
) %>%
left_join(gsSizes) %>%
mutate(gs_name = str_remove(gs_name, "HALLMARK_")) %>%
dplyr::select(
`Hallmark Gene Set` = gs_name,
`Expressed Genes` = NGenes,
`DE Genes` = de_size,
Direction,
PValue, FDR
) %>%
pander(
justify = "lrrlrr",
caption = "Enriched Hallmark Gene Sets, using a threshold of p < 0.01, which corresponds to an FDR of 0.02"
)
```
### Exploration of significant Hallmark Gene Sets
```{r hmFryUpset, fig.width=10, fig.cap = "*UpSet plot indicating distribution of DE genes within all significant HALLMARK gene sets. Gene sets were restricted to those with an FDR < 0.05 and at least 5 DE genes. The plot is truncated at the right for simplicity. Most gene sets seem relatively independent of each other with regard to DE genes.*"}
hmFry %>%
left_join(gsSizes) %>%
dplyr::filter(de_size >= 5, FDR < 0.05) %>%
dplyr::select(gs_name, de_id) %>%
unnest(de_id) %>%
mutate(
gs_name = str_remove(gs_name, "HALLMARK_"),
gs_name = fct_lump(gs_name, n = 14)
) %>%
split(f = .$gs_name) %>%
lapply(magrittr::extract2, "de_id") %>%
fromList() %>%
upset(
nsets = length(.),
nintersects = 20,
order.by = "freq",
mb.ratio = c(0.6, 0.4),
sets.x.label = "Number Of DE Genes"
)
```
```{r hmHeat, fig.height=9, fig.width=10, fig.cap = "*Gene expression patterns for all DE genes in HALLMARK gene sets, containing more than 12 DE genes.*"}
hmHeat <- hmFry %>%
left_join(gsSizes) %>%
dplyr::filter(de_size >= 12, FDR < 0.05) %>%
dplyr::select(gs_name, de_id) %>%
unnest(de_id) %>%
left_join(dgeList$genes, by = c("de_id" = "gene_id")) %>%
dplyr::select(gs_name, de_id, gene_name) %>%
mutate(belongs = TRUE) %>%
pivot_wider(
id_cols = c(de_id, gene_name),
names_from = gs_name,
values_from = belongs,
values_fill = list(belongs = FALSE)
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("de_id")
)
hmHeat %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
cutree_rows = 6,
cutree_cols = 2,
annotation_names_row = FALSE,
annotation_row = hmHeat %>%
dplyr::select(gene_name, starts_with("HALLMARK_")) %>%
mutate_at(vars(starts_with("HALL")), as.character) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
set_colnames(
str_remove(colnames(.), "HALLMARK_")
)
)
```
## KEGG Gene Sets
```{r kgFry}
kgFry <- cpmPostNorm %>%
fry(
index = kgByID,
design = dgeList$design,
contrast = "mutant",
sort = "directional"
) %>%
rownames_to_column("gs_name") %>%
as_tibble()
```
```{r}
kgFry %>%
dplyr::filter(
PValue < 0.005
) %>%
left_join(gsSizes) %>%
mutate(gs_name = str_remove(gs_name, "HALLMARK_")) %>%
dplyr::select(
`KEGG Gene Set` = gs_name,
`Expressed Genes` = NGenes,
`DE Genes` = de_size,
Direction,
PValue, FDR
) %>%
pander(
justify = "lrrlrr",
caption = "Enriched KEGG Gene Sets, using a threshold p < 0.005, which corresponds to an FDR of 0.02"
)
```
### Exploration of Significant KEGG Gene Sets
```{r kgFryUpset, fig.width=8, fig.cap = "*UpSet plot indicating distribution of DE genes within all significant terms from the KEGG gene sets. Gene sets were restricted to those with an FDR < 0.05 and four or more DE genes. There is considerable overlap between DE genes in Oxidative Phosphorylation and both Parkinson's and Huntington's Disease, indicating that these terms essentially capture the same expression signal within this dataset.*"}
kgFry %>%
left_join(gsSizes) %>%
dplyr::filter(de_size >= 4, FDR < 0.05) %>%
dplyr::select(gs_name, de_id) %>%
unnest(de_id) %>%
mutate(
gs_name = str_remove(gs_name, "KEGG_"),
gs_name = fct_lump(gs_name, n = 14)
) %>%
split(f = .$gs_name) %>%
lapply(magrittr::extract2, "de_id") %>%
fromList() %>%
upset(
nsets = length(.),
nintersects = 20,
order.by = "freq",
mb.ratio = c(0.6, 0.4),
sets.x.label = "Number Of DE Genes"
)
```
```{r riboOxHeatmap, fig.width=8, fig.height=8, fig.cap = "*Given that the largest gene sets within the KEGG results were Oxidative Phosphorylation and Ribosomal gene sets, all DE genes associated with these KEGG terms are displayed. All genes appear to show increased expression in mutant samples.*"}
riboOx <- kg %>%
dplyr::filter(
grepl("OXIDATIVE_PHOS", gs_name) | grepl("RIBOSOME", gs_name),
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
mutate(gs_name = str_remove(gs_name, "(KEGG|HALLMARK)_")) %>%
distinct(gs_name, gene_id) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id") %>%
as_tibble()
) %>%
pivot_longer(cols = starts_with("Ps"), names_to = "sample", values_to = "CPM") %>%
left_join(dgeList$samples) %>%
left_join(dgeList$genes) %>%
dplyr::select(gs_name, gene_name, sampleID, genotype, CPM) %>%
pivot_wider(
id_cols = c(gs_name, gene_name),
values_from = CPM,
names_from = sampleID
)
riboOx %>%
dplyr::select(-gs_name) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
annotation_row = data.frame(
GeneSet = riboOx$gs_name %>% str_replace("OXI.+", "OXPHOS"),
row.names = riboOx$gene_name
),
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
annotation_names_row = FALSE,
cutree_rows = 3,
cutree_cols = 2
)
```
## GO Gene Sets
```{r goFry}
goFry <- cpmPostNorm %>%
fry(
index = goByID,
design = dgeList$design,
contrast = "mutant",
sort = "directional"
) %>%
rownames_to_column("gs_name") %>%
as_tibble()
```
```{r}
goFry %>%
left_join(gsSizes) %>%
left_join(distinct(go, gs_name, shortest_path)) %>%
dplyr::filter(
FDR < 0.01,
shortest_path > 3,
NGenes < 1000,
de_size >= 5
) %>%
dplyr::select(
`GO Gene Set` = gs_name,
`Expressed Genes` = NGenes,
`DE Genes` = de_size,
Direction,
PValue, FDR
) %>%
pander(
justify = "lrrlrr",
caption = "Enriched GO Gene Sets, using the thresholds FDR < 0.01, at least 5 DE genes, a set size < 1000 and more than 3 steps back to the ontology root."
)
```
### Exploration of Significant GO Gene Sets
```{r goFryUpset, fig.height=6, fig.width=10, fig.cap = "*UpSet plot indicating distribution of DE genes within significantly enriched terms from the GO gene sets. For this visualisation, GO terms were restricted to those with 15 or more DE genes, where this represented more than 5% of a gene set as being DE, along with an FDR < 0.02 and more than 3 steps back to the ontology root. The 20 largest GO terms satisfying these criteria are shown. The plot is truncated at the right hand side for simplicity. A group of 28 genes is uniquely attributed to the Mitochondrial Envelop, with a further 18 being relatively unique to mRNA Metabolic Process. The next grouping of 15 genes are unique to Regulation Of Nucleobase-Containing Compound Metabolic Process followed by 25 genes, spread across two clusters of terms which largely represent Ribosomal activity. In between these are 13 genes uniquely associated with Anion Transport.*"}
goFry %>%
left_join(gsSizes) %>%
left_join(distinct(go, gs_name, shortest_path)) %>%
mutate(
propDE = de_size / gs_size
) %>%
dplyr::filter(
de_size >= 15,
propDE > 0.05,
FDR < 0.02,
shortest_path > 3
) %>%
dplyr::select(gs_name, de_id) %>%
unnest(de_id) %>%
mutate(
gs_name = str_remove(gs_name, "GO_"),
gs_name = fct_lump(gs_name, n = 20)
) %>%
split(f = .$gs_name) %>%
lapply(magrittr::extract2, "de_id") %>%
fromList() %>%
upset(
nsets = length(.),
nintersects = 20,
order.by = "freq",
mb.ratio = c(0.6, 0.4),
sets.x.label = "Number Of DE Genes"
)
```
### Genes Associated with the Mitochondrial Envelope
```{r heatMito, fig.height=8, fig.width=8, fig.cap="*All DE genes associated with the GO term 'Mitochondrial Envelope'.*"}
go %>%
dplyr::filter(
gs_name == "GO_MITOCHONDRIAL_ENVELOPE",
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
dplyr::select(
gene_id, gene_name
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id")
) %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
annotation_col = dgeList$samples %>%
dplyr::select(Genotype = genotype),
cutree_rows = 4,
cutree_cols = 2
)
```
### Genes Associated with RNA Metabolic Process
```{r heatRnaMetab, fig.height=7, fig.width=8, fig.cap="*All DE genes associated with the GO term 'mRNA Metabolic Process'.*"}
go %>%
dplyr::filter(
gs_name == "GO_MRNA_METABOLIC_PROCESS",
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
dplyr::select(
gene_id, gene_name
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id")
) %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
annotation_col = dgeList$samples %>%
dplyr::select(Genotype = genotype),
cutree_rows = 4,
cutree_cols = 2
)
```
### Genes Associated with Regulation Of Nucleobase-Containing Compound Metabolic Process
```{r heatRegNucleo, fig.height=6, fig.width=8, fig.cap="*All DE genes associated with the GO term 'mRNA Metabolic Process'.*"}
go %>%
dplyr::filter(
gs_name == "GO_REGULATION_OF_NUCLEOBASE_CONTAINING_COMPOUND_METABOLIC_PROCESS",
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
dplyr::select(
gene_id, gene_name
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id")
) %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
annotation_col = dgeList$samples %>%
dplyr::select(Genotype = genotype),
cutree_rows = 4,
cutree_cols = 2
)
```
### Genes Associated with Anion Transport
```{r heatAnion, fig.height=7, fig.width=8, fig.cap="*All DE genes associated with the GO term 'Anion Transport'.*"}
go %>%
dplyr::filter(
gs_name == "GO_ANION_TRANSPORT",
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
dplyr::select(
gene_id, gene_name
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id")
) %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
annotation_col = dgeList$samples %>%
dplyr::select(Genotype = genotype),
cutree_rows = 3,
cutree_cols = 2
)
```
### Genes Associated with Ribosomal Activity
```{r heatRibo, fig.height=7, fig.width=8, fig.cap="*All DE genes associated with the GO term 'Cytosolic Ribosome'.*"}
go %>%
dplyr::filter(
gs_name == "GO_CYTOSOLIC_RIBOSOME",
gene_id %in% dplyr::filter(deTable, DE)$gene_id
) %>%
dplyr::select(
gene_id, gene_name
) %>%
left_join(
cpmPostNorm %>%
as.data.frame() %>%
rownames_to_column("gene_id")
) %>%
dplyr::select(gene_name, starts_with("Ps")) %>%
as.data.frame() %>%
column_to_rownames("gene_name") %>%
as.matrix() %>%
pheatmap(
color = viridis_pal(option = "magma")(100),
legend_breaks = c(seq(-2, 8, by = 2), max(.)),
legend_labels = c(seq(-2, 8, by = 2), "logCPM\n"),
labels_col = hmHeat %>%
dplyr::select(starts_with("Ps")) %>%
colnames() %>%
enframe(name = NULL) %>%
dplyr::rename(sample = value) %>%
left_join(dgeList$samples) %>%
dplyr::select(sample, sampleID) %>%
with(
structure(sampleID, names = sample)
),
annotation_col = dgeList$samples %>%
dplyr::select(Genotype = genotype),
cutree_rows = 3,
cutree_cols = 2
)
```
# Data Export
All enriched gene sets with an FDR adjusted p-value < 0.05 were exported as a single csv file.
```{r}
bind_rows(
hmFry,
kgFry,
goFry
) %>%
dplyr::filter(FDR < 0.05) %>%
left_join(gsSizes) %>%
dplyr::select(
gs_name, NGenes, Direction, PValue, FDR,
gene_symbol, de_size
) %>%
mutate(
DE = lapply(
X = gene_symbol,
FUN = intersect,
y = dplyr::filter(deTable, DE)$gene_name
),
DE = vapply(DE, paste, character(1), collapse = ";")
) %>%
dplyr::select(
`Gene Set` = gs_name,
`Nbr Detected Genes` = NGenes,
`Nbr DE Genes` = de_size,
Direction, PValue, FDR,
`DE Genes` = DE
) %>%
write_csv(
here::here("output", "Enrichment_Mutant_V_WT.csv")
)
```