comparison rmarkdown_report.Rmd @ 0:55d2db17c67c draft

planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author mingchen0919
date Fri, 14 Dec 2018 00:21:26 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:55d2db17c67c
1 ---
2 title: 'Aurora DESeq2 Report'
3 output:
4 html_document:
5 highlight: pygments
6 ---
7
8 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
9 knitr::opts_chunk$set(error = TRUE, echo = FALSE)
10 ```
11
12 ```{css, echo=FALSE}
13 pre code, pre, code {
14 white-space: pre !important;
15 overflow-x: scroll !important;
16 word-break: keep-all !important;
17 word-wrap: initial !important;
18 }
19 ```
20
21 ```{r, echo=FALSE}
22 # to make the css theme to work, <link></link> tags cannot be added directly
23 # as <script></script> tags as below.
24 # it has to be added using a code chunk with the htmltool functions!!!
25 css_link = tags$link()
26 css_link$attribs = list(rel="stylesheet", href="vakata-jstree-3.3.5/dist/themes/default/style.min.css")
27 css_link
28 ```
29
30 ```{r, eval=FALSE, echo=FALSE}
31 # this code chunk is purely for adding comments
32 # below is to add jQuery and jstree javascripts
33 ```
34
35 <script src="vakata-jstree-3.3.5/dist/jstree.min.js"></script>
36
37
38 ```{r, eval=FALSE, echo=FALSE}
39 # this code chunk is purely for adding comments
40 # javascript code below is to build the file tree interface
41 # see this for how to implement opening hyperlink: https://stackoverflow.com/questions/18611317/how-to-get-i-get-leaf-nodes-in-jstree-to-open-their-hyperlink-when-clicked-when
42 ```
43 <script>
44 jQuery(function () {
45 // create an instance when the DOM is ready
46 jQuery('#jstree').jstree().bind("select_node.jstree", function (e, data) {
47 window.open( data.node.a_attr.href, data.node.a_attr.target )
48 });
49 });
50 </script>
51
52
53 ```{r, eval=FALSE, echo=FALSE}
54 ---
55 # ADD YOUR DATA ANALYSIS CODE AND MARKUP TEXT BELOW TO EXTEND THIS R MARKDOWN FILE
56 ---
57 ```
58
59 ## DESeq2 analysis
60
61 ```{r echo=FALSE}
62 # import count data
63 count_data = read.csv(opt$X_A, row.names = 1, header = TRUE)
64 # import column data
65 coldata = read.csv(opt$X_B, row.names = 1, header = TRUE)[colnames(count_data),,drop=FALSE]
66 ```
67
68 ```{r}
69 f = gsub('~', '~ 1 +', opt$X_C) # build formula
70 dds = DESeqDataSetFromMatrix(countData = count_data,
71 colData = coldata,
72 design = formula(f))
73
74
75 # prefiltering
76 keep <- rowSums(counts(dds)) >= 10
77 dds <- dds[keep,]
78
79 # Run DESeq
80 if (opt$X_T == 'LRT') {
81 reduced_f = gsub(paste0('\\+\\s*', opt$X_D), '', f)
82 dds = DESeq(dds, test=opt$X_T, fitType = opt$X_H, reduced = formula(reduced_f))
83 } else {
84 dds = DESeq(dds, test=opt$X_T, fitType = opt$X_H)
85 }
86
87 ## Differential expression test results
88 res = results(dds, contrast = c(opt$X_D, opt$X_E, opt$X_F), alpha = opt$X_I)
89 DT::datatable(as.data.frame(res))
90 ```
91
92
93 ```{r}
94 # save all padj sorted res to tool output directory
95 padj_sorted_res = res[order(res$padj), ]
96 write.table(padj_sorted_res,
97 file = paste0(opt$X_d, '/padj-sorted-genes.txt'),
98 quote = FALSE)
99
100 # save significant genes to a file in tool output directory
101 sig_res = res[(res$padj < opt$X_I) & !is.na(res$padj), ]
102 sig_res_sorted = sig_res[order(sig_res$padj), ]
103 sig_res_sorted$feature_id = rownames(sig_res_sorted)
104 n_col = ncol(sig_res_sorted)
105 sig_res_sorted = sig_res_sorted[, c(n_col, 1:(n_col - 1))]
106 write.table(sig_res_sorted,
107 file = paste0(opt$X_d, '/padj-sorted-significant-genes.txt'),
108 quote = FALSE, row.names = FALSE)
109 ```
110
111 ## MA-plot
112
113 ```{r warning=FALSE}
114 log_fold_change = res$log2FoldChange
115 base_mean = res$baseMean
116 significant = res$padj
117 significant[significant < 0.1] = 'yes'
118 significant[significant != 'yes'] = 'no'
119
120 maplot_df = data.frame(log_fold_change, base_mean, significant)
121 maplot_df = maplot_df[!is.na(maplot_df$significant), ]
122 p = ggplot(data = maplot_df) +
123 geom_point(mapping = aes(log(base_mean), log_fold_change, color = significant),
124 size = 0.5) +
125 scale_color_manual(name = 'Significant',
126 values = c('no' = 'black', 'yes' = 'red'),
127 labels = c('No', 'Yes')) +
128 xlab('Log base mean') +
129 ylab('Log fold change') +
130 theme_classic()
131
132 plotly::ggplotly(p)
133 ```
134
135
136 ## Heatmap of count matrix
137
138 ```{r}
139 ntd <- normTransform(dds)
140 select <- order(rowMeans(counts(dds,normalized=TRUE)),
141 decreasing=TRUE)[1:20]
142 df <- as.data.frame(colData(dds)[, -ncol(colData(dds))])
143 pheatmap(assay(ntd)[select,], annotation_col=df)
144 ```
145
146
147 ## Principle component analysis plot
148
149 ```{r}
150 vsd <- vst(dds, blind=FALSE)
151 p = plotPCA(vsd, intgroup=c(opt$X_D)) +
152 scale_color_discrete(name = 'Group') +
153 theme_classic()
154 ggplotly(p)
155 ```
156