Mercurial > repos > iuc > charts
diff histogram.r @ 0:b457cf9d24d7 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
| author | iuc |
|---|---|
| date | Fri, 09 Mar 2018 08:22:50 -0500 |
| parents | |
| children | bfaa7f89c98d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram.r Fri Mar 09 08:22:50 2018 -0500 @@ -0,0 +1,45 @@ +# wrapper +wrapper <- function(table, columns, options) { + + # initialize output list + l <- list() + + # loop through all columns + m <- list() + for (key in names(columns)) { + # load column data + column <- as.numeric(columns[key]) + column_data <- suppressWarnings(as.numeric(as.character(table[column][[1]]))) + + # collect vectors in list + m <- append(m, list(column_data)) + } + + # identify optimal breaks + hist_data <- hist(unlist(m), plot=FALSE) + breaks <- hist_data$breaks; + + # add as first column + l <- append(l, list(breaks[2: length(breaks)])) + + # loop through all columns + for (key in seq(m)) { + # load column data + column_data <- m[[key]] + + # create hist data + hist_data <- hist(column_data, breaks=breaks, plot=FALSE) + + # normalize densities + count_sum <- sum(hist_data$counts) + if (count_sum > 0) { + hist_data$counts = hist_data$counts / count_sum + } + + # collect vectors in list + l <- append(l, list(hist_data$counts)) + } + + # return + return (l) +}
