annotate viridis.R @ 2:dff7bde22102 draft

"planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
author workflow4metabolomics
date Tue, 04 Feb 2020 10:59:26 -0500
parents
children 546c7ccd2ed4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
1 viridis <- function (n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
2 {
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
3 if (begin < 0 | begin > 1 | end < 0 | end > 1) {
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
4 stop("begin and end must be in [0,1]")
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
5 }
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
6 if (abs(direction) != 1) {
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
7 stop("direction must be 1 or -1")
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
8 }
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
9 if (direction == -1) {
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
10 tmp <- begin
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
11 begin <- end
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
12 end <- tmp
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
13 }
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
14 option <- switch(EXPR = option, A = "A", magma = "A",
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
15 B = "B", inferno = "B", C = "C", plasma = "C",
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
16 D = "D", viridis = "D", E = "E", cividis = "E",
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
17 {
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
18 warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'."))
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
19 "D"
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
20 })
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
21 map <- viridisLite::viridis.map[viridisLite::viridis.map$opt ==
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
22 option, ]
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
23 map_cols <- grDevices::rgb(map$R, map$G, map$B)
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
24 fn_cols <- grDevices::colorRamp(map_cols, space = "Lab",
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
25 interpolate = "spline")
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
26 cols <- fn_cols(seq(begin, end, length.out = n))/255
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
27 grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha)
dff7bde22102 "planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b3abcb650e9b38458aa0ac5f7d838811d982ff65"
workflow4metabolomics
parents:
diff changeset
28 }