-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_sample_heatmap_from_deseq.R
47 lines (32 loc) · 1.51 KB
/
draw_sample_heatmap_from_deseq.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
draw_sample_heatmap_from_deseq = function(deseq_object, normalization = "vst"){
# this is all essentially copy paste from the DESEQ2 vignette
library(colorRamps)
library(RColorBrewer)
library(pheatmap)
colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
if(normalization == "poisson"){
library("PoiClaClu")
poisd <- PoissonDistance(t(counts(deseq_object,normalized = TRUE)))
samplePoisDistMatrix <- as.matrix( poisd$dd )
rownames(samplePoisDistMatrix) <-colnames(deseq_object)
colnames(samplePoisDistMatrix) <-colnames(deseq_object)
simple_heat = pheatmap(samplePoisDistMatrix,
clustering_distance_rows = poisd$dd,
clustering_distance_cols = poisd$dd,
col = colors)
return(simple_heat)
}else if(normalization == "rlog"){
transformed_dds <- rlog(deseq_object, blind = FALSE)
}else if(normalization == "vst"){
transformed_dds <- vst(deseq_object, blind = FALSE)
}
sampleDists <- dist(t(assay(transformed_dds)))
sampleDistMatrix <- as.matrix( sampleDists )
rownames(sampleDistMatrix) <- NULL
colnames(sampleDistMatrix) <- colnames(deseq_object)
simple_heat = pheatmap(sampleDistMatrix,
clustering_distance_rows = sampleDists,
clustering_distance_cols = sampleDists,
col = colors)
return(simple_heat)
}