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