Learn R Programming

OmicFlow (version 1.4.2)

metagenomics: Sub-class metagenomics

Description

This is a sub-class that is compatible to data obtained from either 16S rRNA marker-gene sequencing or shot-gun metagenomics sequencing. It inherits all methods from the abstract class omics and only adapts the initialize function. It supports BIOM format data (v2.1.0 from http://biom-format.org/) in both HDF5 and JSON format, also pre-existing data structures can be used or text files. When omics data is very large, data loading becomes very expensive. It is therefore recommended to use the reset() method to reset your changes. Every omics class creates an internal memory efficient back-up of the data, the resetting of changes is an instant process.

Arguments

Super class

OmicFlow::omics -> metagenomics

Public fields

countData

A path to an existing file, data.table, data.frame, matrix or sparseMatrix with zero values.

metaData

A path to an existing file, data.table or data.frame.

featureData

A path to an existing file, data.table or data.frame.

treeData

A path to an existing newick file or class "phylo", see read.tree.

biomData

A path to an existing biom file or hdf5 file, see h5read.

Methods

Inherited methods


Method new()

Initializes the metagenomics class object with metagenomics$new()

Usage

metagenomics$new(
  countData = NULL,
  metaData = NULL,
  featureData = NULL,
  treeData = NULL,
  biomData = NULL,
  feature_names = c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")
)

Arguments

countData

countData A path to an existing file, data.table, data.frame, matrix or sparseMatrix with zero values.

metaData

A path to an existing file, data.table or data.frame.

featureData

A path to an existing file, data.table or data.frame.

treeData

A path to an existing newick file or class "phylo", see read.tree.

biomData

A path to an existing biom file, version 2.1.0 (http://biom-format.org/), see h5read.

feature_names

A character vector to name the feature names that fit the supplied featureData.

Returns

A new metagenomics object.


Method print()

Displays parameters of the metagenomics object via stdout.

Usage

metagenomics$print()

Returns

object in place

Examples

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow") counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow") features_file <- system.file("extdata", "features.tsv", package = "OmicFlow") tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new( metaData = metadata_file, countData = counts_file, featureData = features_file, treeData = tree_file )

# method 1 to call print function taxa

# method 2 to call print function taxa$print()


Method reset()

Upon creation of a new metagenomics object a small backup of the original data is created. Since modification of the object is done by reference and duplicates are not made, it is possible to reset changes to the class. The methods from the abstract class omics also contains a private method to prevent any changes to the original object when using methods such as ordination alpha_diversity or $DFE.

Usage

metagenomics$reset()

Returns

object in place

Examples

library(ggplot2)
library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow") counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow") features_file <- system.file("extdata", "features.tsv", package = "OmicFlow") tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new( metaData = metadata_file, countData = counts_file, featureData = features_file, treeData = tree_file )

# Performs modifications taxa$transform(log2)

# resets taxa$reset()

# An inbuilt reset function prevents unwanted modification to the taxa object. taxa$rankstat(feature_ranks = c("Kingdom", "Phylum", "Family", "Genus", "Species"))


Method removeZeros()

Removes empty (zero) values by row, column and tips from the countData and treeData. This method is performed automatically during subsetting of the object.

Usage

metagenomics$removeZeros()

Returns

object in place

Examples

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow") counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow") features_file <- system.file("extdata", "features.tsv", package = "OmicFlow") tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new( metaData = metadata_file, countData = counts_file, featureData = features_file, treeData = tree_file )

# Sample subset induces empty features taxa$sample_subset(treatment == "tumor")

# Remove empty features from countData and treeData taxa$removeZeros()


Method write_biom()

Creates a BIOM file in HDF5 format of the loaded items via 'new()', which is compatible to the python biom-format version 2.1, see http://biom-format.org.

Usage

metagenomics$write_biom(filename)

Arguments

filename

A character variable of either the full path of filename of the biom file (e.g. output.biom)

Examples

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow") counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow") features_file <- system.file("extdata", "features.tsv", package = "OmicFlow") tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new( metaData = metadata_file, countData = counts_file, featureData = features_file, treeData = tree_file )

taxa$write_biom(filename = "output.biom") file.remove("output.biom")

See Also

omics

Examples

Run this code

## ------------------------------------------------
## Method `metagenomics$print`
## ------------------------------------------------

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new(
 metaData = metadata_file,
 countData = counts_file,
 featureData = features_file,
 treeData = tree_file
)

# method 1 to call print function
taxa

# method 2 to call print function
taxa$print()


## ------------------------------------------------
## Method `metagenomics$reset`
## ------------------------------------------------

library(ggplot2)
library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new(
 metaData = metadata_file,
 countData = counts_file,
 featureData = features_file,
 treeData = tree_file
)

# Performs modifications
taxa$transform(log2)

# resets
taxa$reset()

# An inbuilt reset function prevents unwanted modification to the taxa object.
taxa$rankstat(feature_ranks = c("Kingdom", "Phylum", "Family", "Genus", "Species"))


## ------------------------------------------------
## Method `metagenomics$removeZeros`
## ------------------------------------------------

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new(
 metaData = metadata_file,
 countData = counts_file,
 featureData = features_file,
 treeData = tree_file
)

# Sample subset induces empty features
taxa$sample_subset(treatment == "tumor")

# Remove empty features from countData and treeData
taxa$removeZeros()


## ------------------------------------------------
## Method `metagenomics$write_biom`
## ------------------------------------------------

library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new(
 metaData = metadata_file,
 countData = counts_file,
 featureData = features_file,
 treeData = tree_file
)

taxa$write_biom(filename = "output.biom")
file.remove("output.biom")

Run the code above in your browser using DataLab