## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE ) ## ----libraries---------------------------------------------------------------- library(ape) library(phylobar) library(microbiome) ## ----download-data------------------------------------------------------------ data(atlas1006) pseq3 <- atlas1006 |> subset_samples(DNA_extraction_method == "r") |> transform(transform = "compositional") ## ----naive-tree--------------------------------------------------------------- tree <- taxonomy_to_tree(tax_table(pseq3)) checkValidPhylo(tree) ## ----valid-tree--------------------------------------------------------------- taxa <- tax_table(pseq3) taxa <- cbind(Kingdom = "Bacteria", taxa) taxa <- phylobar::add_prefix(taxa) tree <- taxonomy_to_tree(taxa) checkValidPhylo(tree) ## ----phylobar-full------------------------------------------------------------ x <- t(otu_table(pseq3)) phylobar(x, tree, sample_show_all = FALSE, rel_width = 0.2) ## ----phylobar-subset---------------------------------------------------------- x_sub <- subset_cluster(x) x_sub <- x_sub[, colSums(x_sub) > 0] leaves_to_keep <- intersect(tree$tip.label, colnames(x_sub)) filtered_tree <- drop.tip(tree, setdiff(tree$tip.label, leaves_to_keep)) phylobar(x_sub, filtered_tree) ## ----bray-curtis-result------------------------------------------------------- x_sub_bc <- subset_cluster(x, method = "medoid") x_sub_bc <- x_sub[, colSums(x_sub) > 0] leaves_to_keep <- intersect(tree$tip.label, colnames(x_sub_bc)) filtered_tree <- drop.tip(tree, setdiff(tree$tip.label, leaves_to_keep)) phylobar(x_sub_bc, filtered_tree) ## ----session------------------------------------------------------------------ sessionInfo()