R/check_phyloseq.R

check_phyloseq <- function (x, fill_na_taxa = TRUE) {

    # Sanity checks for a phyloseq object. Required with some methods.
    if (!taxa_are_rows(x)) {
        x@otu_table <- otu_table(t(otu_table(x)), taxa_are_rows = TRUE)
    }

    if (fill_na_taxa || is.character(fill_na_taxa)) {
        M <- as.matrix(tax_table(x))
        if (!taxa_are_rows(x)) {
            M <- t(M)
        }

        if (!is.character(fill_na_taxa)) {
            fill_na_taxa <- "Unknown"
        }

        M[is.na(M)] <- fill_na_taxa

        x@tax_table <- tax_table(M)

    }

    x

}

Try the microbiome package in your browser

Any scripts or data that you put into this service are public.

microbiome documentation built on Nov. 8, 2020, 5:08 p.m.