annotate ez_histograms.R @ 2:d375c9df9c34 draft default tip

planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
author artbio
date Thu, 07 Nov 2024 15:40:40 +0000
parents fbedb212982d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
1 library(ggplot2)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
2 library(reshape2)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
3 library(dplyr)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
4 library(scales)
1
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
5 library(psych)
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
6 library(optparse)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
7
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
8 options(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
9 show.error.messages = FALSE,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
10 error = function() {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
11 cat(geterrmessage(), file = stderr())
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
12 q("no", 1, FALSE)
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
13 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
14 )
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
15
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
16 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
17 warnings()
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
18
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
19 option_list <- list(
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
20 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
21 c("-f", "--file"),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
22 default = NA,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
23 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
24 help = "Input file that contains count values to transform"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
25 ),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
26 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
27 c("-d", "--profile"),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
28 default = "count",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
29 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
30 help = "Whether y-axis shows absolute counts or density: 'count' or 'density' [default : '%default' ]"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
31 ),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
32 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
33 "--xscale",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
34 default = "cartesian",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
35 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
36 help = "Whether x-axis is 'cartesian', 'log2' or 'log10' [default : '%default' ]"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
37 ),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
38 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
39 "--yscale",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
40 default = "cartesian",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
41 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
42 help = "Whether y-axis is 'cartesian', 'log2' or 'log10' [default : '%default' ]"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
43 ),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
44 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
45 c("-p", "--pdf"),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
46 default = "histograms.pdf",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
47 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
48 help = "Output pdf file name [default : '%default' ]"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
49 ),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
50 make_option(
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
51 c("-s", "--summary"),
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
52 default = "summary.tsv",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
53 type = "character",
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
54 help = "statistics summary file name [default : '%default' ]"
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
55 )
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
56 )
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
57
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
58 opt <- parse_args(OptionParser(option_list = option_list),
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
59 args = commandArgs(trailingOnly = TRUE)
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
60 )
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
61
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
62 plot_histograms <- function(mdata, profile = "count", xscale = "cartesian", yscale = "cartesian", bins = 30) {
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
63 if (profile == "count") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
64 # count histogram
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
65 p <- ggplot(mdata, aes(x = value, fill = variable, color = variable, y = after_stat(count)), show.legend = FALSE) +
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
66 geom_histogram(bins = bins) +
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
67 theme(legend.position = "none")
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
68 if (xscale == "cartesian") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
69 if (yscale == "log2") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
70 p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
71 } else {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
72 if (yscale == "log10") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
73 p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
74 }
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
75 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
76 }
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
77 if (xscale == "log2") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
78 p <- p + scale_x_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
79 if (yscale == "log2") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
80 p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
81 } else {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
82 if (yscale == "log10") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
83 p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
84 }
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
85 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
86 }
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
87 if (xscale == "log10") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
88 p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
89 if (yscale == "log2") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
90 p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
91 } else {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
92 if (yscale == "log10") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
93 p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
94 }
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
95 }
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
96 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
97 }
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
98
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
99 if (profile == "density") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
100 # density histogram
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
101 p <- ggplot(mdata, aes(x = value, fill = variable, color = variable)) +
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
102 geom_density() +
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
103 theme(legend.position = "none")
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
104 if (xscale == "log2") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
105 p <- p + scale_x_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
106 }
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
107 if (xscale == "log10") {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
108 p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
109 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
110 }
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
111 return(p)
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
112 }
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
113
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
114 test_header <- function(file) {
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
115 data <- read.delim(file = file, header = FALSE, row.names = 1, nrows = 2)
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
116 if (all(is.na(as.numeric(data[1, seq_len(ncol(data))])))) {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
117 return(TRUE)
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
118 } else {
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
119 return(FALSE)
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
120 }
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
121 }
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
122
1
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
123 ##### prepare input data
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
124
1
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
125 data <- read.delim(file = opt$file, header = test_header(opt$file))
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
126 data <- data %>% select(where(is.numeric)) # remove non numeric columns
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
127 mdata <- melt(data)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
128
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
129 ##### main
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
130
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
131 # determine optimal number of bins (Sturges’ Rule)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
132 bins <- ceiling(log2(nrow(data)) + 1)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
133 # plot
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
134 p <- plot_histograms(mdata, profile = opt$profile, xscale = opt$xscale, bins = bins, yscale = opt$yscale)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
135
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
136 # determine optimal width for the graph
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
137 width <- length(data)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
138 width <- case_when(
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
139 width == 1 ~ 14 / 3,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
140 width == 2 ~ (2 / 3) * 14,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
141 TRUE ~ 14
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
142 )
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
143 # determine optimal height for the graph
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
144 height <- length(data)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
145 height <- case_when(
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
146 height <= 3 ~ 3,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
147 height <= 6 ~ 6,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
148 TRUE ~ (floor(height / 3) + 1) * 3
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
149 )
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
150 # determine optimal number of col for the graph
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
151 ncol <- length(data)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
152 ncol <- case_when(
2
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
153 ncol == 1 ~ 1,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
154 ncol == 2 ~ 2,
d375c9df9c34 planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
artbio
parents: 1
diff changeset
155 TRUE ~ 3
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
156 )
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
157 pdf(opt$pdf, width = width, height = height)
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
158 print(p + facet_wrap(~variable, ncol = ncol, scales = "free"))
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
159 dev.off()
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
160
1
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
161 # Summary statistics with psych package
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
162 summary_df <- describe(x = data, skew = FALSE, ranges = FALSE, quant = c(.25, .50, .75))
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
163 summary_df <- cbind(var_names = rownames(summary_df), summary_df)
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
164 colnames(summary_df)[2] <- "var_num"
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
165 summary_df <- summary_df[, -6]
fbedb212982d planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 5e25392164eca5585239b62c82b7f6ba326cda6e
artbio
parents: 0
diff changeset
166 summary_df[, 4:8] <- format(summary_df[, 4:8], scientific = TRUE)
0
bdf40b0924cb planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit 443759a746f78d67dc4ffcafdc6610d09d278846
artbio
parents:
diff changeset
167 write.table(summary_df, file = opt$summary, sep = "\t", quote = FALSE, row.names = FALSE)