-
Notifications
You must be signed in to change notification settings - Fork 34
Add tree and metadata options to importers #798
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
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,13 @@ NULL | |
| #' | ||
| #' @param file BIOM file location | ||
| #' | ||
| #' @param col.data a DataFrame-like object that includes sample names in | ||
| #' rownames, or a single \code{character} value defining the file | ||
| #' path of the sample metadata file (tsv). (Default: \code{NULL}). | ||
| #' | ||
| #' @param tree.file \code{Character scalar}. Optional path to a phylogenetic | ||
| #' tree. If provided, replaces any tree stored in the BIOM metadata. | ||
| #' | ||
| #' @param ... additional arguments to be passed to \code{convertFromBIOM} | ||
| #' | ||
| #' @details | ||
|
|
@@ -110,11 +117,45 @@ NULL | |
| #' # Clean artifacts from taxonomic data | ||
| #' tse <- importBIOM(biom_file, artifact.rm = TRUE) | ||
| #' | ||
| #' @importFrom ape read.tree | ||
| #' @export | ||
| importBIOM <- function(file, ...) { | ||
| importBIOM <- function(file, col.data = NULL, tree.file = NULL, ...) { | ||
| .require_package("biomformat") | ||
| biom <- biomformat::read_biom(file) | ||
| convertFromBIOM(biom, ...) | ||
| tse <- convertFromBIOM(biom, ...) | ||
|
|
||
| # Load sample metadata if provided (overrides BIOM sample metadata) | ||
| if (!is.null(col.data)) { | ||
| tse <- .add_coldata(tse, col.data) | ||
| } | ||
|
|
||
| # Load/replace tree if provided | ||
| if (!is.null(tree.file)) { | ||
| if (!.is_non_empty_string(tree.file)) { | ||
| stop("'tree.file' must be a single character value or NULL.", | ||
| call. = FALSE) | ||
| } | ||
| tree <- read.tree(tree.file) | ||
| # Validate that rownames(tse) can be matched to tree tip labels. If | ||
| # not, give a clear error so users know to construct the TreeSE | ||
| # without the tree and then add it manually using `changeTree`. | ||
| if (!all(rownames(tse) %in% tree$tip.label)) { | ||
| stop( | ||
| paste( | ||
| "Rownames do not match with tree labels. Construct", | ||
| "TreeSE without tree (tree.file=NULL) and then add", | ||
| "the tree manually with", | ||
| "changeTree(tse, tree = tree_object,", | ||
| "rowNodeLab = link_vector)", | ||
| sep = "\n" | ||
| ), | ||
| call. = FALSE | ||
| ) | ||
| } | ||
| rowTree(tse) <- tree | ||
| } | ||
|
Comment on lines
+132
to
+156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The node names in tree must match exactly the rownames. Otherwise, the rows cannot be linked with the tree and it leads to warning that some rows were dropped (it is hard for user to know what is the problem):
One could provide links between rows and nodes of tree, but it becomes too complicated. Proposal:
|
||
|
|
||
| return(tse) | ||
| } | ||
|
|
||
| #' @rdname importBIOM | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Is it possible to provide multiple trees?
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.
In theory uses, but there is no any practical use-cases