annotate helper.R @ 2:d9601e1eb360 draft

v1.1.0
author mingchen0919
date Sun, 18 Mar 2018 11:07:16 -0400
parents
children c7de860e5be7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
mingchen0919
parents:
diff changeset
1 #' \code{getopt_specification_matrix} returns a getopt specification matrix.
mingchen0919
parents:
diff changeset
2 #'
mingchen0919
parents:
diff changeset
3 #' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data.
mingchen0919
parents:
diff changeset
4 #' The first column are short flags, the second column are argument masks, the third column
mingchen0919
parents:
diff changeset
5 #' is data types. The fourth column are variable names used in the tool XML. These three columns are required.
mingchen0919
parents:
diff changeset
6 #' @param gtg_name the name of a running GTG.
mingchen0919
parents:
diff changeset
7 getopt_specification_matrix = function(specification_file, gtg_name = 'gtg', tool_dir = Sys.getenv('TOOL_DIRECTORY')) {
mingchen0919
parents:
diff changeset
8 df = read.csv(paste0(tool_dir, specification_file),
mingchen0919
parents:
diff changeset
9 header = TRUE, stringsAsFactors = FALSE)
mingchen0919
parents:
diff changeset
10 # check if there are duplicated short flags
mingchen0919
parents:
diff changeset
11 short_flags = df[, 1]
mingchen0919
parents:
diff changeset
12 if (length(unique(short_flags)) < length(short_flags)) {
mingchen0919
parents:
diff changeset
13 cat('----Duplicated short flags found ----\n')
mingchen0919
parents:
diff changeset
14 cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n')
mingchen0919
parents:
diff changeset
15 stop('Duplicated short flags are not allowed.')
mingchen0919
parents:
diff changeset
16 }
mingchen0919
parents:
diff changeset
17
mingchen0919
parents:
diff changeset
18 # use short flags to generate long flags
mingchen0919
parents:
diff changeset
19 long_flags = paste0('X_', df[, 1])
mingchen0919
parents:
diff changeset
20
mingchen0919
parents:
diff changeset
21 # specification matrix
mingchen0919
parents:
diff changeset
22 df2 = data.frame(long_flags = long_flags,
mingchen0919
parents:
diff changeset
23 short_flags = df[, 1],
mingchen0919
parents:
diff changeset
24 argument_mask = df[, 2],
mingchen0919
parents:
diff changeset
25 data_type = df[, 3])
mingchen0919
parents:
diff changeset
26
mingchen0919
parents:
diff changeset
27 as.matrix(df2)
mingchen0919
parents:
diff changeset
28 }