annotate helper.R @ 0:ebb7afcb2b75 draft default tip

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