Mercurial > repos > mingchen0919 > aurora_demo
changeset 0:a246652032c1 draft
planemo upload
author | mingchen0919 |
---|---|
date | Sat, 10 Mar 2018 01:44:02 -0500 |
parents | |
children | d67f4b3642ab |
files | aurora_demo.Rmd aurora_demo.sh aurora_demo.xml aurora_demo_render.R |
diffstat | 4 files changed, 121 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_demo.Rmd Sat Mar 10 01:44:02 2018 -0500 @@ -0,0 +1,43 @@ +--- +title: 'Aurora Galaxy Tool Demo' +output: html_document +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set( + echo = TRUE, + error = TRUE +) +``` + + +# Python script + +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 = os.environ['X_r'] +n_col = os.environ['X_c'] +heatmap_data = np.power(10, np.random.randn(n_row, n_col)) +heatmap_file = os.environ['X_O'] +with open(heatmap_file, 'w') as f: + f.write(heatmap_data) +``` + + +# Shell script + +Then we use shell script to display the file content. + +```{bash} +cat ${X_O} +``` + + +# R script + +Finally, we use R script to import the data and generate a heatmap. +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_demo.sh Sat Mar 10 01:44:02 2018 -0500 @@ -0,0 +1,11 @@ +Rscript '${__tool_directory__}/rmarkdown_report_render.R' + # user input + -r $row_number + -c $column_number + + # output + -R $report + -O $heatmap_data + + # tool installation directory + -T '${__tool_directory__}' \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_demo.xml Sat Mar 10 01:44:02 2018 -0500 @@ -0,0 +1,41 @@ +<tool name="Tool report" id="tool_1" 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="2.2.1">r-ggplot2</requirement><requirement type="package" version="4.5.6">r-plotly</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__}/rmarkdown_report_render.R' + # user input + -r $row_number + -c $column_number + + # output + -R $report + -O $heatmap_data + + # tool installation directory + -T '${__tool_directory__}']]></command> + <inputs> + <param type="boolean" name="echo" truevalue="TRUE" falsevalue="FALSE" checked="false" label="Display analysis code in report?"/><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="5"/></inputs> + <outputs> + <data name="heatmap_data" format="txt" 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_render.R Sat Mar 10 01:44:02 2018 -0500 @@ -0,0 +1,26 @@ + +#------------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]) +#------------------------------------------------ + + +#-----------------render Rmd-------------- +render(paste0(TOOL_DIR, '/aurora_demo.Rmd'), + output_file = OUTPUT_REPORT) +#------------------------------------------ +