forked from cribbslab/deseq2_report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Heatmap.R
44 lines (33 loc) · 1.23 KB
/
Heatmap.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
plotUpDownSigGenes <- function(results, colNums, rld, title) {
# make the lists
upgenes <- rownames(head(results[ order( results$log2FoldChange ), ], n=20))
downgenes <- rownames(head(results[ order( -results$log2FoldChange ), ], n=20))
# this gives us the rows we want
rows <- match(upgenes, row.names(rld))
mat <- assay(rld)[rows,colNums]
mat <- mat - rowMeans(mat)
# the labels are hard coded at the moment :(
df <- as.data.frame(colData(rld)[c("labelA","labelB")])
pheatmap(mat, fontsize=5, annotation_col=df, main=paste(title,"top 20 up genes"))
# this gives us the rows we want
rows <- match(downgenes, row.names(rld))
mat <- assay(rld)[rows,colNums]
mat <- mat - rowMeans(mat)
df <- as.data.frame(colData(rld)[c("labelA","labelB")])
pheatmap(mat, fontsize=5, annotation_col=df, main=paste(title,"top 20 down genes"))
}
contrastDEGenes <- subset(results(dds, contrast=c("A","B")), padj < 0.05)
# this part is kind of funky
# the function needs to know which columns
# correspond to the samples (to pull from rld)
aCols <- c(1,2,3)
bCols <- c(4,5,6)
# get the log transforms again
rld <- rlog(dds, blind=F)
# call
plotUpDownSigGenes(
contrastDEGenes,
c(aCols, bCols),
rld,
"Title for the plot"
)