Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add phyloseq bar chart #6575

Merged
merged 15 commits into from
Dec 3, 2024
32 changes: 32 additions & 0 deletions tools/phyloseq/phyloseq_plot_bar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env Rscript

# Load libraries
suppressPackageStartupMessages(library("optparse"))
suppressPackageStartupMessages(library("phyloseq"))
suppressPackageStartupMessages(library("ggplot2"))

option_list <- list(
make_option(c("--input"), action = "store", dest = "input", help = "Input file containing a phyloseq object"),
make_option(c("--x"), action = "store", dest = "x", help = "Variable for x-axis (e.g., 'Sample', 'Phylum')"),
make_option(c("--fill"), action = "store", dest = "fill", help = "Variable for fill color (e.g., 'Genus', 'Order')"),
make_option(c("--facet"), action = "store", dest = "facet", default = NULL, help = "Facet by variable (optional)"),
make_option(c("--output"), action = "store", dest = "output", help = "Output file (PDF)")
)

# Parse arguments
parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
args <- parse_args(parser)
opt <- args$options

# Load phyloseq object
physeq <- readRDS(opt$input)

# Generate bar plot
p <- plot_bar(physeq, x = opt$x, fill = opt$fill)

if (!is.null(opt$facet)) {
p <- p + facet_wrap(as.formula(paste("~", opt$facet)))
}

# Save to output file
ggsave(opt$output, plot = p, width = 10, height = 8)
60 changes: 60 additions & 0 deletions tools/phyloseq/phyloseq_plot_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<tool id="phyloseq_plot_bar" name="Phyloseq: Bar Chart" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
<description>Generate bar charts from a phyloseq object</description>
<macros>
<import>macros.xml</import>
</macros>
<expand macro="bio_tools"/>
<expand macro="requirements"/>
<command detect_errors="exit_code"><![CDATA[
Rscript '${__tool_directory__}/phyloseq_plot_bar.R'
--input '$input'
--x '$x'
--fill '$fill'
--facet '${facet}'
--output '$output'
]]></command>
<inputs>
<expand macro="phyloseq_input"/>
<param name="x" type="text" label="X-axis variable" help="Variable for the x-axis (e.g., Sample, Phylum)" />
<param name="fill" type="text" label="Fill variable" help="Variable to color the bars (e.g., Genus, Order)" />
<param name="facet" type="text" optional="true" label="Facet by variable" help="Optional: Variable to facet the chart by (e.g., SampleType)" />
</inputs>
<outputs>
<data name="output" format="pdf" label="Bar Chart (PDF)" />
</outputs>
<tests>
<test>
<param name="input" value="output.phyloseq" ftype="phyloseq"/>
<param name="x" value="Sample"/>
<param name="fill" value="Genus"/>
<param name="facet" value="SampleType"/>
<output name="output" ftype="pdf">
<assert_contents>
<has_text text="%PDF"/>
<has_text text="%%EOF"/>
</assert_contents>
</output>
</test>
</tests>
<help>
**Description**

This tool generates bar charts from a phyloseq object using the `plot_bar` function.

**Inputs**

- **Input**: A phyloseq object in RDS format.
- **X-axis variable**: The variable to use for the x-axis (e.g., Sample, Phylum).
- **Fill variable**: The variable to use for the bar fill colors (e.g., Genus, Order).
- **Facet by variable**: (Optional) A variable to facet the bar chart (e.g., SampleType).

**Outputs**

- A PDF file containing the bar chart.

**Usage Notes**

Ensure that the input file is a valid phyloseq object in RDS format.
</help>
<expand macro="citations"/>
</tool>
Loading