# HG changeset patch # User mingchen0919 # Date 1510066977 18000 # Node ID 61c184384d02fe81c8c7df6beb464e8d9852ee9d planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_deseq2 diff -r 000000000000 -r 61c184384d02 DESeq.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq.Rmd Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,97 @@ +--- +title: 'DESeq2: Perform DESeq analysis' +output: + html_document: + number_sections: true + toc: true + theme: cosmo + highlight: tango +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set( + echo = ECHO, + error = TRUE +) +``` + +```{r} +str(opt) +``` + +# `DESeqDataSet` object + +```{r eval=FALSE} +count_files = strsplit(opt$count_files, ',')[[1]] +sample_table = read.table(opt$sample_table, header = TRUE) + +## copy count files into working directory +file_copy = file.copy(count_files, sample_table$fileName, overwrite = TRUE) + +## DESeqDataSet object +dds = DESeqDataSetFromHTSeqCount(sampleTable = sample_table, + directory = './', + design = DESIGN_FORMULA) +dds +``` + +# Pre-filtering the dataset. + +We can remove the rows that have 0 or 1 count to reduce object size and increase the calculation speed. + +* Number of rows before pre-filtering +```{r eval=FALSE} +nrow(dds) +``` + +* Number of rows after pre-filtering +```{r eval=FALSE} +dds = dds[rowSums(counts(dds)) > 1, ] +nrow(dds) +``` + +# Peek at data {.tabset} + +## Count Data + +```{r eval=FALSE} +datatable(head(counts(dds), 100), style="bootstrap", + class="table-condensed", options = list(dom = 'tp', scrollX = TRUE)) +``` + +## Sample Table + +```{r eval=FALSE} +datatable(sample_table, style="bootstrap", + class="table-condensed", options = list(dom = 'tp', scrollX = TRUE)) +``` + +# Sample distance on variance stabilized data {.tabset} + +## `rlog` Stabilizing transformation + +```{r eval=FALSE} +rld = rlog(dds, blind = FALSE) +datatable(head(assay(rld), 100), style="bootstrap", + class="table-condensed", options = list(dom = 'tp', scrollX = TRUE)) +``` + +## Sample distance + +```{r eval=FALSE} +sampleDists <- dist(t(assay(rld))) +sampleDists +``` + +# Differential expression analysis + +```{r eval=FALSE} +dds <- DESeq(dds) +``` + +```{r eval=FALSE} +rm("opt") +save(list=ls(all.names = TRUE), file='DESEQ_WORKSPACE') +``` + + diff -r 000000000000 -r 61c184384d02 DESeq.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq.xml Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,127 @@ + + + pandoc + r-getopt + r-rmarkdown + r-plyr + bioconductor-deseq2 + r-stringr + r-highcharter + r-dt + r-reshape2 + r-plotly + r-formattable + r-htmltools + r-pheatmap + + + An R Markdown tool to perform DESeq analysis. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @article{love2014moderated, + title={Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2}, + author={Love, Michael I and Huber, Wolfgang and Anders, Simon}, + journal={Genome biology}, + volume={15}, + number={12}, + pages={550}, + year={2014}, + publisher={BioMed Central} + } + + + @article{allaire2016rmarkdown, + title={rmarkdown: Dynamic Documents for R, 2016}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff + and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + journal={R package version 0.9}, + volume={6}, + year={2016} + } + + + @book{xie2015dynamic, + title={Dynamic Documents with R and knitr}, + author={Xie, Yihui}, + volume={29}, + year={2015}, + publisher={CRC Press} + } + + + @misc{pheatmap2015, + title = {pheatmap: Pretty Heatmaps}, + author = {Raivo Kolde}, + year = {2015}, + note = {R package version 1.0.8}, + url = {https://CRAN.R-project.org/package=pheatmap}, + } + + + @misc{dt2016, + title = {DT: A Wrapper of the JavaScript Library 'DataTables'}, + author = {Yihui Xie}, + year = {2016}, + note = {R package version 0.2}, + url = {https://CRAN.R-project.org/package=DT}, + } + + + \ No newline at end of file diff -r 000000000000 -r 61c184384d02 DESeq_render.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_render.R Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,91 @@ +library(getopt) +library(rmarkdown) +library(htmltools) +library(dplyr) +library(stringi) +library(DESeq2) +library(pheatmap) +library(RColorBrewer) + +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file('warnings_and_errors.txt') +sink(zz) +sink(zz, type = 'message') + ##---------below is the code for rendering .Rmd templates----- + + ##=============STEP 1: handle command line arguments========== + ## + ##============================================================ + # column 1: the long flag name + # column 2: the short flag alias. A SINGLE character string + # column 3: argument mask + # 0: no argument + # 1: argument required + # 2: argument is optional + # column 4: date type to which the flag's argument shall be cast. + # possible values: logical, integer, double, complex, character. + #------------------------------------------------------------- + #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++ + # 1. short flag alias should match the flag in the command section in the XML file. + # 2. long flag name can be any legal R variable names + # 3. two names in args_list can have common string but one name should not be a part of another name. + # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems. + #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + args_list=list() + ##------- 1. input data --------------------- + args_list$ECHO = c('echo', 'e', '1', 'character') + args_list$COUNT_FILES = c('count_files', 'c', '1', 'character') + args_list$SAMPLE_TABLE = c('sample_table', 'S', '1', 'character') + args_list$DESIGN_FORMULA = c('design_formula', 'p', '1', 'character') + ##--------2. output report and outputs -------------- + args_list$REPORT_HTML = c('report_html', 'r', '1', 'character') + args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character') + args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character') + args_list$WORKSPACE = c('deseq_workspace', 'w', '1', 'character') + ##--------3. .Rmd templates in the tool directory ---------- + args_list$deseq_RMD = c('deseq_rmd', 't', '1', 'character') + ##----------------------------------------------------------- + opt = getopt(t(as.data.frame(args_list))) + + + + ##=======STEP 2: create report directory (optional)========== + ## + ##=========================================================== + dir.create(opt$report_dir) + + ##=STEP 3: replace placeholders in .Rmd with argument values= + ## + ##=========================================================== + #++ need to replace placeholders with args values one by one+ + readLines(opt$deseq_rmd) %>% + (function(x) { + gsub('ECHO', opt$echo, x) + }) %>% + (function(x) { + gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x) + }) %>% + (function(x) { + gsub('DESIGN_FORMULA', opt$design_formula, x) + }) %>% + (function(x) { + gsub('REPORT_DIR', opt$output_dir, x) + }) %>% + (function(x) { + fileConn = file('deseq.Rmd') + writeLines(x, con=fileConn) + close(fileConn) + }) + + + ##=============STEP 4: render .Rmd templates================= + ## + ##=========================================================== + render('deseq.Rmd', output_file = opt$report_html) + + + ##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file diff -r 000000000000 -r 61c184384d02 DESeq_render_ori.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_render_ori.R Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,77 @@ +library(getopt) +library(rmarkdown) +library(htmltools) +library(dplyr) + +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file('warnings_and_errors.txt') +sink(zz) +sink(zz, type = 'message') +##---------below is the code for rendering .Rmd templates----- + +##=============STEP 1: handle command line arguments========== +## +##============================================================ +# column 1: the long flag name +# column 2: the short flag alias. A SINGLE character string +# column 3: argument mask +# 0: no argument +# 1: argument required +# 2: argument is optional +# column 4: date type to which the flag's argument shall be cast. +# possible values: logical, integer, double, complex, character. +#------------------------------------------------------------- +#++++++++++++++++++++ Best practice ++++++++++++++++++++++++++ +# 1. short flag alias should match the flag in the command section in the XML file. +# 2. long flag name can be any legal R variable names +# 3. two names in args_list can have common string but one name should not be a part of another name. +# for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems. +#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +args_list=list() +##------- 1. input data --------------------- +args_list$ECHO = c('echo', 'e', '1', 'character') +##--------2. output report and outputs -------------- +args_list$REPORT_HTML = c('report_html', 'r', '1', 'character') +args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character') +args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character') +##--------3. .Rmd templates in the tool directory ---------- +args_list$TOOL_TEMPLATE_RMD = c('tool_template_rmd', 't', '1', 'character') +##----------------------------------------------------------- +opt = getopt(t(as.data.frame(args_list))) + + + +##=======STEP 2: create report directory (optional)========== +## +##=========================================================== +dir.create(opt$report_dir) + +##=STEP 3: replace placeholders in .Rmd with argument values= +## +##=========================================================== +#++ need to replace placeholders with args values one by one+ +readLines(opt$tool_template_rmd) %>% + (function(x) { + gsub('ECHO', opt$echo, x) + }) %>% + (function(x) { + gsub('REPORT_DIR', opt$output_dir, x) + }) %>% + (function(x) { + fileConn = file('tool_template.Rmd') + writeLines(x, con=fileConn) + close(fileConn) + }) + + +##=============STEP 4: render .Rmd templates================= +## +##=========================================================== +render('tool_template.Rmd', output_file = opt$report_html) + + +##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file diff -r 000000000000 -r 61c184384d02 DESeq_results.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_results.Rmd Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,85 @@ +--- +title: 'DESeq2: Results' +output: + html_document: + number_sections: true + toc: true + theme: cosmo + highlight: tango +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set( + echo = ECHO +) + +library(DESeq2) +library(pheatmap) +library(genefilter) +``` + +# Import workspace + +```{r eval=TRUE} +fcp = file.copy("DESEQ_WORKSPACE", "deseq.RData") +load("deseq.RData") +``` + +# Results {.tabset} + +## Result table + +```{r} +group = colnames(sample_table)[CONTRAST_GROUP] +res <- results(dds, contrast = c(group, 'TREATMENT_LEVEL', 'CONDITION_LEVEL')) +datatable(as.data.frame(res), style="bootstrap", filter = 'top', + class="table-condensed", options = list(dom = 'tp', scrollX = TRUE)) +``` + +## Result summary + +```{r} +summary(res) +``` + + +# MA-plot {.tabset} + +## Shrinked with `lfcShrink()` function + +```{r eval=FALSE} +shrink_res = DESeq2::lfcShrink(dds, contrast = c(group, 'TREATMENT_LEVEL', 'CONDITION_LEVEL'), res=res) +plotMA(shrink_res) +``` + +## Shrinked with Bayesian procedure + +```{r} +plotMA(res) +``` + + +# Histogram of p values + +```{r} +hist(res$pvalue[res$baseMean > 1], breaks = 0:20/20, + col = "grey50", border = "white", main = "", + xlab = "Mean normalized count larger than 1") +``` + + +# Gene clustering + +```{r} +group_index = as.numeric(strsplit("CLUSTERING_GROUPS", ',')[[1]]) +clustering_groups = colnames(sample_table)[group_index] + +topVarGenes <- head(order(rowVars(assay(rld)), decreasing = TRUE), 20) +mat <- assay(rld)[ topVarGenes, ] +mat <- mat - rowMeans(mat) +annotation_col <- as.data.frame(colData(rld)[, clustering_groups]) +colnames(annotation_col) = clustering_groups +rownames(annotation_col) = colnames(mat) +pheatmap(mat, annotation_col = annotation_col) +``` + diff -r 000000000000 -r 61c184384d02 DESeq_results.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_results.xml Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,139 @@ + + + pandoc + bioconductor-deseq2 + r-getopt + r-rmarkdown + r-plyr + r-stringr + r-highcharter + r-dt + r-reshape2 + r-plotly + r-formattable + r-htmltools + r-pheatmap + + + An R Markdown tool to display DESeq analysis. + + + + + + + + + + + + + + + + + + + + + + + + + + + + @article{love2014moderated, + title={Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2}, + author={Love, Michael I and Huber, Wolfgang and Anders, Simon}, + journal={Genome biology}, + volume={15}, + number={12}, + pages={550}, + year={2014}, + publisher={BioMed Central} + } + + + @article{allaire2016rmarkdown, + title={rmarkdown: Dynamic Documents for R, 2016}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + journal={R package version 0.9}, + volume={6}, + year={2016} + } + + + @book{xie2015dynamic, + title={Dynamic Documents with R and knitr}, + author={Xie, Yihui}, + volume={29}, + year={2015}, + publisher={CRC Press} + } + + + @misc{pheatmap2015, + title = {pheatmap: Pretty Heatmaps}, + author = {Raivo Kolde}, + year = {2015}, + note = {R package version 1.0.8}, + url = {https://CRAN.R-project.org/package=pheatmap}, + } + + + @misc{dt2016, + title = {DT: A Wrapper of the JavaScript Library 'DataTables'}, + author = {Yihui Xie}, + year = {2016}, + note = {R package version 0.2}, + url = {https://CRAN.R-project.org/package=DT}, + } + + + \ No newline at end of file diff -r 000000000000 -r 61c184384d02 DESeq_results_render.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_results_render.R Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,120 @@ +##======= Handle arguments from command line ======== +# setup R error handline to go to stderr +options(show.error.messages=FALSE, + error=function(){ + cat(geterrmessage(), file=stderr()) + quit("no", 1, F) + }) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + +# suppress warning +options(warn = -1) + +options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) +args = commandArgs(trailingOnly=TRUE) + +suppressPackageStartupMessages({ + library(getopt) + library(tools) +}) + +# column 1: the long flag name +# column 2: the short flag alias. A SINGLE character string +# column 3: argument mask +# 0: no argument +# 1: argument required +# 2: argument is optional +# column 4: date type to which the flag's argument shall be cast. +# possible values: logical, integer, double, complex, character. +spec_list=list() + +##------- 1. input data --------------------- +spec_list$ECHO = c('echo', 'e', '1', 'character') +spec_list$DESEQ_WORKSPACE = c('deseq_workspace', 'w', '1', 'character') +spec_list$SAMPLE_TABLE = c('sample_table', 's', '1', 'character') +spec_list$CONTRAST_GROUP = c('contrast_group', 'c', '1', 'character') +spec_list$TREATMENT_LEVEL = c('treatment_level', 't', '1', 'character') +spec_list$CONDITION_LEVEL = c('condition_level', 'k', '1', 'character') +spec_list$CLUSTERING_GROUPS = c('clustering_groups', 'm', '1', 'character') + +##--------2. output report and report site directory -------------- +spec_list$OUTPUT_HTML = c('deseq_results_html', 'o', '1', 'character') +spec_list$OUTPUT_DIR = c('deseq_results_dir', 'd', '1', 'character') + +##--------3. Rmd templates sitting in the tool directory ---------- + +spec_list$DESEQ_VISUALIZATION_RMD = c('deseq_results_rmd', 'D', '1', 'character') + + + +##------------------------------------------------------------------ + +spec = t(as.data.frame(spec_list)) +opt = getopt(spec) +# arguments are accessed by long flag name (the first column in the spec matrix) +# NOT by element name in the spec_list +# example: opt$help, opt$expression_file +##====== End of arguments handling ========== + +#------ Load libraries --------- +library(rmarkdown) +library(plyr) +library(stringr) +library(dplyr) +library(highcharter) +library(DT) +library(reshape2) +# library(Kmisc) +library(plotly) +library(formattable) +library(htmltools) + + +#----- 1. create the report directory ------------------------ +system(paste0('mkdir -p ', opt$deseq_results_dir)) + + +#----- 2. generate Rmd files with Rmd templates -------------- +# a. templates without placeholder variables: +# copy templates from tool directory to the working directory. +# b. templates with placeholder variables: +# substitute variables with user input values and place them in the working directory. + + +#----- 01 DESeq_results.Rmd ----------------------- +readLines(opt$deseq_results_rmd) %>% + (function(x) { + gsub('ECHO', opt$echo, x) + }) %>% + (function(x) { + gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x) + }) %>% + (function(x) { + gsub('CONTRAST_GROUP', opt$contrast_group, x) + }) %>% + (function(x) { + gsub('TREATMENT_LEVEL', opt$treatment_level, x) + }) %>% + (function(x) { + gsub('CONDITION_LEVEL', opt$condition_level, x) + }) %>% + (function(x) { + gsub('CLUSTERING_GROUPS', opt$clustering_groups, x) + }) %>% + (function(x) { + gsub('OUTPUT_DIR', opt$deseq_results_dir, x) + }) %>% + (function(x) { + fileConn = file('DESeq_results.Rmd') + writeLines(x, con=fileConn) + close(fileConn) + }) + + +#------ 3. render all Rmd files -------- +render('DESeq_results.Rmd', output_file = opt$deseq_results_html) + + +#-------4. manipulate outputs ----------------------------- diff -r 000000000000 -r 61c184384d02 DESeq_visualization.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_visualization.Rmd Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,114 @@ +--- +title: 'DESeq2: Visualization' +output: + html_document: + number_sections: true + toc: true + theme: cosmo + highlight: tango +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set( + echo = ECHO +) + +library(stringi) +library(DESeq2) +library(pheatmap) +# library(PoiClaClu) +library(RColorBrewer) +``` + +# Import workspace + +```{r eval=TRUE} +fcp = file.copy("DESEQ_WORKSPACE", "deseq.RData") +load("deseq.RData") +``` + +# Visualization + +## Heatmaps of sample-to-sample distances {.tabset} + +### rlog-transformed values + +```{r} +sampleDistMatrix <- as.matrix( sampleDists ) +colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255) +pheatmap(sampleDistMatrix, + # clustering_distance_rows = sampleDists, + clustering_distance_cols = sampleDists, + col = colors) +``` + +### Poisson Distance + +```{r eval=FALSE} +count_t = t(counts(dds)) +rownames(count_t) = colnames(counts(dds)) +poisd <- PoissonDistance(count_t) +samplePoisDistMatrix <- as.matrix( poisd$dd ) +rownames(samplePoisDistMatrix) = rownames(count_t) +colnames(samplePoisDistMatrix) = rownames(count_t) +pheatmap(samplePoisDistMatrix, + # clustering_distance_rows = poisd$dd, + clustering_distance_cols = poisd$dd, + col = colors) +``` + + +## PCA plots {.tabset} + +### Using `plotPCA()` function + +```{r} +# interest groups +col_index = as.numeric(strsplit("INTGROUPS_PCA", ',')[[1]]) +intgroup_pca = colnames(sample_table)[col_index] +``` + +```{r} +plotPCA(rld, intgroup = intgroup_pca) +``` + + +### Using *ggplot2* + +```{r} +pcaData <- plotPCA(rld, intgroup = intgroup_pca, returnData = TRUE) +percentVar <- round(100 * attr(pcaData, "percentVar")) +ggplot(pcaData, aes(x = PC1, y = PC2, color = time)) + + geom_point(size =3) + + xlab(paste0("PC1: ", percentVar[1], "% variance")) + + ylab(paste0("PC2: ", percentVar[2], "% variance")) + + coord_fixed() +``` + +### PCA data table + +```{r} +knitr::kable(pcaData) +``` + + +## MDS plots {.tabset} + +### Using rlog-transformed values + +```{r} +mds <- as.data.frame(colData(rld)) %>% + cbind(cmdscale(sampleDistMatrix)) +mds +ggplot(mds, aes(x = `1`, y = `2`, col = time)) + + geom_point(size = 3) + coord_fixed() +``` + +### Using the *Poisson Distance* + +```{r eval=FALSE} +mdsPois <- as.data.frame(colData(dds)) %>% + cbind(cmdscale(samplePoisDistMatrix)) +ggplot(mdsPois, aes(x = `1`, y = `2`, col = time)) + + geom_point(size = 3) + coord_fixed() +``` diff -r 000000000000 -r 61c184384d02 DESeq_visualization.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_visualization.xml Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,145 @@ + + + pandoc + bioconductor-deseq2 + r-getopt + r-rmarkdown + r-plyr + r-stringr + r-highcharter + r-dt + r-reshape2 + r-plotly + r-formattable + r-htmltools + r-pheatmap + + + An R Markdown tool to visualize DESeq analysis results. + + + + + + + + + + + + + + + + + + + + + + + + + + @article{love2014moderated, + title={Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2}, + author={Love, Michael I and Huber, Wolfgang and Anders, Simon}, + journal={Genome biology}, + volume={15}, + number={12}, + pages={550}, + year={2014}, + publisher={BioMed Central} + } + + + @article{allaire2016rmarkdown, + title={rmarkdown: Dynamic Documents for R, 2016}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + journal={R package version 0.9}, + volume={6}, + year={2016} + } + + + @book{xie2015dynamic, + title={Dynamic Documents with R and knitr}, + author={Xie, Yihui}, + volume={29}, + year={2015}, + publisher={CRC Press} + } + + + @misc{pheatmap2015, + title = {pheatmap: Pretty Heatmaps}, + author = {Raivo Kolde}, + year = {2015}, + note = {R package version 1.0.8}, + url = {https://CRAN.R-project.org/package=pheatmap}, + } + + + @misc{dt2016, + title = {DT: A Wrapper of the JavaScript Library 'DataTables'}, + author = {Yihui Xie}, + year = {2016}, + note = {R package version 0.2}, + url = {https://CRAN.R-project.org/package=DT}, + } + + + \ No newline at end of file diff -r 000000000000 -r 61c184384d02 DESeq_visualization_render.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DESeq_visualization_render.R Tue Nov 07 10:02:57 2017 -0500 @@ -0,0 +1,112 @@ +##======= Handle arguments from command line ======== +# setup R error handline to go to stderr +options(show.error.messages=FALSE, + error=function(){ + cat(geterrmessage(), file=stderr()) + quit("no", 1, F) + }) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + +# suppress warning +options(warn = -1) + +options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) +args = commandArgs(trailingOnly=TRUE) + +suppressPackageStartupMessages({ + library(getopt) + library(tools) +}) + +# column 1: the long flag name +# column 2: the short flag alias. A SINGLE character string +# column 3: argument mask +# 0: no argument +# 1: argument required +# 2: argument is optional +# column 4: date type to which the flag's argument shall be cast. +# possible values: logical, integer, double, complex, character. +spec_list=list() + +##------- 1. input data --------------------- +spec_list$ECHO = c('echo', 'e', '1', 'character') +spec_list$DESEQ_WORKSPACE = c('deseq_workspace', 'w', '1', 'character') +spec_list$SAMPLE_TABLE = c('sample_table', 's', '1', 'character') +spec_list$INTGROUPS_PCA = c('intgroups_pca', 'p', '1', 'character') +spec_list$INTGROUPS_MDS = c('intgroups_mds', 'm', '1', 'character') + +##--------2. output report and report site directory -------------- +spec_list$OUTPUT_HTML = c('deseq_visualization_html', 'o', '1', 'character') +spec_list$OUTPUT_DIR = c('deseq_visualization_dir', 'd', '1', 'character') + +##--------3. Rmd templates sitting in the tool directory ---------- + +spec_list$DESEQ_VISUALIZATION_RMD = c('deseq_visualization_rmd', 'D', '1', 'character') + + + +##------------------------------------------------------------------ + +spec = t(as.data.frame(spec_list)) +opt = getopt(spec) +# arguments are accessed by long flag name (the first column in the spec matrix) +# NOT by element name in the spec_list +# example: opt$help, opt$expression_file +##====== End of arguments handling ========== + +#------ Load libraries --------- +library(rmarkdown) +library(plyr) +library(stringr) +library(dplyr) +library(highcharter) +library(DT) +library(reshape2) +# library(Kmisc) +library(plotly) +library(formattable) +library(htmltools) + + +#----- 1. create the report directory ------------------------ +system(paste0('mkdir -p ', opt$deseq_visualization_dir)) + + +#----- 2. generate Rmd files with Rmd templates -------------- +# a. templates without placeholder variables: +# copy templates from tool directory to the working directory. +# b. templates with placeholder variables: +# substitute variables with user input values and place them in the working directory. + + +#----- 01 DESeq_visualization.Rmd ----------------------- +readLines(opt$deseq_visualization_rmd) %>% + (function(x) { + gsub('ECHO', opt$echo, x) + }) %>% + (function(x) { + gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x) + }) %>% + (function(x) { + gsub('INTGROUPS_PCA', opt$intgroups_pca, x) + }) %>% + (function(x) { + gsub('INTGROUPS_MDS', opt$intgroups_mds, x) + }) %>% + (function(x) { + gsub('OUTPUT_DIR', opt$deseq_visualization_dir, x) + }) %>% + (function(x) { + fileConn = file('DESeq_visualization.Rmd') + writeLines(x, con=fileConn) + close(fileConn) + }) + + +#------ 3. render all Rmd files -------- +render('DESeq_visualization.Rmd', output_file = opt$deseq_visualization_html) + + +#-------4. manipulate outputs -----------------------------