annotate histogram.r @ 1:344ac3ca7557 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
author iuc
date Wed, 17 Nov 2021 09:06:59 +0000
parents a87a3773d8ed
children
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]])))
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
13
0
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 }
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
17
0
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
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
19 hist_data <- hist(unlist(m), plot = FALSE)
0
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;
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
21
0
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)]))
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
24
0
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]]
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
29
0
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
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
31 hist_data <- hist(column_data, breaks = breaks, plot = FALSE)
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
32
0
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) {
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
36 hist_data$counts <- hist_data$counts / count_sum
0
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
37 }
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
38
0
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 }
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
42
0
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
43 # return
1
344ac3ca7557 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
iuc
parents: 0
diff changeset
44 return(l)
0
a87a3773d8ed planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
iuc
parents:
diff changeset
45 }