Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #33 from HendrikSchultheis/tobias
Tobias
  • Loading branch information
HendrikSchultheis committed Mar 21, 2019
2 parents 56a7560 + 3b03555 commit 8987664
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 373 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: wilson
Type: Package
Title: Web-Based Interactive Omics Visualization
Version: 2.1.0
Version: 2.1.1
Authors@R: c(
person("Hendrik", "Schultheis", email = "hendrik.schultheis@mpi-bn.mpg.de", role = c("aut", "cre")),
person("Jens", "Preussner", email = "jens.preussner@mpi-bn.mpg.de", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,3 +1,5 @@
# wilson 2.1.1
- fixed multiple unique_id bug in tobias_parser
# wilson 2.1.0
- implemented tobias_parser
# wilson 2.0.3
Expand Down
6 changes: 5 additions & 1 deletion R/clarion.R
Expand Up @@ -56,7 +56,7 @@ Clarion <- R6::R6Class("Clarion",
# return unique_id
# if no type return first feature
if (is.element("type", names(self$metadata))) {
return(self$metadata[type == "unique_id"][["key"]])
return(self$metadata[type == "unique_id"][["key"]][1])
} else {
return(self$metadata[level == "feature"][["key"]][1])
}
Expand Down Expand Up @@ -201,6 +201,10 @@ Clarion <- R6::R6Class("Clarion",
if (!is.element("unique_id", self$metadata[["type"]])) {
stop("Metadata: No unique_id defined in type! Please define a unique_id.")
}
# case: multiple unique_ids
if (sum(is.element(self$metadata[["type"]], "unique_id")) > 1) {
warning("Metadata: Found multiple unique_ids! Only first will be used.")
}
# case: type = array but no delimiter
if (is.element("array", self$metadata[["type"]]) && !is.element("delimiter", names(self$header))) {
stop("Found type=array but no delimiter! Columns with multi-value fields require delimiter (in header) and type=array (in metadata).")
Expand Down
29 changes: 18 additions & 11 deletions R/parser.R
Expand Up @@ -393,14 +393,14 @@ parser <- function(file, dec = ".") {
#' @param condition_pattern Used to identify condition names by matching und removing given pattern with \code{\link[base]{grep}}. Ignored when condition_names is set.
#' @param in_field_delimiter Delimiter for multi value fields. Default = ','.
#' @param dec Decimal separator. Used in file reading and writing.
#' @param unique_id Whether the table contains an unique id column. If FALSE (default) will create one at first position.
#' @param ... Used as header information.
#'
#' @details During conversion the parser will try to use the given config (if provided) to create the \href{https://github.molgen.mpg.de/loosolab/wilson-apps/wiki/CLARION-Format}{Clarion} metadata. In the case of insufficient config information it will try to approximate by referencing condition names issuing warnings in the process.
#' @details As the format requires an unqiue id the parser will create one if necessary.
#' @details Factor grouping (metadata factor columns) is currently not implemented!
#'
#' @export
tobias_parser <- function(input, output, filter_columns = NULL, filter_pattern = NULL, config = system.file("extdata", "tobias_config.json", package = "wilson"), omit_NA = FALSE, condition_names = NULL, condition_pattern = "_bound$", in_field_delimiter = ",", dec = ".", unique_id = FALSE, ...) {
tobias_parser <- function(input, output, filter_columns = NULL, filter_pattern = NULL, config = system.file("extdata", "tobias_config.json", package = "wilson"), omit_NA = FALSE, condition_names = NULL, condition_pattern = "_bound$", in_field_delimiter = ",", dec = ".", ...) {
## filter data columns
# check if filter columns is a file or a vector
if (!is.null(filter_columns) && file.exists(filter_columns)) {
Expand Down Expand Up @@ -432,14 +432,6 @@ tobias_parser <- function(input, output, filter_columns = NULL, filter_pattern =
data <- stats::na.omit(data)
}

# create id column
if (!unique_id) {
data[, "id" := seq_len(nrow(data))]
# move id column to first position
new_order <- c("id", names(data)[ names(data) != "id"])
data <- data[, new_order, with = FALSE]
}

##### metadata
metadata <- data.table::data.table(names(data))

Expand Down Expand Up @@ -558,7 +550,22 @@ tobias_parser <- function(input, output, filter_columns = NULL, filter_pattern =

# set unique_id fallback
if (!any(metadata[["type"]] == "unique_id")) {
metadata[key == unique_id_fallback, "type"] <- "unique_id"
if (!is.null(unique_id_fallback)) {
metadata[key == unique_id_fallback, "type"] <- "unique_id"
} else {
# setup unique_id column if there is neither a defined column nor a fallback

# create id column
data[, "id" := seq_len(nrow(data))]
# move id column to first position
new_order <- c("id", names(data)[ names(data) != "id"])
data <- data[, new_order, with = FALSE]

id_row <- data.table::data.table("id", level = "feature", type = "unique_id", label = "id", sub_label = "")
names(id_row)[1] <- "key"
# add meta entry
metadata <- rbind(id_row, metadata)
}
}

##### header
Expand Down

0 comments on commit 8987664

Please sign in to comment.