R/convertFromBIOM.R, R/convertFromDADA2.R, R/convertFromPhyloseq.R, and 1 more
convert.RdFor convenience, a few functions are available to convert BIOM, DADA2 and
phyloseq objects to
TreeSummarizedExperiment
objects, and
TreeSummarizedExperiment
objects to phyloseq objects.
convertFromBIOM(
x,
prefix.rm = removeTaxaPrefixes,
removeTaxaPrefixes = FALSE,
rank.from.prefix = rankFromPrefix,
rankFromPrefix = FALSE,
artifact.rm = remove.artifacts,
remove.artifacts = FALSE,
...
)
convertToBIOM(x, assay.type = "counts", ...)
# S4 method for class 'SummarizedExperiment'
convertToBIOM(x, assay.type = "counts", ...)
convertFromDADA2(...)
convertFromPhyloseq(x)
convertToPhyloseq(x, ...)
# S4 method for class 'SummarizedExperiment'
convertToPhyloseq(x, assay.type = "counts", assay_name = NULL, ...)
# S4 method for class 'TreeSummarizedExperiment'
convertToPhyloseq(x, tree.name = tree_name, tree_name = "phylo", ...)a
TreeSummarizedExperiment
object
TRUE or FALSE: Should
taxonomic prefixes be removed? The prefixes is removed only from detected
taxa columns meaning that rank.from.prefix should be enabled in the most cases.
(default prefix.rm = FALSE)
Deprecated. Use prefix.rm instead.
TRUE or FALSE: If file does not have
taxonomic ranks on feature table, should they be scraped from prefixes?
(default rank.from.prefix = FALSE)
Deprecated.Use rank.from.prefix instead.
TRUE or FALSE: If file have
some taxonomic character naming artifacts, should they be removed.
(default artifact.rm = FALSE)
Deprecated. Use artifact.rm instead.
Additional arguments. For convertFromDADA2, see
mergePairs function for more details.
A single character value for selecting the
assay to be
included in the phyloseq object that is created.
(By default: assay.type = "counts")
a single character value for specifying which
assay to use for calculation.
(Please use assay.type instead. At some point assay_name
will be disabled.)
a single character value for specifying which
tree will be included in the phyloseq object that is created,
(By default: tree.name = "phylo")
Deprecated. Use tree.name instead.
convertFromBIOM returns an object of class
TreeSummarizedExperiment
convertFromDADA2 returns an object of class
TreeSummarizedExperiment
convertFromPhyloseq returns an object of class
TreeSummarizedExperiment
convertToPhyloseq returns an object of class
phyloseq
convertFromBIOM coerces a BIOM object to a
TreeSummarizedExperiment
object.
convertFromBIOM coerces a
TreeSummarizedExperiment
object to a biom object.
convertFromDADA2 is a wrapper for the
mergePairs function from the dada2 package.
A count matrix is constructed via
makeSequenceTable(mergePairs(...)) and rownames are dynamically
created as ASV(N) with N from 1 to nrow of the count
tables. The colnames and rownames from the output of makeSequenceTable
are stored as colnames and in the referenceSeq slot of the
TreeSummarizedExperiment, respectively.
convertFromPhyloseq converts phyloseq
objects into
TreeSummarizedExperiment objects.
All data stored in a phyloseq object is transferred.
convertToPhyloseq creates a phyloseq object from a
TreeSummarizedExperiment
object. By using assay.type, it is possible to specify which table
from assay is added to the phyloseq object.
# Convert BIOM results to a TreeSE
# Load biom file
library(biomformat)
biom_file <- system.file("extdata", "rich_dense_otu_table.biom",
package = "biomformat")
# Make TreeSE from BIOM object
biom_object <- biomformat::read_biom(biom_file)
tse <- convertFromBIOM(biom_object)
# Convert TreeSE object to BIOM
biom <- convertToBIOM(tse)
### Coerce DADA2 results to a TreeSE object
if(requireNamespace("dada2")) {
fnF <- system.file("extdata", "sam1F.fastq.gz", package="dada2")
fnR = system.file("extdata", "sam1R.fastq.gz", package="dada2")
dadaF <- dada2::dada(fnF, selfConsist=TRUE)
dadaR <- dada2::dada(fnR, selfConsist=TRUE)
tse <- convertFromDADA2(dadaF, fnF, dadaR, fnR)
tse
}
#> Loading required namespace: dada2
#> Initializing error rates to maximum possible estimate.
#> selfConsist step 1 .
#> selfConsist step 2
#> selfConsist step 3
#> selfConsist step 4
#> Convergence after 4 rounds.
#> Initializing error rates to maximum possible estimate.
#> selfConsist step 1 .
#> selfConsist step 2
#> selfConsist step 3
#> selfConsist step 4
#> Convergence after 4 rounds.
#> class: TreeSummarizedExperiment
#> dim: 4 1
#> metadata(0):
#> assays(1): counts
#> rownames(4): ASV01 ASV02 ASV03 ASV04
#> rowData names(0):
#> colnames: NULL
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: NULL
#> rowTree: NULL
#> colLinks: NULL
#> colTree: NULL
#> referenceSeq: a DNAStringSet (4 sequences)
### Coerce a phyloseq object to a TreeSE object
if (requireNamespace("phyloseq")) {
data(GlobalPatterns, package="phyloseq")
convertFromPhyloseq(GlobalPatterns)
data(enterotype, package="phyloseq")
convertFromPhyloseq(enterotype)
data(esophagus, package="phyloseq")
convertFromPhyloseq(esophagus)
}
#> Loading required namespace: phyloseq
#> class: TreeSummarizedExperiment
#> dim: 58 3
#> metadata(0):
#> assays(1): counts
#> rownames(58): 59_8_22 59_5_13 ... 65_9_9 59_2_6
#> rowData names(0):
#> colnames(3): B C D
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: a LinkDataFrame (58 rows)
#> rowTree: 1 phylo tree(s) (58 leaves)
#> colLinks: NULL
#> colTree: NULL
### Coerce a TreeSE object to a phyloseq object
# Get tse object
data(GlobalPatterns)
tse <- GlobalPatterns
# Create a phyloseq object from it
phy <- convertToPhyloseq(tse)
phy
#> phyloseq-class experiment-level object
#> otu_table() OTU Table: [ 19216 taxa and 26 samples ]
#> sample_data() Sample Data: [ 26 samples by 7 sample variables ]
#> tax_table() Taxonomy Table: [ 19216 taxa by 7 taxonomic ranks ]
#> phy_tree() Phylogenetic Tree: [ 19216 tips and 19215 internal nodes ]
# By default the chosen table is counts, but if there are other tables,
# they can be chosen with assay.type.
# Counts relative abundances table
tse <- transformAssay(tse, method = "relabundance")
phy2 <- convertToPhyloseq(tse, assay.type = "relabundance")
phy2
#> phyloseq-class experiment-level object
#> otu_table() OTU Table: [ 19216 taxa and 26 samples ]
#> sample_data() Sample Data: [ 26 samples by 7 sample variables ]
#> tax_table() Taxonomy Table: [ 19216 taxa by 7 taxonomic ranks ]
#> phy_tree() Phylogenetic Tree: [ 19216 tips and 19215 internal nodes ]