Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

make_biom

Create a biom-class from matrix-class or data.frame.


Description

This function creates a valid instance of the biom-class from standard base-R objects like matrix-class or data.frame. This makes it possible to export any contingency table data represented in R to the biom-format, regardless of its source. The object returned by this function is appropriate for writing to a .biom file using the write_biom function. The sparse biom-format is not (yet) supported.

Usage

make_biom(data, sample_metadata = NULL, observation_metadata = NULL,
  id = NULL, matrix_element_type = "int")

Arguments

data

(Required). matrix-class or data.frame. A contingency table. Observations / features / OTUs / species are rows, samples / sites / libraries are columns.

sample_metadata

(Optional). A matrix-class or data.frame with the number of rows equal to the number of samples in data. Sample covariates associated with the count data. This should look like the table returned by sample_metadata on a valid instance of the biom-class.

observation_metadata

(Optional). A matrix-class or data.frame with the number of rows equal to the number of features / species / OTUs / genes in data. This should look like the table returned by observation_metadata on a valid instance of the biom-class.

id

(Optional). Character string. Identifier for the project.

matrix_element_type

(Optional). Character string. Either 'int' or 'float'

Details

The BIOM file format (canonically pronounced biome) is designed to be a general-use format for representing biological sample by observation contingency tables. BIOM is a recognized standard for the Earth Microbiome Project and is a Genomics Standards Consortium candidate project. Please see the biom-format home page for more details.

Value

An object of biom-class.

References

See Also

Examples

# import with default parameters, specify a file
biomfile = system.file("extdata", "rich_dense_otu_table.biom", package = "biomformat")
x = read_biom(biomfile)
data = biom_data(x)
data
smd = sample_metadata(x)
smd
omd = observation_metadata(x)
omd
# Make a new biom object from component data
y = make_biom(data, smd, omd)
# Won't be identical to x because of header info.
identical(x, y)
# The data components should be, though.
identical(observation_metadata(x), observation_metadata(y))
identical(sample_metadata(x), sample_metadata(y))
identical(biom_data(x), biom_data(y))
## Quickly show that writing and reading still identical.
# Define a temporary directory to write .biom files
tempdir = tempdir()
write_biom(x, biom_file=file.path(tempdir, "x.biom"))
write_biom(y, biom_file=file.path(tempdir, "y.biom"))
x1 = read_biom(file.path(tempdir, "x.biom"))
y1 = read_biom(file.path(tempdir, "y.biom"))
identical(observation_metadata(x1), observation_metadata(y1))
identical(sample_metadata(x1), sample_metadata(y1))
identical(biom_data(x1), biom_data(y1))

biomformat

An interface package for the BIOM file format

v1.18.0
GPL-2
Authors
Paul J. McMurdie <mcmurdie@stanford.edu> and Joseph N Paulson <jpaulson@jimmy.harvard.edu>
Initial release
2016-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.