-
Notifications
You must be signed in to change notification settings - Fork 441
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: implement tool to add rank names to phyloseq object #6625
Open
MaraBesemer
wants to merge
6
commits into
galaxyproject:main
Choose a base branch
from
MaraBesemer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e37921d
add: implement tool to add rank names to phyloseq object
6c50914
Update add_rank_names_to_phyloseq.xml
MaraBesemer 64265fb
add: enhance add_rank_names_to_phyloseq tool with ranks option for ta…
a1e6046
Merge branch 'main' of https://github.com/MaraBesemer/tools-iuc into …
c0751ed
fix: enforce strict matching of taxonomy table columns to provided ranks
0d981e7
fix: remove 'Species' rank from test parameters in add_rank_names_to_…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
suppressPackageStartupMessages(library("optparse")) | ||
suppressPackageStartupMessages(library("phyloseq")) | ||
suppressPackageStartupMessages(library("tidyverse")) | ||
|
||
# Option parsing | ||
option_list <- list( | ||
make_option(c("--input"), | ||
action = "store", dest = "input", | ||
help = "Input file containing a phyloseq object" | ||
), | ||
make_option(c("--output"), | ||
action = "store", dest = "output", | ||
help = "Output file for the updated phyloseq object" | ||
), | ||
make_option(c("--ranks"), | ||
action = "store", dest = "ranks", | ||
help = "Comma-separated list of taxonomy ranks (default: Kingdom,Phylum,Class,Order,Family,Genus,Species)" | ||
) | ||
) | ||
|
||
parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) | ||
args <- parse_args(parser, positional_arguments = TRUE) | ||
opt <- args$options | ||
|
||
cat("Input file: ", opt$input, "\n") | ||
cat("Output file: ", opt$output, "\n") | ||
cat("Ranks provided: ", opt$ranks, "\n") | ||
|
||
if (is.null(opt$ranks)) { | ||
opt$ranks <- "Kingdom,Phylum,Class,Order,Family,Genus,Species" | ||
} | ||
|
||
# Parse rank names | ||
rank_names <- unlist(strsplit(opt$ranks, ",")) | ||
|
||
# Load phyloseq object | ||
physeq <- readRDS(opt$input) | ||
|
||
# Check if physeq object is loaded successfully | ||
if (is.null(physeq)) { | ||
stop("Error: Failed to load the Phyloseq object. Check the input file.") | ||
} | ||
|
||
cat("Phyloseq object successfully loaded.\n") | ||
cat("Class of loaded object: ", class(physeq), "\n") | ||
|
||
# Check the current tax_table | ||
cat("Current tax_table:\n") | ||
print(tax_table(physeq)) | ||
|
||
|
||
# Strict check for taxonomy table and provided ranks | ||
if (ncol(tax_table(physeq)) != length(rank_names)) { | ||
stop( | ||
"Error: Number of columns in tax_table does not match the number of provided ranks. ", | ||
"Please ensure the taxonomy table matches the ranks exactly." | ||
) | ||
} | ||
|
||
# Set column names to the provided ranks | ||
colnames(tax_table(physeq)) <- rank_names | ||
|
||
# Confirm the changes | ||
cat("Updated tax_table:\n") | ||
print(tax_table(physeq)) | ||
|
||
# Save the updated phyloseq object | ||
saveRDS(physeq, file = opt$output, compress = TRUE) | ||
cat("Updated Phyloseq object saved to: ", opt$output, "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<tool id="add_rank_names_to_phyloseq" name="Add Rank Names to Phyloseq Object" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> | ||
<description>Add taxonomy rank names to 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__}/add_rank_names_to_phyloseq.R' --input '$input' --output '$output' --ranks '$ranks' | ||
]]></command> | ||
|
||
<inputs> | ||
<expand macro="phyloseq_input"/> | ||
<param name="ranks" type="text" label="Comma-separated list of taxonomy ranks" value="Kingdom,Phylum,Class,Order,Family,Genus,Species"/> | ||
</inputs> | ||
|
||
<outputs> | ||
<data name="output" format="phyloseq"/> | ||
</outputs> | ||
|
||
<tests> | ||
<test> | ||
<param name="input" value="output.phyloseq" ftype="phyloseq"/> | ||
<param name="ranks" value="Kingdom,Phylum,Class,Order,Family,Genus"/> | ||
<output name="output" ftype="phyloseq"> | ||
<assert_contents> | ||
<has_size value="87125" delta="1000"/> | ||
</assert_contents> | ||
</output> | ||
</test> | ||
</tests> | ||
|
||
<help> | ||
This tool adds taxonomy rank names to a phyloseq object in the `tax_table` slot. | ||
</help> | ||
<expand macro="citations"/> | ||
</tool> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could compare the new phylosq object to expected output, like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better just use an
has_size
assertion and removevalue="AalborgWWTPs-subset_samples.rds"
.