Mercurial > repos > mingchen0919 > aurora_data
diff helper.R @ 0:ebb7afcb2b75 draft default tip
planemo upload
| author | mingchen0919 |
|---|---|
| date | Tue, 17 Apr 2018 10:58:55 -0400 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helper.R Tue Apr 17 10:58:55 2018 -0400 @@ -0,0 +1,55 @@ +#' \code{getopt_specification_matrix} returns a getopt specification matrix. +#' +#' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data. +#' The first column are short flags, the second column are argument masks, the third column +#' is data types. The fourth column are variable names used in the tool XML. These three columns are required. +#' @param gtg_name the name of a running GTG. +getopt_specification_matrix = function(specification_file, gtg_name = 'gtg', tool_dir = Sys.getenv('TOOL_DIR')) { + df = read.csv(paste0(tool_dir, '/', specification_file), + header = TRUE, stringsAsFactors = FALSE) + # check if there are duplicated short flags + short_flags = df[, 1] + if (length(unique(short_flags)) < length(short_flags)) { + cat('----Duplicated short flags found ----\n') + cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n') + stop('Duplicated short flags are not allowed.') + } + + # use short flags to generate long flags + long_flags = paste0('X_', df[, 1]) + + # specification matrix + df2 = data.frame(long_flags = long_flags, + short_flags = df[, 1], + argument_mask = df[, 2], + data_type = df[, 3]) + + as.matrix(df2) +} + + + +#' \code{file_tree} generate file tree of a directory in the format of HTML lists. +#' +#' @param dir the path to the directory for generating the file tree. +file_tree = function(dir = '.'){ + files = list.files(path = dir, recursive = FALSE, full.names = TRUE) + # files also include directorys, need to remove directorys + files = files[!dir.exists(files)] + dirs = list.dirs(path = dir, recursive = FALSE, full.names = TRUE) + tags$ul( + { + if (length(files) > 0) { + lapply(files, tags$li) + } + }, + { + if (length(dirs) > 0) { + lapply(dirs, function(x){ + tags$li(x, file_tree(x)) + + }) + } + } + ) +} \ No newline at end of file
