Skip to content

Commit 198360c

Browse files
authored
Fix phyloseq converter (#711)
1 parent f7ec6c3 commit 198360c

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mia
22
Type: Package
3-
Version: 1.15.31
3+
Version: 1.15.32
44
Authors@R:
55
c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"),
66
email = "[email protected]",

R/convertFromPhyloseq.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#' Create a \code{TreeSummarizedExperiment} object from a phyloseq object
2-
#'
2+
#'
33
#' @inheritParams convertFromBIOM
4-
#'
5-
#' @details
4+
#'
5+
#' @details
66
#' \code{convertFromPhyloseq} converts \code{phyloseq}
7-
#' objects into
7+
#' objects into
88
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} objects.
99
#' All data stored in a \code{phyloseq} object is transferred.
1010
#'
11-
#' @return
12-
#' \code{convertFromPhyloseq} returns an object of class
11+
#' @return
12+
#' \code{convertFromPhyloseq} returns an object of class
1313
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}
1414
#'
1515
#' @importFrom S4Vectors SimpleList DataFrame make_zero_col_DFrame
@@ -20,7 +20,7 @@
2020
#' @rdname convertFromPhyloseq
2121
#'
2222
#' @examples
23-
#'
23+
#'
2424
#' ### Coerce a phyloseq object to a TreeSE object
2525
#' if (requireNamespace("phyloseq")) {
2626
#' data(GlobalPatterns, package="phyloseq")
@@ -38,14 +38,14 @@ convertFromPhyloseq <- function(x) {
3838
}
3939
#
4040
# Get the assay
41-
counts <- phyloseq::otu_table(x)
41+
counts <- phyloseq::otu_table(x) |> as.matrix() |> unclass()
4242
# Check the orientation, and transpose if necessary
4343
if( !phyloseq::taxa_are_rows(x) ){
4444
counts <- t(counts)
4545
}
4646
# Create a list of assays
4747
assays <- SimpleList(counts = counts)
48-
48+
4949
rowData <- tryCatch(phyloseq::tax_table(x), error = function(e) NULL) |>
5050
data.frame() |> DataFrame()
5151
if( nrow(rowData) == 0L ){

tests/testthat/test-4IO.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ test_that("Importing phyloseq objects yield TreeSummarizedExperiment objects", {
159159
data(GlobalPatterns, package="phyloseq")
160160
me <- convertFromPhyloseq(GlobalPatterns)
161161
expect_s4_class(me, "TreeSummarizedExperiment")
162+
expect_is(assay(me), "matrix")
163+
expect_true( !is(assay(me), "otu_table") )
164+
expect_s4_class(colData(me), "DataFrame")
165+
expect_s4_class(rowData(me), "DataFrame")
166+
expect_is(rowTree(me), "phylo")
162167
expect_equal(dim(me),c(19216,26))
163168
data(enterotype, package="phyloseq")
164169
me <- convertFromPhyloseq(enterotype)

0 commit comments

Comments
 (0)