forked from snakemake-workflows/rna-seq-star-deseq2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeseq2.R
31 lines (24 loc) · 755 Bytes
/
deseq2.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
log <- file(snakemake@log[[1]], open="wt")
sink(log)
sink(log, type="message")
library("DESeq2")
parallel <- FALSE
if (snakemake@threads > 1) {
library("BiocParallel")
# setup parallelization
register(MulticoreParam(snakemake@threads))
parallel <- TRUE
}
dds <- readRDS(snakemake@input[[1]])
contrast <- c("condition", snakemake@params[["contrast"]])
res <- results(dds, contrast=contrast, parallel=parallel)
# shrink fold changes for lowly expressed genes
res <- lfcShrink(dds, contrast=contrast, res=res)
# sort by p-value
res <- res[order(res$padj),]
# TODO explore IHW usage
# store results
pdf(snakemake@output[["ma_plot"]])
plotMA(res, ylim=c(-2,2))
dev.off()
write.table(as.data.frame(res), file=snakemake@output[["table"]])