make_biom: Create a 'biom-class' from 'matrix-class' or 'data.frame'.

Description Usage Arguments Details Value References See Also Examples

View source: R/BIOM-class.R

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

1
2

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

http://biom-format.org/

See Also

write_biom

biom-class

read_biom

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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))

Example output

5 x 6 Matrix of class "dgeMatrix"
         Sample1 Sample2 Sample3 Sample4 Sample5 Sample6
GG_OTU_1       0       0       1       0       0       0
GG_OTU_2       5       1       0       2       3       1
GG_OTU_3       0       0       1       4       2       0
GG_OTU_4       2       1       1       0       0       1
GG_OTU_5       0       1       1       0       0       0
        BarcodeSequence  LinkerPrimerSequence BODY_SITE Description
Sample1    CGCTTATCGAGA CATGCTGCCTCCCGTAGGAGT       gut   human gut
Sample2    CATACCAGTAGC CATGCTGCCTCCCGTAGGAGT       gut   human gut
Sample3    CTCTCTACCTGT CATGCTGCCTCCCGTAGGAGT       gut   human gut
Sample4    CTCTCGGCCTGT CATGCTGCCTCCCGTAGGAGT      skin  human skin
Sample5    CTCTCTACCAAT CATGCTGCCTCCCGTAGGAGT      skin  human skin
Sample6    CTAACTACCAAT CATGCTGCCTCCCGTAGGAGT      skin  human skin
           taxonomy1         taxonomy2              taxonomy3
GG_OTU_1 k__Bacteria p__Proteobacteria c__Gammaproteobacteria
GG_OTU_2 k__Bacteria  p__Cyanobacteria    c__Nostocophycideae
GG_OTU_3  k__Archaea  p__Euryarchaeota     c__Methanomicrobia
GG_OTU_4 k__Bacteria     p__Firmicutes          c__Clostridia
GG_OTU_5 k__Bacteria p__Proteobacteria c__Gammaproteobacteria
                    taxonomy4             taxonomy5         taxonomy6
GG_OTU_1 o__Enterobacteriales f__Enterobacteriaceae    g__Escherichia
GG_OTU_2        o__Nostocales        f__Nostocaceae g__Dolichospermum
GG_OTU_3 o__Methanosarcinales f__Methanosarcinaceae g__Methanosarcina
GG_OTU_4   o__Halanaerobiales   f__Halanaerobiaceae  g__Halanaerobium
GG_OTU_5 o__Enterobacteriales f__Enterobacteriaceae    g__Escherichia
                               taxonomy7
GG_OTU_1                             s__
GG_OTU_2                             s__
GG_OTU_3                             s__
GG_OTU_4 s__Halanaerobiumsaccharolyticum
GG_OTU_5                             s__
[1] FALSE
[1] TRUE
[1] TRUE
[1] TRUE
[1] FALSE
[1] FALSE
[1] TRUE

biomformat documentation built on Nov. 8, 2020, 7:43 p.m.