Repository 'ez_histograms'
hg clone https://radegast.galaxyproject.org/repos/artbio/ez_histograms

Changeset 2:d375c9df9c34 (2024-11-07)
Previous changeset 1:fbedb212982d (2024-02-08)
Commit message:
planemo upload for repository https://github.com/artbio/tools-artbio/tree/main/tools/ez_histograms commit f8dffb887b68fdc2c9b35f30676539b8396abd54
modified:
ez_histograms.R
ez_histograms.xml
b
diff -r fbedb212982d -r d375c9df9c34 ez_histograms.R
--- a/ez_histograms.R Thu Feb 08 02:15:11 2024 +0000
+++ b/ez_histograms.R Thu Nov 07 15:40:40 2024 +0000
[
b'@@ -5,121 +5,125 @@\n library(psych)\n library(optparse)\n \n-options(show.error.messages = FALSE,\n-  error = function() {\n-    cat(geterrmessage(), file = stderr())\n-    q("no", 1, FALSE)\n-  }\n+options(\n+    show.error.messages = FALSE,\n+    error = function() {\n+        cat(geterrmessage(), file = stderr())\n+        q("no", 1, FALSE)\n+    }\n )\n \n loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")\n warnings()\n \n option_list <- list(\n-  make_option(\n-    c("-f", "--file"),\n-    default = NA,\n-    type = "character",\n-    help = "Input file that contains count values to transform"\n-  ),\n-  make_option(\n-    c("-d", "--profile"),\n-    default = "count",\n-    type = "character",\n-    help = "Whether y-axis shows absolute counts or density: \'count\' or \'density\' [default : \'%default\' ]"\n-  ),\n-  make_option(\n-    "--xscale",\n-    default = "cartesian",\n-    type = "character",\n-    help = "Whether x-axis is \'cartesian\', \'log2\' or \'log10\' [default : \'%default\' ]"\n-  ),\n-  make_option(\n-    "--yscale",\n-    default = "cartesian",\n-    type = "character",\n-    help = "Whether y-axis is \'cartesian\', \'log2\' or \'log10\' [default : \'%default\' ]"\n-  ),\n-  make_option(\n-    c("-p", "--pdf"),\n-    default = "histograms.pdf",\n-    type = "character",\n-    help = "Output pdf file name [default : \'%default\' ]"\n-  ),\n-  make_option(\n-    c("-s", "--summary"),\n-    default = "summary.tsv",\n-    type = "character",\n-    help = "statistics summary file name [default : \'%default\' ]"\n-  )\n+    make_option(\n+        c("-f", "--file"),\n+        default = NA,\n+        type = "character",\n+        help = "Input file that contains count values to transform"\n+    ),\n+    make_option(\n+        c("-d", "--profile"),\n+        default = "count",\n+        type = "character",\n+        help = "Whether y-axis shows absolute counts or density: \'count\' or \'density\' [default : \'%default\' ]"\n+    ),\n+    make_option(\n+        "--xscale",\n+        default = "cartesian",\n+        type = "character",\n+        help = "Whether x-axis is \'cartesian\', \'log2\' or \'log10\' [default : \'%default\' ]"\n+    ),\n+    make_option(\n+        "--yscale",\n+        default = "cartesian",\n+        type = "character",\n+        help = "Whether y-axis is \'cartesian\', \'log2\' or \'log10\' [default : \'%default\' ]"\n+    ),\n+    make_option(\n+        c("-p", "--pdf"),\n+        default = "histograms.pdf",\n+        type = "character",\n+        help = "Output pdf file name [default : \'%default\' ]"\n+    ),\n+    make_option(\n+        c("-s", "--summary"),\n+        default = "summary.tsv",\n+        type = "character",\n+        help = "statistics summary file name [default : \'%default\' ]"\n+    )\n )\n \n opt <- parse_args(OptionParser(option_list = option_list),\n-                  args = commandArgs(trailingOnly = TRUE))\n+    args = commandArgs(trailingOnly = TRUE)\n+)\n \n plot_histograms <- function(mdata, profile = "count", xscale = "cartesian", yscale = "cartesian", bins = 30) {\n-  if (profile == "count") {\n-    # count histogram\n-    p <- ggplot(mdata, aes(x = value, fill = variable, color = variable, y = after_stat(count)), show.legend = FALSE) +\n-      geom_histogram(bins = bins) + theme(legend.position = "none")\n-    if (xscale == "cartesian") {\n-      if (yscale == "log2") {\n-        p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n-      } else {\n-        if (yscale == "log10") {\n-          p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+    if (profile == "count") {\n+        # count histogram\n+        p <- ggplot(mdata, aes(x = value, fill = variable, color = variable, y = after_stat(count)), show.legend = FALSE) +\n+            geom_histogram(bins = bins) +\n+            theme(legend.position = "none")\n+        if (xscale == "cartesian") {\n+            if (yscale == "log2") {\n+                p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n+            } else {\n+        '..b'x_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n+            if (yscale == "log2") {\n+                p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n+            } else {\n+                if (yscale == "log10") {\n+                    p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+                }\n+            }\n         }\n-      }\n+        if (xscale == "log10") {\n+            p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+            if (yscale == "log2") {\n+                p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n+            } else {\n+                if (yscale == "log10") {\n+                    p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+                }\n+            }\n+        }\n     }\n-    if (xscale == "log10") {\n-      p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n-      if (yscale == "log2") {\n-        p <- p + scale_y_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n-      } else {\n-        if (yscale == "log10") {\n-          p <- p + scale_y_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+\n+    if (profile == "density") {\n+        # density histogram\n+        p <- ggplot(mdata, aes(x = value, fill = variable, color = variable)) +\n+            geom_density() +\n+            theme(legend.position = "none")\n+        if (xscale == "log2") {\n+            p <- p + scale_x_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n         }\n-      }\n+        if (xscale == "log10") {\n+            p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n+        }\n     }\n-  }\n-\n-  if (profile == "density") {\n-    # density histogram\n-    p <- ggplot(mdata, aes(x = value, fill = variable, color = variable)) +\n-      geom_density() + theme(legend.position = "none")\n-    if (xscale == "log2") {\n-      p <- p + scale_x_continuous(trans = "log2", labels = trans_format("log2", math_format(2^.x)))\n-    }\n-    if (xscale == "log10") {\n-      p <- p + scale_x_continuous(trans = "log10", labels = trans_format("log10", math_format(10^.x)))\n-    }\n-  }\n-  return(p)\n+    return(p)\n }\n \n test_header <- function(file) {\n-  data <- read.delim(file = file, header = FALSE, row.names = 1, nrows = 2)\n-  if (all(is.na(as.numeric(data[1, seq_len(ncol(data))])))) {\n-    return(TRUE)\n-  } else {\n-    return(FALSE)\n-  }\n+    data <- read.delim(file = file, header = FALSE, row.names = 1, nrows = 2)\n+    if (all(is.na(as.numeric(data[1, seq_len(ncol(data))])))) {\n+        return(TRUE)\n+    } else {\n+        return(FALSE)\n+    }\n }\n \n ##### prepare input data\n \n data <- read.delim(file = opt$file, header = test_header(opt$file))\n-data <- data %>% select(where(is.numeric))  # remove non numeric columns\n+data <- data %>% select(where(is.numeric)) # remove non numeric columns\n mdata <- melt(data)\n \n ##### main\n@@ -132,23 +136,23 @@\n # determine optimal width for the graph\n width <- length(data)\n width <- case_when(\n-  width == 1 ~ 14 / 3,\n-  width == 2 ~ (2 / 3) * 14,\n-  TRUE ~ 14\n+    width == 1 ~ 14 / 3,\n+    width == 2 ~ (2 / 3) * 14,\n+    TRUE ~ 14\n )\n # determine optimal height for the graph\n height <- length(data)\n height <- case_when(\n-  height <= 3 ~ 3,\n-  height <= 6 ~ 6,\n-  TRUE ~ (floor(height / 3) + 1) * 3\n+    height <= 3 ~ 3,\n+    height <= 6 ~ 6,\n+    TRUE ~ (floor(height / 3) + 1) * 3\n )\n # determine optimal number of col for the graph\n ncol <- length(data)\n ncol <- case_when(\n-  ncol == 1 ~ 1,\n-  ncol == 2 ~ 2,\n-  TRUE ~ 3\n+    ncol == 1 ~ 1,\n+    ncol == 2 ~ 2,\n+    TRUE ~ 3\n )\n pdf(opt$pdf, width = width, height = height)\n print(p + facet_wrap(~variable, ncol = ncol, scales = "free"))\n'
b
diff -r fbedb212982d -r d375c9df9c34 ez_histograms.xml
--- a/ez_histograms.xml Thu Feb 08 02:15:11 2024 +0000
+++ b/ez_histograms.xml Thu Nov 07 15:40:40 2024 +0000
b
@@ -1,9 +1,14 @@
 <tool id="ez_histograms" name="ez_histograms" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
     <macros>
         <token name="@TOOL_VERSION@">3.4.4</token>
-        <token name="@VERSION_SUFFIX@">1</token>
+        <token name="@VERSION_SUFFIX@">2</token>
         <token name="@PROFILE@">23.0</token>
     </macros>
+
+    <xrefs>
+        <xref type="bio.tools">ez_histograms</xref>
+    </xrefs>
+
     <requirements>
         <requirement type="package" version="3.4.4">r-ggplot2</requirement>
         <requirement type="package" version="1.4.4">r-reshape2</requirement>