Mercurial > repos > recetox > rcx_boxplot
diff rcx_boxplot.xml @ 0:92325ed91115 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools commit 68159a987b0597222625834e235441b95e8c3a5e
author | recetox |
---|---|
date | Mon, 03 Feb 2025 16:18:52 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rcx_boxplot.xml Mon Feb 03 16:18:52 2025 +0000 @@ -0,0 +1,151 @@ +<tool id="rcx_boxplot" name="recetox-boxplot" version="@TOOL_VERSION@+galaxy0" profile="23.0"> + <description>Boxplot visualization tool using ggplot2</description> + <macros> + <import>macros.xml</import> + <import>help.xml</import> + </macros> + + <expand macro="creator" /> + <expand macro="requirements" /> + + <command detect_errors="exit_code"><![CDATA[ + Rscript '${run_script}' + #if $export_R_script + && cat ${run_script} >> $script + #end if + ]]></command> + + <configfiles> + <configfile name="run_script"><![CDATA[ + + #if $input_data.ext == "csv" + data_input <- read.csv("$input_data", check.names = "false") + #else if $input_data.ext in ["tsv", "txt", "tabular"] + data_input <- read.delim("$input_data", sep="\t", check.names = "false") + #else if $input_data.ext == "parquet" + data_input <- arrow::read_parquet("$input_data") + #end if + + #if $has_rownames + rownames(data_input) <- data_input[, 1] + data_input <- data_input[ ,-1] + #end if + + y_colname <- "intensity" + data_long <- tidyr::pivot_longer(data_input, + cols = c(1:ncol(data_input)), + names_to = "samples", + values_to = y_colname) + + #if $transform_data == "replace_zero" + data_long[data_long == 0] <- NA + #else if $transform_data == "log2" + data_long[[y_colname]] <- log2(data_long[[y_colname]]) + #else if $transform_data == "log10" + data_long[[y_colname]] <- log10(data_long[[y_colname]]) + #end if + + #if $grouping_boxplot.use_grouping == "yes" + metadata_input <- read.delim("$grouping_boxplot.input_metadata", sep="\t", check.names = "false") + sampleID_column <- colnames(metadata_input)[$grouping_boxplot.sampleID] + plotting_column <- colnames(metadata_input)[$grouping_boxplot.groupingCol] + metadata_input <- data.frame(lapply(metadata_input, as.factor)) + + data_long <- dplyr::left_join(data_long, metadata_input, by = c("samples" = sampleID_column), keep = TRUE) + + #if $grouping_boxplot.facet_x + facet_x <- rlang::sym(colnames(metadata_input)[$grouping_boxplot.facet_x]) + #else + facet_x <- NULL + #end if + + #if $grouping_boxplot.facet_y + facet_y <- rlang::sym(colnames(metadata_input)[$grouping_boxplot.facet_y]) + #else + facet_y <- NULL + #end if + + plot_boxplot <- ggplot2::ggplot(data_long, ggplot2::aes( + x = !!rlang::sym(plotting_column), + y = intensity, + #if $grouping_boxplot.colorCol + fill = !!rlang::sym(colnames(metadata_input)[$grouping_boxplot.colorCol]) + #end if + )) + + ggplot2::geom_boxplot() + + ggplot2::theme_bw()+ + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust=1)) + + ggplot2::facet_grid(rows = if(!is.null(facet_y)) dplyr::vars(!!facet_y) else NULL, + cols = if(!is.null(facet_x)) dplyr::vars(!!facet_x) else NULL, + scales = "free") + + + #else + + plot_boxplot <- ggplot2::ggplot(data_long, ggplot2::aes(x = samples, y = intensity)) + + ggplot2::geom_boxplot() + + ggplot2::theme_bw()+ + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust=1)) + + #end if + + #if $xlab + plot_boxplot <- plot_boxplot + ggplot2::xlab("$xlab") + #end if + + #if $ylab + plot_boxplot <- plot_boxplot + ggplot2::ylab("$ylab") + #end if + + #if $flip_axes == "true" + plot_boxplot <- plot_boxplot + ggplot2::coord_flip() + #end if + + ggplot2::ggsave(filename = "boxplot.png", plot_boxplot) + + ]]></configfile> + </configfiles> + + <inputs> + <expand macro="boxplot_param"/> + </inputs> + + <outputs> + <data name="boxplot" format="png" label="Boxplot on ${on_string}" from_work_dir="boxplot.png"/> + <data name="script" format="txt" label="R script"> + <filter>export_R_script</filter> + </data> + </outputs> + + <tests> + <test expect_num_outputs="1"> + <param name="input_data" value="test_data.txt"/> + <param name="has_rownames" value="true"/> + <output name="boxplot" ftype="png"> + <assert_contents> + <has_size size="1164615" delta="200"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="2"> + <param name="input_data" value="test_data.txt"/> + <param name="has_rownames" value="true"/> + <param name="use_grouping" value="yes"/> + <param name="input_metadata" value="test_expDesign.txt"/> + <param name="sampleID" value="1"/> + <param name="groupingCol" value="1"/> + <param name="export_R_script" value="TRUE"/> + <output name="boxplot" ftype="png"> + <assert_contents> + <has_size size="1164615" delta="200"/> + </assert_contents> + </output> + </test> + </tests> + + <help><![CDATA[ + @GENERAL_HELP@ + ]]></help> + + <expand macro="citations" /> +</tool> \ No newline at end of file