Mercurial > repos > mingchen0919 > rmarkdown_fastq_dump
comparison fastq_dump_pe_render.R @ 11:d4a9c31d0046 draft
planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastq_dump commit affb362adeb095389646b0c51738d24c2de3838d-dirty
author | mingchen0919 |
---|---|
date | Wed, 27 Sep 2017 16:43:52 -0400 |
parents | 7ec600e7dba7 |
children | 66bc1016ec2a |
comparison
equal
deleted
inserted
replaced
10:057a6b742899 | 11:d4a9c31d0046 |
---|---|
1 ##======= Handle arguments from command line ======== | |
2 # setup R error handline to go to stderr | |
3 options(show.error.messages=FALSE, | |
4 error=function(){ | |
5 cat(geterrmessage(), file=stderr()) | |
6 quit("no", 1, F) | |
7 }) | |
8 | |
9 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
10 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
11 | |
12 # suppress warning | |
13 options(warn = -1) | |
14 | |
15 options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) | |
16 args = commandArgs(trailingOnly=TRUE) | |
17 | |
18 suppressPackageStartupMessages({ | |
19 library(getopt) | |
20 library(tools) | |
21 }) | |
22 | |
23 #/////////////////////// SINK WARNINGS AND ERRORS TO A FILE FOR DEBUGGING /////////// | |
24 zz = file('warnings_and_errors.txt') | |
25 sink(zz) | |
26 sink(zz, type = 'message') | |
27 | |
28 # column 1: the long flag name | |
29 # column 2: the short flag alias. A SINGLE character string | |
30 # column 3: argument mask | |
31 # 0: no argument | |
32 # 1: argument required | |
33 # 2: argument is optional | |
34 # column 4: date type to which the flag's argument shall be cast. | |
35 # possible values: logical, integer, double, complex, character. | |
36 ##------- 1. input data --------------------- | |
37 spec_list=list() | |
38 spec_list$SRA_ACCESSION = c('sra_accession', 'i', '1', 'character') | |
39 spec_list$FORMAT = c('format', 'f', '1', 'character') | |
40 spec_list$ECHO = c('echo', 'e', '1', 'character') | |
41 spec_list$SPLIT_FILES = c('split_files', 'p', '1', 'character') | |
42 ##--------2. output report and outputs -------------- | |
43 spec_list$REPORT_HTML = c('report_html', 'r', '1', 'character') | |
44 spec_list$OUTPUT_DIR = c('output_dir', 'd', '1', 'character') | |
45 spec_list$SINK_OUTPUT = c('sink_output', 's', '1', 'character') | |
46 ##--------3. Rmd templates in the tool directory ---------- | |
47 spec_list$FASTQ_DUMP_SE_RMD = c('fastq_dump_pe_rmd', 't', '1', 'character') | |
48 | |
49 spec = t(as.data.frame(spec_list)) | |
50 opt = getopt(spec) | |
51 | |
52 #------ Load libraries --------- | |
53 library(rmarkdown) | |
54 library(htmltools) | |
55 library(dplyr) | |
56 | |
57 #----- 1. create the report directory ------------------------ | |
58 system(paste0('mkdir -p ', opt$output_dir)) | |
59 | |
60 #----- 2. generate Rmd files with Rmd templates -------------- | |
61 # a. templates without placeholder variables: | |
62 # copy templates from tool directory to the working directory. | |
63 # b. templates with placeholder variables: | |
64 # substitute variables with user input values and place them in the working directory. | |
65 | |
66 #----- 01 fastq_dump_pe.Rmd ----------------------- | |
67 readLines(opt$fastq_dump_pe_rmd) %>% | |
68 (function(x) { | |
69 gsub('SRA_ACCESSION', opt$sra_accession, x) | |
70 }) %>% | |
71 (function(x) { | |
72 gsub('FORMAT', opt$format, x) | |
73 }) %>% | |
74 (function(x) { | |
75 gsub('ECHO', opt$echo, x) | |
76 }) %>% | |
77 (function(x) { | |
78 gsub('SPLIT_FILES', opt$split_files, x) | |
79 }) %>% | |
80 (function(x) { | |
81 gsub('OUTPUT_DIR', opt$output_dir, x) | |
82 }) %>% | |
83 (function(x) { | |
84 fileConn = file('fastq_dump_pe.Rmd') | |
85 writeLines(x, con=fileConn) | |
86 close(fileConn) | |
87 }) | |
88 | |
89 #------ 3. render all Rmd files -------- | |
90 render('fastq_dump_pe.Rmd', output_file = opt$report_html) | |
91 | |
92 | |
93 #-------4. manipulate outputs ----------------------------- | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 sink() | |
100 #/////////// END OF SINK OUTPUT /////////////////////////// |