annotate histogram.r @ 0:a87a3773d8ed 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:23:08 -0500
parents
children 344ac3ca7557
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
1 # wrapper
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
2 wrapper <- function(table, columns, options) {
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
3
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
4 # initialize output list
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
5 l <- list()
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
6
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
7 # loop through all columns
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
8 m <- list()
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
9 for (key in names(columns)) {
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
10 # load column data
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
11 column <- as.numeric(columns[key])
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
12 column_data <- suppressWarnings(as.numeric(as.character(table[column][[1]])))
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
13
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
14 # collect vectors in list
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
15 m <- append(m, list(column_data))
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
16 }
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
17
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
18 # identify optimal breaks
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
19 hist_data <- hist(unlist(m), plot=FALSE)
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
20 breaks <- hist_data$breaks;
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
21
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
22 # add as first column
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
23 l <- append(l, list(breaks[2: length(breaks)]))
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
24
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
25 # loop through all columns
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
26 for (key in seq(m)) {
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
27 # load column data
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
28 column_data <- m[[key]]
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
29
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
30 # create hist data
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
31 hist_data <- hist(column_data, breaks=breaks, plot=FALSE)
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
32
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
33 # normalize densities
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
34 count_sum <- sum(hist_data$counts)
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
35 if (count_sum > 0) {
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
36 hist_data$counts = hist_data$counts / count_sum
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
37 }
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
38
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
39 # collect vectors in list
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
40 l <- append(l, list(hist_data$counts))
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
41 }
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
42
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
43 # return
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
44 return (l)
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
45 }