annotate DESeq_visualization.Rmd @ 10:ec09fb119c67 draft

Uploaded
author mingchen0919
date Mon, 07 Aug 2017 18:26:39 -0400
parents 507e408cd6cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
1 ---
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
2 title: 'DESeq2: Visualization'
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
3 output:
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
4 html_document:
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
5 number_sections: true
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
6 toc: true
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
7 theme: cosmo
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
8 highlight: tango
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
9 ---
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
10
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
11 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
12 knitr::opts_chunk$set(
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
13 echo = ECHO
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
14 )
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
15
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
16 library(stringi)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
17 library(DESeq2)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
18 library(pheatmap)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
19 library(PoiClaClu)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
20 library(RColorBrewer)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
21 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
22
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
23 # Import workspace
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
24
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
25 ```{r eval=TRUE}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
26 fcp = file.copy("DESEQ_WORKSPACE", "deseq.RData")
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
27 load("deseq.RData")
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
28 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
29
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
30 # Visualization
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
31
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
32 ## Heatmaps of sample-to-sample distances {.tabset}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
33
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
34 ### rlog-transformed values
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
35
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
36 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
37 sampleDistMatrix <- as.matrix( sampleDists )
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
38 colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
39 pheatmap(sampleDistMatrix,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
40 # clustering_distance_rows = sampleDists,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
41 clustering_distance_cols = sampleDists,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
42 col = colors)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
43 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
44
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
45 ### Poisson Distance
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
46
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
47 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
48 count_t = t(counts(dds))
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
49 rownames(count_t) = colnames(counts(dds))
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
50 poisd <- PoissonDistance(count_t)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
51 samplePoisDistMatrix <- as.matrix( poisd$dd )
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
52 rownames(samplePoisDistMatrix) = rownames(count_t)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
53 colnames(samplePoisDistMatrix) = rownames(count_t)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
54 pheatmap(samplePoisDistMatrix,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
55 # clustering_distance_rows = poisd$dd,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
56 clustering_distance_cols = poisd$dd,
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
57 col = colors)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
58 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
59
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
60
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
61 ## PCA plots {.tabset}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
62
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
63 ### Using `plotPCA()` function
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
64
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
65 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
66 # interest groups
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
67 col_index = as.numeric(strsplit("INTGROUPS_PCA", ',')[[1]])
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
68 intgroup_pca = colnames(sample_table)[col_index]
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
69 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
70
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
71 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
72 plotPCA(rld, intgroup = intgroup_pca)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
73 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
74
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
75
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
76 ### Using *ggplot2*
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
77
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
78 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
79 pcaData <- plotPCA(rld, intgroup = intgroup_pca, returnData = TRUE)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
80 percentVar <- round(100 * attr(pcaData, "percentVar"))
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
81 ggplot(pcaData, aes(x = PC1, y = PC2, color = time)) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
82 geom_point(size =3) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
83 xlab(paste0("PC1: ", percentVar[1], "% variance")) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
84 ylab(paste0("PC2: ", percentVar[2], "% variance")) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
85 coord_fixed()
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
86 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
87
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
88 ### PCA data table
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
89
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
90 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
91 knitr::kable(pcaData)
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
92 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
93
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
94
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
95 ## MDS plots {.tabset}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
96
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
97 ### Using rlog-transformed values
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
98
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
99 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
100 mds <- as.data.frame(colData(rld)) %>%
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
101 cbind(cmdscale(sampleDistMatrix))
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
102 mds
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
103 ggplot(mds, aes(x = `1`, y = `2`, col = time)) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
104 geom_point(size = 3) + coord_fixed()
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
105 ```
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
106
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
107 ### Using the *Poisson Distance*
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
108
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
109 ```{r}
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
110 mdsPois <- as.data.frame(colData(dds)) %>%
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
111 cbind(cmdscale(samplePoisDistMatrix))
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
112 ggplot(mdsPois, aes(x = `1`, y = `2`, col = time)) +
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
113 geom_point(size = 3) + coord_fixed()
507e408cd6cc Uploaded
mingchen0919
parents:
diff changeset
114 ```