-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09_post_hoc_diffex.Rmd
2026 lines (1542 loc) · 49.1 KB
/
09_post_hoc_diffex.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: "TEP post hoc analysis: differential expression"
author: "Kat Moore"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
toc_float: yes
toc_depth: 5
df_print: paged
highlight: kate
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(edgeR)
#library(RColorBrewer)
library(here)
library(ggsci)
library(ggthemes)
library(ggpubr)
library(openxlsx)
library(GO.db)
library(org.Hs.eg.db)
library(biomaRt)
library(KEGGREST)
library(ComplexHeatmap)
library(DESeq2)
library(tidyverse)
theme_set(theme_bw())
```
## Introduction
In this notebook, we will continue exploring possible explanations for the poor performance of the TEP classifiers on the blind validation set. In addition to the analyses already performed, this notebook will focus on differential expression analysis with `edgeR`, especially within the batch effect.
The DGEList that contains all the data:
```{r}
dgeAll <- readRDS(file = here("Rds/07b_dgeAll.Rds"))
```
Overview of sample data:
```{r}
head(dgeAll$samples)
```
Within the sample data, "Original" refers to the collection of samples originally received from the VUMC in December of 2018, subsetted to include only healthy controls and breast cancer patients. "blindVal" refers to the blind validation dataset collected by the NKI in 2019. Performance of classifiers trained on the blind validation set was verified by a third party in August 2020, after which the class labels were shared with all parties (i.e. the dataset is no longer blind).
Original_Label refers to the data partition I developed in the summer of 2020 to build a classifier on breast cancer vs healthy controls. See notebook 01 for details. `isolationlocation` refers to the hospital from which the sample originates. Note that the NKI appears twice here, with "blindNKI" referring to the second batch produced for the blind validation set.
```{r}
dgeAll$samples %>%
select(isolationlocation, group) %>%
table() %>%
addmargins()
```
Since some hospitals contributed few samples (AMC, VUMC, VIENNA), they have been grouped together into an "other" category.
```{r}
dgeAll$samples %>%
select(hosp, group) %>%
table() %>%
addmargins()
```
As frequently commented upon in previous notebooks, the study design is imbalanced so that most of the cancer samples come from the NKI or MGH, and most of the control samples come from the VUMC.
```{r}
dgeAll$samples %>%
filter(hosp != "blindNKI") %>%
ggplot(aes(x = group, fill = hosp)) +
geom_bar() +
ggsci::scale_fill_igv() +
ggtitle("TEP samples by cancer status and hospital of origin")
```
We will also need the entrez IDs for pathway analysis later, which is not included in `dgeAll$genes`.
```{r}
# Return the Ensembl IDs for a set of genes
entrez <- AnnotationDbi::select(org.Hs.eg.db, # database
keys = rownames(dgeAll), # data to use for retrieval
columns = c("ENSEMBL", "ENTREZID"
#,"GENENAME"
), # information to retreive for given data
keytype = "ENSEMBL") # type of data given in 'keys' argument
#Remove duplicates: Many of these are NAs
#For the rest, not much else we can do about multi-mapping
entrez <- entrez[!duplicated(entrez$ENTREZID),]
entrez <- entrez[!duplicated(entrez$ENSEMBL),]
#nrow(dgeAll$genes)
#nrow(entrez)
entrez <- left_join(dgeAll$genes, entrez,
by=c("ensembl_gene_id" = "ENSEMBL"))
entrez <- as.data.frame(entrez)
rownames(entrez) <- entrez$ensembl_gene_id
dgeAll$genes <- entrez
head(dgeAll$genes)
```
## Differential expression
For a standard `edgeR` diffex pipeline, apply TMM normalization.
Outside of a machine-learning context, we are not concerned with manually selecting the reference sample or excluding training samples from the TMM calculation.
```{r}
dgeAll <- calcNormFactors(dgeAll, method = "TMM")
```
Although it will be tough to compensate for batch effects that are so imbalanced, we will try by including hospital in the design formula.
### Design matrix
The original NKI samples and the blind validation samples from the NKI will be modelled as two separate groups.
```{r}
dgeAll$samples$hosp %>% levels()
dgeAll$samples$group %>% levels()
```
```{r}
design <- model.matrix(~Age + hosp + group, data = dgeAll$samples)
colnames(design) <- str_remove_all(str_remove_all(colnames(design), "hosp"),"group")
design[1:2,]
```
### Fit model
```{r}
#A wrapper function to perform all steps up until the final test
#We omit the final test to allow for greater flexibility with contrasts later on
fitmydiffex <- function(y, design, method = "QL", show.time = T){
stopifnot(method %in% c("QL", "LRT"))
start <- Sys.time()
#Normalize if it hasn't been done already
if(all(y$samples$norm.factors == 1)){
y <- calcNormFactors(y, method = "TMM")
}
#Estimate dispersions
y <- estimateDisp(y,design,robust = T)
#Fit model
if(method == "QL"){
fit <- glmQLFit(y, design)
method <- "QL"
} else {
fit <- glmFit(y,design)
method <- "LRT"
}
#Slow part ends here
end <- Sys.time()
if(show.time){print(end-start)}
#Return results
list(dge = y,
fit = fit,
method = method)
}
fit.group <- fitmydiffex(dgeAll, design = design)
```
### Dispersion plots
```{r}
plotBCV(fit.group$dge)
```
```{r}
plotQLDisp(fit.group$fit)
```
### Diffex genes: Cancer status
Using the QL framework, how many genes are differentially expressed in cancer vs healthy control?
```{r}
#colnames(design)[7] #"groupbreastCancer"
cancer.res <- glmQLFTest(fit.group$fit, coef=ncol(design))
decideTestsDGE(cancer.res) %>% summary()
```
What are the top expressed genes in cancer vs healthy control?
```{r}
topTags(cancer.res)
```
Filter out the pseudogenes and those without hgnc symbols/entrez IDs and look again:
```{r}
topTags(cancer.res, n = Inf) %>%
as.data.frame() %>%
filter(!str_detect(description, "pseudogene")) %>%
filter(hgnc_symbol != "" & !is.na(ENTREZID)) %>%
filter(FDR <= 0.05) %>%
head(30) %>% remove_rownames()
```
#### Pathways: Cancer status
Gene ontology analysis for biological process (BP) and KEGG pathway analysis.
```{r}
get_pathways <- function(res, ont = "BP", threshold = 0.05,
verbose = T){
#goana.DGELRT defines its own universe
goanna <- goana(res, species = "Hs", geneid = "ENTREZID")
go <- goanna %>%
topGO(ont = ont, number = Inf) %>%
mutate(fdr.up = p.adjust(P.Up, method = "fdr"),
fdr.down = p.adjust(P.Down, method = "fdr"))
#Add the go terms
goanna <- as.data.frame(goanna) %>%
rownames_to_column("GOID") %>%
dplyr::select(GOID, Term)
go <- left_join(go, goanna, by = "Term")
nup <- go %>% filter(fdr.up <= !!threshold) %>% nrow()
ndown <- go %>% filter(fdr.down <= !!threshold) %>% nrow()
if(verbose == T){
print(paste("Significantly upregulated GO", ont, "terms:", nup))
print(paste("Significantly downregulated GO", ont, "terms:", ndown))
}
kegg <- kegga(res, species = "Hs", geneid = "ENTREZID") %>%
topKEGG(number = Inf) %>%
mutate(fdr.up = p.adjust(P.Up, method = "fdr"),
fdr.down = p.adjust(P.Down, method = "fdr"))
keggup <- kegg %>% filter(fdr.up <= !!threshold) %>% nrow()
keggdown <- kegg %>% filter(fdr.down <= !!threshold) %>% nrow()
if(verbose == T){
print(paste("Significantly upregulated KEGG pathways:", keggup))
print(paste("Significantly downregulated KEGG pathways:", keggdown))
}
list(go = go,
kegg = kegg)
}
path.cancer.res <- get_pathways(cancer.res)
```
The top upregulated GO terms associated with cancer include many platelet and wound processes.
This does suggest that the classifier is picking up on endogenous platelet RNA and not RNA taken up in the tumor microenvironment.
```{r}
path.cancer.res$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Visualize the platelet degranulation pathway.
```{r}
platelet.go <- path.cancer.res$go %>%
filter(Term == "platelet degranulation") %>%
pull(GOID)
#Entrez gene ids
Rkeys(org.Hs.egGO2ALLEGS) <- platelet.go
stopifnot(all(row.names(fit.group$fit) == row.names(fit.group$dge$genes)))
#ind <- ids2indices(as.list(org.Hs.egGO2ALLEGS), #entrez gene ids
# fit.group$dge$genes$ENTREZID)
#fry(fit.group$dge, index=ind, design=design, contrast=colnames(design)[7])
ind <- fit.group$dge$genes$ENTREZID %in% as.data.frame(org.Hs.egGO2ALLEGS)$gene_id
barcodeplot(cancer.res$table$logFC, index = ind,
labels = c("healthyControl", "breastCancer"),
main = path.cancer.res$go %>%
filter(Term == "platelet degranulation") %>%
mutate(title = paste(Term, GOID, sep=", ")) %>%
pull(title)
)
```
Downregulated GO terms are an eclectic blend, but immune- and metabolism-related processes stand out.
RNA processing also features here.
```{r}
path.cancer.res$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
KEGG pathways can give us a more condensed view than GO terms. By far the most enriched is platelet activation.
```{r}
path.cancer.res$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Once again we see immune and RNA related pathways in the downregulated group.
```{r}
path.cancer.res$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
### Diffex genes: Hospital
Note: There is no "pathways" subheader for hospital, as those analyses will be included in each pairwise comparison.
Recall that these are the elements of the design matrix.
The original NKI samples and the new ones from the blind validation set are modelled separately.
```{r}
colnames(design)
```
We can fit an ANOVA-like test for batch effect among all hospitals by selecting multiple coefficients.
This will account for both age and cancer status, so this should narrow down the batch effect as much as possible.
```{r}
#Column names corresponding to hospital of origin
colnames(design)[3:6]
hosp.anova.res <- glmQLFTest(fit.group$fit, coef=3:6)
decideTestsDGE(hosp.anova.res) %>% summary()
```
Basically everything is significant if we do this, which is very bad.
Let's set up some contrasts to look at specific hospitals.
```{r}
hosp.contrasts <- makeContrasts(
blindvsNKI = blindNKI-NKI,
NKIvsMGH = NKI-MGH,
NKIvsVUMC = NKI-VUMC,
VUMCvsMGH = VUMC-MGH,
blindvsMGH = blindNKI-MGH,
blindvsVUMC = blindNKI-VUMC,
levels = design
)
hosp.contrasts
#Not true because (Intercept) is now Intercept
#stopifnot(all(colnames(fit.group$fit$coefficients) == rownames(hosp.contrasts)))
```
Apply the QLF test to each of the comparisons in the contrast and retrieve the number of DEGs in each.
Most contrasts have a lot of DEGs, which is not good but also not a surprise.
```{r}
hosp.res <- lapply(colnames(hosp.contrasts),
function(x) glmQLFTest(fit.group$fit,
contrast = hosp.contrasts[,x]))
names(hosp.res) <- colnames(hosp.contrasts)
lapply(hosp.res, function(x) summary(decideTests(x)))
```
Retrieve the most interesting columns for all the comparisons:
```{r}
hosp.res.df <- lapply(hosp.res, function(x) topTags(x, n = Inf))
hosp.res.df <- lapply(hosp.res.df,
function(x) as.data.frame(x) %>%
dplyr::select(hgnc_symbol, FDR, logFC:PValue,
description, ENTREZID, ensembl_gene_id)
%>% as.data.frame() #No tibbles
)
```
Set up an empty list for bundling pathway analyses together
```{r}
paths.hosp <- vector(mode = "list", length = length(hosp.res))
names(paths.hosp) <- names(hosp.res)
path.ind <- 0
```
#### Blind validation vs original NKI
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
The blindval group is quite balanced, the NKI group contains mostly cancers.
```{r}
dgeAll$samples %>%
filter(hosp %in% c("blindNKI", "NKI")) %>%
select(group, hosp) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
There are at least a couple of "obvious cancer genes" in here (SDCCAG8 up, NKTR up, TPT1 down, FUS up, NBPF10 up).
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
Upregulated GO terms include RNA and metabolic processes.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Kegg terms are similar.
```{r}
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05)
```
Downregulated GO terms and KEGG pathways include platelet and wound healing. This is notable because both processes were upregulated when comparing cancer vs healthy controls.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
This is the barcode plot for platelet degranulation in the blind validation set vs original NKI samples.
```{r}
barcodeplot(hosp.res$blindvsNKI$table$logFC, index = ind,
labels = c("NKI", "blind"),
main = path.cancer.res$go %>%
filter(Term == "platelet degranulation") %>%
mutate(title = paste(Term, GOID, sep=", ")) %>%
pull(title)
)
```
By contrast, this is how it looked for cancer vs non-cancer.
```{r}
barcodeplot(cancer.res$table$logFC, index = ind,
labels = c("healthyControl", "breastCancer"),
main = path.cancer.res$go %>%
filter(Term == "platelet degranulation") %>%
mutate(title = paste(Term, GOID, sep=", ")) %>%
pull(title)
)
```
#### NKI vs MGH
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
The MGH cohort is entirely cancers, the NKI group contains mostly cancers but with some controls.
```{r}
dgeAll$samples %>%
filter(hosp %in% c("NKI", "MGH")) %>%
select(group, hosp) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
Pathway results:
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
Like the previous comparison, we see a lot of RNA processing in the upregulated list when comparing original NKI samples to MGH.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Also like the previous comparison, we see platelet activation is downregulated in original NKI to MGH.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
#### NKI vs VUMC
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
VUMC is almost all controls, NKI is a mix but is skewed towards cancers.
```{r}
dgeAll$samples %>%
filter(hosp %in% c("NKI", "VUMC")) %>%
select(group, hosp) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Just like the previous comparisons, wound healing and platelet processes are downregulated.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
#### VUMC vs MGH
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
This is almost entirely confounded with case-control status.
```{r}
dgeAll$samples %>%
filter(hosp %in% c("VUMC", "MGH")) %>%
select(hosp, group) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
Pathway results:
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
Translational regulation and rRNA prevail among the upregulated pathways in VUMC vs MGH. Platelet activation is included among KEGG pathways.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Some immune processes among the results: but this may always be cancer vs healthy signal.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
#### Blind validation vs MGH
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
```{r}
dgeAll$samples %>%
filter(hosp %in% c("blindNKI", "MGH")) %>%
select(group, hosp) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
More RNA processing stuff here (blind validation vs MGH).
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Platelet processes again (blind validation vs MGH).
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
#### Blind validation vs VUMC
Set the analysis index.
```{r}
path.ind <- path.ind + 1
thispath <- names(paths.hosp)[path.ind]
thispath
```
```{r}
dgeAll$samples %>%
filter(hosp %in% c("blindNKI", "VUMC")) %>%
select(group, hosp) %>%
droplevels() %>% table()
```
Top 30 most diffex genes.
```{r}
hosp.res.df[[thispath]] %>% head(30)
```
```{r}
paths.hosp[[thispath]] <- get_pathways(hosp.res[[thispath]])
```
RNA processes prevail in blind validation vs VUMC.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
```
Like before, platelet activation is downregulated in blind validation vs VUMC.
```{r}
paths.hosp[[thispath]]$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.hosp[[thispath]]$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
#### Group comparisons
##### NKI and blindval vs all
A few additional contrasts to supplement the pairwise comparisons above.
```{r groupcontrasts}
groupContrasts <- makeContrasts(
blindvsall = blindNKI-(NKI+VUMC+MGH)/3,
NKIvsOriginalHosps = NKI-(VUMC+MGH)/2,
levels = design
)
qlf.blindvsall <- glmQLFTest(fit.group$fit, contrast=groupContrasts[,"blindvsall"])
paths.blindvsall <- get_pathways(qlf.blindvsall, verbose=F)
qlf.NKIvsHosps <- glmQLFTest(fit.group$fit, contrast=groupContrasts[,"NKIvsOriginalHosps"])
paths.NKIvsHosps <- get_pathways(qlf.NKIvsHosps, verbose=F)
```
For blind val:
```{r}
#Pathway results for blind NKI vs all other hospitals
paths.blindvsall$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.blindvsall$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.blindvsall$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.blindvsall$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
For NKI:
```{r}
#Pathway results for NKI vs other hospitals in original dataset:
paths.NKIvsHosps$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.NKIvsHosps$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.NKIvsHosps$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.NKIvsHosps$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
##### VUMC vs all
```{r groupcontrasts2}
contrastsVUMC <- makeContrasts(
VUMCvsall = VUMC-(NKI+blindNKI+MGH)/3,
VUMCvsOriginalHosps = VUMC-(NKI+MGH)/2,
levels = design
)
qlf.VUMCvsall <- glmQLFTest(fit.group$fit, contrast=contrastsVUMC[,"VUMCvsall"])
paths.VUMCvsall <- get_pathways(qlf.VUMCvsall, verbose=F)
qlf.VUMCvsHosps <- glmQLFTest(fit.group$fit, contrast=contrastsVUMC[,"VUMCvsOriginalHosps"])
paths.VUMCvsHosps <- get_pathways(qlf.VUMCvsHosps, verbose=F)
```
Pathway results for VUMC vs all other hospitals
```{r}
paths.VUMCvsall$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.VUMCvsall$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.VUMCvsall$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.VUMCvsall$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
Vs original dataset
```{r}
paths.VUMCvsHosps$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.VUMCvsHosps$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.VUMCvsHosps$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.VUMCvsHosps$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
##### MGH vs all
```{r groupcontrasts3}
contrastsMGH <- makeContrasts(
MGHvsall = MGH-(NKI+blindNKI+VUMC)/3,
MGHvsOriginalHosps = MGH-(NKI+VUMC)/2,
levels = design
)
qlf.MGHvsall <- glmQLFTest(fit.group$fit, contrast=contrastsMGH[,"MGHvsall"])
paths.MGHvsall <- get_pathways(qlf.MGHvsall, verbose=F)
qlf.MGHvsHosps <- glmQLFTest(fit.group$fit, contrast=contrastsMGH[,"MGHvsOriginalHosps"])
paths.MGHvsHosps <- get_pathways(qlf.MGHvsHosps, verbose=F)
```
Pathway results for MGH vs all other hospitals
```{r}
paths.MGHvsall$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.MGHvsall$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.MGHvsall$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.MGHvsall$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
Vs original dataset
```{r}
paths.MGHvsHosps$go %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.MGHvsHosps$go %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
paths.MGHvsHosps$kegg %>%
arrange(fdr.up) %>%
filter(fdr.up <= 0.05) %>%
head(30)
paths.MGHvsHosps$kegg %>%
arrange(fdr.down) %>%
filter(fdr.down <= 0.05) %>%
head(30)
```
## Diffex: Healthy controls
Since case-control status is so confounded by isolation location, what if we subset down to just controls?
```{r}
dgeControls <- dgeAll[, dgeAll$samples$group == "healthyControl"]
dgeControls$samples <- droplevels(dgeControls$samples)
dgeControls$samples %>%
select(hosp, group) %>% table()
```
Create design formula:
```{r}
designControls <- model.matrix(~Age + hosp, data = dgeControls$samples)
colnames(designControls) <- str_remove_all(colnames(designControls), "hosp")