Mercurial > repos > mingchen0919 > aurora_htseq_site
comparison htseq_count_site_render.R @ 2:fad3864136c9 draft
fix error
| author | mingchen0919 |
|---|---|
| date | Tue, 13 Mar 2018 09:49:58 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:9be3a8754fb3 | 2:fad3864136c9 |
|---|---|
| 1 ##============ Sink warnings and errors to a file ============== | |
| 2 ## use the sink() function to wrap all code within it. | |
| 3 ##============================================================== | |
| 4 zz = file('warnings_and_errors.txt') | |
| 5 sink(zz) | |
| 6 sink(zz, type = 'message') | |
| 7 | |
| 8 #------------import libraries-------------------- | |
| 9 options(stringsAsFactors = FALSE) | |
| 10 | |
| 11 library(getopt) | |
| 12 library(rmarkdown) | |
| 13 library(htmltools) | |
| 14 #------------------------------------------------ | |
| 15 | |
| 16 | |
| 17 #------------get arguments into R-------------------- | |
| 18 # library(dplyr) | |
| 19 # getopt_specification_matrix(extract_short_flags('')) %>% | |
| 20 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE) | |
| 21 | |
| 22 | |
| 23 spec_matrix = as.matrix( | |
| 24 data.frame(stringsAsFactors=FALSE, | |
| 25 long_flags = c("X_e", "X_o", "X_d", "X_s", "X_t", "X_A", "X_B", "X_G", | |
| 26 "X_f", "X_r", "X_S", "X_a", "X_T", "X_i", "X_m", "X_c", "X_O"), | |
| 27 short_flags = c("e", "o", "d", "s", "t", "A", "B", "G", "f", "r", "S", | |
| 28 "a", "T", "i", "m", "c", "O"), | |
| 29 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, | |
| 30 1L, 1L, 1L, 1L), | |
| 31 data_type_flags = c("character", "character", "character", "character", | |
| 32 "character", "character", "character", "character", | |
| 33 "character", "character", "character", "character", | |
| 34 "character", "character", "character", "character", | |
| 35 "character") | |
| 36 ) | |
| 37 ) | |
| 38 opt = getopt(spec_matrix) | |
| 39 #---------------------------------------------------- | |
| 40 | |
| 41 | |
| 42 #-----------using passed arguments in R | |
| 43 # to define system environment variables--- | |
| 44 do.call(Sys.setenv, opt[-1]) | |
| 45 #---------------------------------------------------- | |
| 46 | |
| 47 #---------- often used variables ---------------- | |
| 48 # OUTPUT_REPORT: path to galaxy output report | |
| 49 # OUTPUT_DIR: path to the output associated directory, which stores all outputs | |
| 50 # TOOL_DIR: path to the tool installation directory | |
| 51 OUTPUT_DIR = opt$X_d | |
| 52 TOOL_DIR = opt$X_t | |
| 53 OUTPUT_REPORT = opt$X_o | |
| 54 | |
| 55 | |
| 56 # create the output associated directory to store all outputs | |
| 57 dir.create(OUTPUT_DIR, recursive = TRUE) | |
| 58 | |
| 59 #-----------------render site-------------- | |
| 60 # copy site generating materials into OUTPUT_DIR | |
| 61 dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE) | |
| 62 system(paste0('cp -r ', TOOL_DIR, '/htseq_count_site.Rmd ', OUTPUT_DIR, '/site_generator/htseq_count_site.Rmd')) | |
| 63 system(paste0('cp -r ', TOOL_DIR, '/htseq_count_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml')) | |
| 64 system(paste0('cp -r ', TOOL_DIR, '/htseq_count_site_index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd')) | |
| 65 # render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file | |
| 66 render_site(input = paste0(OUTPUT_DIR, '/site_generator')) | |
| 67 # remove site generating materials from output associated directory | |
| 68 unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE) | |
| 69 # move _site/* into output associated directory | |
| 70 move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR) | |
| 71 system(move_cmd) | |
| 72 #------------------------------------------ | |
| 73 | |
| 74 #-----link index.html to output----- | |
| 75 cp_index = paste0('cp ', OUTPUT_DIR, '/index.html ', OUTPUT_REPORT) | |
| 76 system(cp_index) | |
| 77 #----------------------------------- | |
| 78 | |
| 79 #==============the end============== | |
| 80 | |
| 81 | |
| 82 ##--------end of code rendering .Rmd templates---------------- | |
| 83 sink() | |
| 84 ##=========== End of sinking output============================= |
