-
Notifications
You must be signed in to change notification settings - Fork 7
/
runScripts.R
87 lines (75 loc) · 2.28 KB
/
runScripts.R
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
runDESeq2 <- function(e) {
padj <- rep(NA, nrow(e))
# cpm=FALSE means don't do any filtering
keep <- cpmFilter(e, cpm=FALSE)
e <- e[keep,]
dds <- DESeqDataSetFromMatrix(exprs(e), DataFrame(pData(e)), ~ condition)
dds <- DESeq(dds,quiet=TRUE)
res <- results(dds)
# slightly different bc DESeq2 filters internally
padj[keep] <- res$padj
padj[is.na(padj)] <- 1
padj
}
runEdgeR <- function(e) {
padj <- rep(NA, nrow(e))
keep <- cpmFilter(e, cpm=TRUE)
e <- e[keep,]
design <- model.matrix(~ condition, pData(e))
dgel <- DGEList(exprs(e))
dgel <- calcNormFactors(dgel)
# current recommendation (Sep 2016) according to vignette:
dgel <- estimateDisp(dgel, design)
edger.fit <- glmFit(dgel, design)
edger.lrt <- glmLRT(edger.fit)
pvals <- edger.lrt$table$PValue
padj[keep] <- p.adjust(pvals,method="BH")
padj[is.na(padj)] <- 1
padj
}
runEdgeRQL <- function(e) {
padj <- rep(NA, nrow(e))
keep <- cpmFilter(e, cpm=TRUE)
e <- e[keep,]
design <- model.matrix(~ condition, pData(e))
dgel <- DGEList(exprs(e))
dgel <- calcNormFactors(dgel)
# current recommendation (Sep 2016) according to vignette:
dgel <- estimateDisp(dgel, design)
edger.fit <- glmQLFit(dgel,design)
edger.qlf <- glmQLFTest(edger.fit)
pvals <- edger.qlf$table$PValue
padj[keep] <- p.adjust(pvals,method="BH")
padj[is.na(padj)] <- 1
padj
}
runVoom <- function(e) {
padj <- rep(NA, nrow(e))
keep <- cpmFilter(e, cpm=TRUE)
e <- e[keep,]
design <- model.matrix(~ condition, pData(e))
dgel <- DGEList(exprs(e))
dgel <- calcNormFactors(dgel)
v <- voom(dgel,design,plot=FALSE)
fit <- lmFit(v,design)
fit <- eBayes(fit)
tt <- topTable(fit,coef=ncol(design),n=nrow(dgel),sort.by="none")
pvals <- tt$P.Value
padj[keep] <- p.adjust(pvals,method="BH")
padj[is.na(padj)] <- 1
padj
}
cpmFilter <- function(e, cpm=TRUE) {
if (cpm) {
# this is the filtering recommendation from Gordon Smyth
# https://support.bioconductor.org/p/85511/#85514
L <- min(colSums(exprs(e))/1e6)
dgel <- DGEList(exprs(e))
# here I use 3 even for the heldout set (n=7/8),
# because otherwise the filtering is too strict
# to the detriment of edgeR and limma-voom performance
return(rowSums(cpm(dgel) > 10/L) >= 3)
} else {
return(rowSums(exprs(e)) > 0)
}
}