Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions R/convertFromBIOM.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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?

Copy link
Contributor

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

#'
#' @param ... additional arguments to be passed to \code{convertFromBIOM}
#'
#' @details
Expand Down Expand Up @@ -111,10 +118,27 @@ NULL
#' tse <- importBIOM(biom_file, artifact.rm = TRUE)
#'
#' @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 <- ape::read.tree(tree.file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add importFrom and use without specifying the package

rowTree(tse) <- tree
}
Comment on lines +131 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The 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):

Warning message:
18371 row(s) couldn't be matched to the tree and are/is removed.

One could provide links between rows and nodes of tree, but it becomes too complicated.

Proposal:

  • Pack this tree adding script into function
  • Check if rownames can be found from tree. If not, give error:

"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)"


tse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return(tse)

}

#' @rdname importBIOM
Expand Down
15 changes: 14 additions & 1 deletion R/importHumann.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#' path of the sample metadata file. The file must be in \code{tsv} format
#' (Default: \code{NULL}).
#'
#' @param tree.file \code{Character scalar}. Optional path to a
#' phylogenetic tree. If provided, the tree is attached as \code{rowTree}.
#'
#' @param colData Deprecated. Use \code{col.data} instead.
#'
#' @param ... additional arguments:
Expand Down Expand Up @@ -69,7 +72,8 @@
#'
NULL

importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){
importHUMAnN <- function(file, col.data = colData, colData = NULL,
tree.file = NULL, ...){
################################ Input check ###############################
if(!.is_non_empty_string(file)){
stop("'file' must be a single character value.",
Expand All @@ -84,6 +88,10 @@ importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){
stop("'col.data' must be a single character value, DataFrame or NULL.",
call. = FALSE)
}
if (!is.null(tree.file) && !.is_non_empty_string(tree.file)) {
stop("'tree.file' must be a single character value or NULL.",
call. = FALSE)
}
############################## Input check end #############################
# Humann files has these columns that goes to rowData
rowdata_col <- c("Pathway", "Gene_Family")
Expand All @@ -95,6 +103,11 @@ importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){
if( !is.null(col.data) ){
tse <- .add_coldata(tse, col.data)
}
# Add tree if provided
if (!is.null(tree.file)) {
tree <- ape::read.tree(tree.file)
rowTree(tse) <- tree
}
return(tse)
}

Expand Down
20 changes: 18 additions & 2 deletions R/importMothur.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#'
#' @param designFile Deprecated. Use \code{col.file} instead.
#'
#' @param tree.file \code{Character scalar}. Optional path to a phylogenetic
#' tree in Newick format. If provided, the tree is attached as
#' \code{rowTree}.
#'
#' @details
#' Results exported from Mothur can be imported as a
#' \code{SummarizedExperiment} using \code{importMothur}. Except for the
Expand Down Expand Up @@ -72,7 +76,8 @@ importMothur <- function(assay.file = sharedFile,
taxonomyFile = NULL,
row.file = taxonomyFile,
designFile = NULL,
col.file = designFile) {
col.file = designFile,
tree.file = NULL) {

# input check
if(!.is_non_empty_string(assay.file)){
Expand All @@ -87,6 +92,10 @@ importMothur <- function(assay.file = sharedFile,
stop("'col.file' must be a single character value or NULL.",
call. = FALSE)
}
if (!is.null(tree.file) && !.is_non_empty_string(tree.file)) {
stop("'tree.file' must be a single character value or NULL.",
call. = FALSE)
}

# Reads the assay.file
feature_tab_and_data_to_colData <- .read_mothur_feature(assay.file)
Expand All @@ -113,10 +122,17 @@ importMothur <- function(assay.file = sharedFile,
rownames(sample_meta) <- colnames(feature_tab)
}

TreeSummarizedExperiment(
tse <- TreeSummarizedExperiment(
assays = S4Vectors::SimpleList(counts = feature_tab),
rowData = taxa_tab,
colData = sample_meta)

if (!is.null(tree.file)) {
tree <- ape::read.tree(tree.file)
rowTree(tse) <- tree
}

tse
}

# These extra information must be added to colData. Return list of assay and
Expand Down
9 changes: 8 additions & 1 deletion man/importBIOM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/importHUMAnN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/importMothur.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading