changeset 0:dd498df3f006 draft

planemo upload
author mingchen0919
date Mon, 12 Mar 2018 10:02:53 -0400
parents
children 5808dc52afe8
files aurora_demo_site.xml aurora_demo_site_bash.Rmd aurora_demo_site_index.Rmd aurora_demo_site_python.Rmd aurora_demo_site_r.Rmd aurora_demo_site_render.R aurora_demo_site_site.yml
diffstat 7 files changed, 216 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site.xml	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,53 @@
+<tool id="aurora_demo_site" name="Aurora Demo site" version="1.0.0">
+    <description>A demo tool for demonstrating how Aurora Galaxy tool works. This tool is developed under the R Markdown
+        framework and use shell, python and R script together to generate a random heatmap.
+    </description>
+    <requirements>
+        <requirement type="package" version="1.15.0.6-0">pandoc</requirement>
+        <requirement type="package" version="1.20.0">r-getopt</requirement>
+        <requirement type="package" version="1.6">r-rmarkdown</requirement>
+        <requirement type="package" version="1.0.8">r-pheatmap</requirement>
+    </requirements>
+    <stdio>
+        <regex match="XXX" source="stderr" level="warning"
+               description="Check the warnings_and_errors.txt file for more details."/>
+    </stdio>
+    <command><![CDATA[Rscript '${__tool_directory__}/aurora_demo_render.R'
+
+      -r $row_number
+      -c $column_number
+
+      -R $report
+      -O $heatmap_data
+
+      -T '${__tool_directory__}']]></command>
+    <inputs>
+        <param type="integer" name="row_number" label="Number of rows" optional="False" value="10"/>
+        <param type="integer" name="column_number" label="Number of columns" optional="False" value="4"/>
+    </inputs>
+    <outputs>
+        <data name="heatmap_data" format="tabular" hidden="false" label="aurora demo output"/>
+        <data name="report" format="html" label="aurora demo site" hidden="false"/>
+    </outputs>
+    <citations>
+        <citation type="bibtex"><![CDATA[
+            @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}
+            }
+        ]]></citation>
+        <citation type="bibtex"><![CDATA[
+            @book{xie2015dynamic,
+            title={Dynamic Documents with R and knitr},
+            author={Xie, Yihui},
+            volume={29},
+            year={2015},
+            publisher={CRC Press}
+            }
+        ]]></citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_bash.Rmd	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,18 @@
+---
+title: 'Bash script'
+output: html_document
+---
+
+```{r setup, include=FALSE, warning=FALSE, message=FALSE}
+knitr::opts_chunk$set(
+  echo = TRUE, 
+  error = TRUE
+)
+```
+
+
+Then we use shell script to display the file content.
+
+```{bash}
+awk '{print $1, $2}' ${X_O}
+```
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_index.Rmd	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,14 @@
+---
+title: "Analysis Report"
+output: html_document
+---
+
+```{r setup, include=FALSE, warning=FALSE, message=FALSE}
+knitr::opts_chunk$set(echo = TRUE, error = TRUE)
+```
+
+## References
+
+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 (2016). rmarkdown: Dynamic Documents for R, 2016. In R package version 0.9, 6.
+
+Xie, Yihui (2015). Dynamic Documents with R and knitr, CRC Press, Vol.29.
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_python.Rmd	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,24 @@
+---
+title: 'Python script'
+output: html_document
+---
+
+```{r setup, include=FALSE, warning=FALSE, message=FALSE}
+knitr::opts_chunk$set(
+  echo = TRUE, 
+  error = TRUE
+)
+```
+
+We first use Python code to generate a random data matrix and save the data into an output file.
+
+```{python}
+import numpy as np
+import os
+
+n_row = int(os.environ['X_r'])
+n_col = int(os.environ['X_c'])
+heatmap_data = np.power(10, np.random.randn(n_row, n_col))
+np.savetxt(os.environ['X_O'], heatmap_data)
+print(heatmap_data)
+```
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_r.Rmd	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,20 @@
+---
+title: 'R script'
+output: html_document
+---
+
+```{r setup, include=FALSE, warning=FALSE, message=FALSE}
+knitr::opts_chunk$set(
+  echo = TRUE, 
+  error = TRUE
+)
+```
+
+
+Finally, we use R script to import the data and generate a heatmap.
+
+```{r warning=FALSE, message=FALSE}
+heatmap_data = read.table(opt$X_O, header = FALSE, stringsAsFactors = FALSE)
+knitr::kable(heatmap_data)
+pheatmap::pheatmap(heatmap_data, cluster_rows = FALSE, cluster_cols = FALSE)
+```
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_render.R	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,68 @@
+
+#------------import libraries--------------------
+library(getopt)
+library(rmarkdown)
+#------------------------------------------------
+
+#------------1. collect input values in R--------
+#------------2. define environment variables-----
+spec_matrix = as.matrix(
+  data.frame(stringsAsFactors=FALSE,
+             long_flags = c("X_r", "X_c", "X_R", "X_O", "X_T"),
+             short_flags = c("r", "c", "R", "O", "T"),
+             argument_mask_flags = c(1L, 1L, 1L, 1L, 1L),
+             data_type_flags = c("integer", "integer", "character", "character", "character")
+  )
+)
+opt = getopt(spec_matrix)
+do.call(Sys.setenv, opt[-1])
+#------------------------------------------------
+
+
+#------------1. collect input values in R--------
+#------------2. define environment variables-----
+spec_matrix = as.matrix(
+  data.frame(stringsAsFactors=FALSE,
+             long_flags = c("X_r", "X_c", "X_R", "X_O", "X_T"),
+             short_flags = c("r", "c", "R", "O", "T"),
+             argument_mask_flags = c(1L, 1L, 1L, 1L, 1L),
+             data_type_flags = c("integer", "integer", "character", "character", "character")
+  )
+)
+opt = getopt(spec_matrix)
+do.call(Sys.setenv, opt[-1])
+#------------------------------------------------
+
+#---------- often used variables ----------------
+# OUTPUT_REPORT: path to galaxy output report
+# OUTPUT_DIR: path to the output associated directory, which stores all outputs
+# TOOL_DIR: path to the tool installation directory
+OUTPUT_DIR = opt$X_d
+TOOL_DIR =   opt$X_t
+OUTPUT_REPORT = opt$X_o
+
+
+# create the output associated directory to store all outputs
+dir.create(OUTPUT_DIR, recursive = TRUE)
+
+#-----------------render site--------------
+# copy site generating materials into OUTPUT_DIR
+dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
+system(paste0('cp -r ', TOOL_DIR, '/aurora_demo_site_*.Rmd ', OUTPUT_DIR, '/site_generator/'))
+system(paste0('cp -r ', TOOL_DIR, '/aurora_demo_site_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml'))
+system(paste0('cp -r ', TOOL_DIR, '/aurora_demo_site_index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd'))
+# render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file
+render_site(input = paste0(OUTPUT_DIR, '/site_generator'))
+# remove site generating materials from output associated directory
+unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
+# move _site/* into output associated directory
+move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR)
+system(move_cmd)
+#------------------------------------------
+
+#-----link index.html to output-----
+cp_index = paste0('cp ', OUTPUT_DIR, '/index.html ', OUTPUT_REPORT)
+system(cp_index)
+#-----------------------------------
+
+#==============the end==============
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aurora_demo_site_site.yml	Mon Mar 12 10:02:53 2018 -0400
@@ -0,0 +1,19 @@
+name: "Analysis Report"
+output_dir: "../_site"
+navbar:
+    title: ""
+    type: inverse
+    left:
+        - text: "Home"
+          icon: fa-home
+          href: index.html
+        - text: "Python"
+          href: aurora_demo_site_python.html
+        - text: "Bash"
+          href: aurora_demo_site_bash.html
+        - text: "R"
+          href: aurora_demo_site_r.html
+output:
+  html_document:
+    theme: cosmo
+    highlight: textmate
\ No newline at end of file