annotate DESeq_visualization.Rmd @ 0:61c184384d02 draft default tip

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