write_biom: Save an rbiom object to a file.

write_biomR Documentation

Save an rbiom object to a file.

Description

Automatically creates directories and adds compression based on file name.

  • write_biom() - According to BIOM format specification.

  • write_xlsx() - Raw data and summary tables in Excel file format. See details.

  • write_fasta() - Sequences only in fasta format. biom may also be a named character vector.

  • write_tree() - Phylogenetic tree only in newick format. biom may also be a phylo object.

  • write_counts(), write_metadata(), write_taxonomy() - Tab-separated values.

Usage

write_biom(biom, file, format = "json")

write_metadata(biom, file, quote = FALSE, sep = "\t", ...)

write_counts(biom, file, quote = FALSE, sep = "\t", ...)

write_taxonomy(biom, file, quote = FALSE, sep = "\t", ...)

write_fasta(biom, file = NULL)

write_tree(biom, file = NULL)

write_xlsx(biom, file, depth = "auto", n = NULL, seed = 0, unc = "singly")

Arguments

biom

An rbiom object, such as from as_rbiom(). Any value accepted by as_rbiom() can also be given here.

file

Path to the output file. File names ending in .gz or .bz2 will be compressed accordingly. write_fasta() and write_tree() can have file=NULL, which returns a string of the output which would have been written.

format

Options are "tab", "json", and "hdf5", corresponding to classic tabular format, BIOM format version 1.0 and biom version 2.1, respectively. NOTE: to write HDF5 formatted BIOM files, the BioConductor R package rhdf5 must be installed. Default: "json"

quote, sep, ...

Parameters passed on to write.table(). Default: ⁠quote=FALSE, sep="\t"⁠

depth, n, seed

Passed on to rarefy_cols(). For write_xlsx() only, depth=0 disables rarefaction. Default: ⁠depth='auto', n=NULL, seed=0⁠

seed

Random seed to use in rarefying. See rarefy_cols() function for details. Default: 0

unc

How to handle unclassified, uncultured, and similarly ambiguous taxa names. Options are:

  • "singly" - Replaces them with the OTU name.

  • "grouped" - Replaces them with a higher rank's name.

  • "drop" - Excludes them from the result.

  • "asis" - To not check/modify any taxa names.

Default: "singly"

Abbreviations are allowed.

Details

For write_xlsx(), attributes(biom) are saved as additional worksheets if the attribute is a data frame, matrix, or dist -class object. An attribute named 'Reads Per Step' is treated specially and merged with the usual 'Reads Per Sample' tab.

Value

The normalized filepath that was written to (invisibly).

Examples

    library(rbiom)
    
    write_tree(hmp50) %>% substr(1, 50)
    
    if (FALSE) {
    
      hmp10        <- hmp50$clone()
      hmp10$counts <- hmp10$counts[,1:10] %>% rarefy_cols()
      
      attr(hmp10, "Weighted UniFrac")   <- bdiv_distmat(hmp10, 'unifrac')
      attr(hmp10, "Unweighted Jaccard") <- bdiv_distmat(hmp10, 'jaccard', weighted=F)
      
      outfile <- write_xlsx(hmp10, tempfile(fileext = ".xlsx"))
    }


cmmr/rbiom documentation built on April 28, 2024, 6:38 a.m.