comparison helper.R @ 0:ebb7afcb2b75 draft default tip

planemo upload
author mingchen0919
date Tue, 17 Apr 2018 10:58:55 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ebb7afcb2b75
1 #' \code{getopt_specification_matrix} returns a getopt specification matrix.
2 #'
3 #' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data.
4 #' The first column are short flags, the second column are argument masks, the third column
5 #' is data types. The fourth column are variable names used in the tool XML. These three columns are required.
6 #' @param gtg_name the name of a running GTG.
7 getopt_specification_matrix = function(specification_file, gtg_name = 'gtg', tool_dir = Sys.getenv('TOOL_DIR')) {
8 df = read.csv(paste0(tool_dir, '/', specification_file),
9 header = TRUE, stringsAsFactors = FALSE)
10 # check if there are duplicated short flags
11 short_flags = df[, 1]
12 if (length(unique(short_flags)) < length(short_flags)) {
13 cat('----Duplicated short flags found ----\n')
14 cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n')
15 stop('Duplicated short flags are not allowed.')
16 }
17
18 # use short flags to generate long flags
19 long_flags = paste0('X_', df[, 1])
20
21 # specification matrix
22 df2 = data.frame(long_flags = long_flags,
23 short_flags = df[, 1],
24 argument_mask = df[, 2],
25 data_type = df[, 3])
26
27 as.matrix(df2)
28 }
29
30
31
32 #' \code{file_tree} generate file tree of a directory in the format of HTML lists.
33 #'
34 #' @param dir the path to the directory for generating the file tree.
35 file_tree = function(dir = '.'){
36 files = list.files(path = dir, recursive = FALSE, full.names = TRUE)
37 # files also include directorys, need to remove directorys
38 files = files[!dir.exists(files)]
39 dirs = list.dirs(path = dir, recursive = FALSE, full.names = TRUE)
40 tags$ul(
41 {
42 if (length(files) > 0) {
43 lapply(files, tags$li)
44 }
45 },
46 {
47 if (length(dirs) > 0) {
48 lapply(dirs, function(x){
49 tags$li(x, file_tree(x))
50
51 })
52 }
53 }
54 )
55 }