### Install phyloseq using BiocManager Source: https://github.com/joey711/phyloseq/blob/master/README.md Installs the phyloseq package using BiocManager. Ensure BiocManager is installed first if necessary. ```R if(!requireNamespace("BiocManager")){ install.packages("BiocManager") } BiocManager::install("phyloseq") ``` -------------------------------- ### Document Setup and Support Detection Source: https://github.com/joey711/phyloseq/blob/master/README.html This section sets up document-specific properties and detects browser support for various features. ```JavaScript c = ga.support = {}, f = ga.isXML = function(a) { var b = a && (a.ownerDocument || a).documentElement; return b ? "HTML" !== b.nodeName : !1 }, m = ga.setDocument = function(a) { var b, e, g = a ? a.ownerDocument || a : v; return g !== n && 9 === g.nodeType && g.documentElement ? (n = g, o = g.documentElement, e = g.defaultView, e && e !== e.top && (e.addEventListener ? e.addEventListener("unload", ea, !1) : e.attachEvent && e.attachEvent("onunload", ea)), p = !f(g), c.attributes = ja(function(a) { return a.className = "i", !a.getAttribute("className") }), c.getElementsByTagName = ja(function(a) { return a.appendChild(g.createComment("")), !a.getElementsByTagName("*").length }), c.getElementsByClassName = $.test(g.getElementsByClassName), c.getById = ja(function(a) { return o.appendChild(a).id = u, !g.getElementsByName || !g.getElementsByName(u).length }), c.getById ? (d.find.ID = function(a, b) { if ("undefined" != typeof b.getElementById && p) { var c = b.getElementById(a); return c && c.parentNode ? [c] : [] } }, d.filter.ID = function(a) { var b = a.replace(ca, da); return function(a) { return a.getAttribute("id") === b } }) : (delete d.find.ID, d.filter.ID = function(a) { var b = a.replace(ca, da); return function(a) { var c = "undefined" != typeof a.getAttributeNode && a.getAttributeNode("id"); return c && c.value === b } }), d.find.TAG ``` -------------------------------- ### Getting Sample Names Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the names of all samples in the phyloseq object. ```r sample_names(physeq) ``` -------------------------------- ### Getting Sample Data as Data Frame Source: https://github.com/joey711/phyloseq/blob/master/README.html Converts the sample_data object into a data frame. ```R sample_df <- as.data.frame(sample_data(physeq_obj)) ``` -------------------------------- ### Getting Sample Data for Specific Variables Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts specific variables (columns) from the sample data. ```R # Get 'Treatment' and 'Sex' variables selected_vars <- get_variable(sample_data(physeq_obj), c("Treatment", "Sex")) ``` -------------------------------- ### Getting Sample Data as SampleData Object Source: https://github.com/joey711/phyloseq/blob/master/README.html Ensures the sample data is returned as a sample_data object. ```R sample_data_strict <- sample_data(physeq_obj, errorIfNULL = TRUE) ``` -------------------------------- ### Getting Sample Data with Missing Values Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data, handling potential missing values. ```R sample_with_na <- sample_data(physeq_obj, na.rm = FALSE) ``` -------------------------------- ### Getting Sample Data Transposed Source: https://github.com/joey711/phyloseq/blob/master/README.html Returns the sample data with metadata variables as rows and samples as columns. ```R sample_transposed <- t(sample_data(physeq_obj)) ``` -------------------------------- ### Getting Sample Data as a Matrix with Column Names Only Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a matrix, preserving only the column (metadata variable) names. ```r sample_matrix_col_names <- as(sample_data(physeq), "matrix") rownames(sample_matrix_col_names) <- NULL ``` -------------------------------- ### Load and Inspect a Phyloseq Object Source: https://github.com/joey711/phyloseq/blob/master/README.html Loads a phyloseq object from a file and displays its structure. Ensure the 'phyloseq' package is installed and loaded. ```R library(phyloseq) # Load the phyloseq object from a file (e.g., .rds) physeq <- readRDS("path/to/your/phyloseq_object.rds") # Print the structure of the object print(physeq) ``` -------------------------------- ### Getting Sample Data as Data Frame Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data from the phyloseq object as a data frame. ```r sample_df <- as.data.frame(sample_data(physeq)) ``` -------------------------------- ### Create a Phyloseq Object from All Components Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, sample data, taxonomy table, and a phylogenetic tree. ```R library(phyloseq) # Assuming 'otu_table_data', 'sample_data_frame', 'tax_table_data', 'phylo_tree' are your data physeq_all <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Setting or Getting HTML Content Source: https://github.com/joey711/phyloseq/blob/master/README.html Use the .html() method to set or get the HTML content of elements. When setting HTML, it can parse strings and append them as DOM nodes. Be cautious with untrusted HTML strings due to potential security risks. ```javascript html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fa,""):void 0;if(!("string"!=typeof a||ma.test(a)||!k.htmlSerialize&&ga.test(a)||!k.leadingWhitespace&&ha.test(a)||ra[(ja.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ia,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ua(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)} ``` -------------------------------- ### Getting Phylogenetic Tree with Missing Tips Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the phylogenetic tree, potentially handling cases where tips might be missing. ```R tree_with_missing_tips <- phy_tree(physeq_with_tree, errorIfNULL = FALSE) ``` -------------------------------- ### Getting Sample Data as a Character Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a character matrix. Useful for inspecting metadata strings. ```r sample_char_matrix <- as(sample_data(physeq), "character") ``` -------------------------------- ### Getting Sample Data for Specific Samples and Variables (Second Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts specific variables from the sample data for a subset of samples using a second method. ```R # Get 'Treatment' for 'Sample1' and 'Sample2' sample_subset_vars_alt <- sample_data(physeq_obj)[c("Sample1", "Sample2"), ]$Treatment ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Tree (No Sample Data) Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and a phylogenetic tree. Sample data is not included. ```R library(phyloseq) # Assuming 'otu_table_data', 'tax_table_data', 'phylo_tree' are your data physeq_no_sample <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Getting Sample Size Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the number of samples in the phyloseq object. ```r nsamples(physeq) ``` -------------------------------- ### Getting Sample Data as a Sparse Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a sparse matrix. Note: This is uncommon as sample data is typically dense. ```r sparse_sample_matrix <- as(sample_data(physeq), "dgCMatrix") ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa and Rooting (Second Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to specific taxa and then roots it using a second method. ```R # Prune tree to 'OTU1', 'OTU2' and root using 'OTU_outgroup' pruned_tree_alt2 <- prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)) rooted_tree_alt2 <- root(pruned_tree_alt2, outgroup = "OTU_outgroup") ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Tree (No Sample Data) Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and a phylogenetic tree. Sample data is not included. ```R library(phyloseq) # Assuming 'otu_table_data', 'tax_table_data', 'phylo_tree' are your data physeq_no_sample_data <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Getting Taxonomy Table as Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Ensures the taxonomy table is returned as a matrix. ```R tax_matrix_strict <- tax_table(physeq_obj, errorIfNULL = TRUE) ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Tree (No Sample Data) Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and a phylogenetic tree. Sample data is not included. ```R library(phyloseq) # Assuming 'otu_table_data', 'tax_table_data', 'phylo_tree' are your data physeq_no_sample_data_final <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Getting Number of Samples Source: https://github.com/joey711/phyloseq/blob/master/README.html Returns the total number of samples in the phyloseq object. ```R num_samples <- nsamples(physeq_obj) ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Tree (No Sample Data) Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and a phylogenetic tree. Sample data is not included. ```R library(phyloseq) # Assuming 'otu_table_data', 'tax_table_data', 'phylo_tree' are your data physeq_no_sample_data_final_again <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Creating a Phyloseq Object with Only OTU Table Source: https://github.com/joey711/phyloseq/blob/master/README.html Constructs a phyloseq object using only an OTU table. This is a minimal starting point. ```R physeq <- otu_table(otu.tab, taxa_are_rows = TRUE) ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa and Rooting (Third Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to specific taxa and then roots it using a third method. ```R # Prune tree to 'OTU1', 'OTU2' and root using 'OTU_outgroup' pruned_tree_alt3 <- prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)) rooted_tree_alt3 <- root(pruned_tree_alt3, outgroup = "OTU_outgroup") ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Sample Data with Tree Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, sample data, and a phylogenetic tree. ```R library(phyloseq) # Assuming 'otu_table_data', 'sample_data_frame', 'tax_table_data', 'phylo_tree' are your data physeq_full_tree <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Getting Taxa Count Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the number of taxa (OTUs/ASVs) in the phyloseq object. ```r ntaxa(physeq) ``` -------------------------------- ### Getting Sample Data for Specific Samples and Variables (Third Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts specific variables from the sample data for a subset of samples using a third method. ```R # Get 'Treatment' for 'Sample1' and 'Sample2' sample_subset_vars_alt2 <- sample_data(physeq_obj)[c("Sample1", "Sample2"), "Treatment", drop = FALSE] ``` -------------------------------- ### Create a Phyloseq Object from OTU and Sample Data with Tree Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU, sample data, and a phylogenetic tree. Taxonomy can be added later. ```R library(phyloseq) # Assuming 'otu_table_data', 'sample_data_frame', 'phylo_tree' are your data physeq_otu_sample_tree <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame), phy_tree(phylo_tree)) ``` -------------------------------- ### jQuery Value Manipulation Source: https://github.com/joey711/phyloseq/blob/master/README.html Handles getting and setting values for form elements. ```javascript var lb=/\r/g;m.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=m.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,m(this).val()):a,null==e?e="":"number"==typeof e?e+="":"number"==typeof e?e+="":m.isArray(e)&&(e=m.map(e,function(a){return null==a?"":a+""})),b=m.valHooks[this.type]||m.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=m.valHooks[e.type]||m.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&v ``` -------------------------------- ### Getting Sample Data as a Matrix with Row and Column Names Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a matrix, preserving row (samples) and column (metadata variable) names. ```r sample_matrix_named <- as(sample_data(physeq), "matrix") ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa and Rooting (Fourth Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to specific taxa and then roots it using a fourth method. ```R # Prune tree to 'OTU1', 'OTU2' and root using 'OTU_outgroup' pruned_tree_alt4 <- prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)) rooted_tree_alt4 <- root(pruned_tree_alt4, outgroup = "OTU_outgroup") ``` -------------------------------- ### Getting Sample Data as a Matrix with Row Names Only Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a matrix, preserving only the row (samples) names. ```r sample_matrix_row_names <- as(sample_data(physeq), "matrix") colnames(sample_matrix_row_names) <- NULL ``` -------------------------------- ### Create a Phyloseq Object from Sample Data Only Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with only sample metadata. OTU and taxonomy data can be added later. ```R library(phyloseq) # Assuming 'sample_data_frame' is your sample data physeq_sample_only <- phyloseq(sample_data(sample_data_frame)) ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa and Rooting (Alternative) Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to specific taxa and then roots it using an alternative method. ```R # Prune tree to 'OTU1', 'OTU2' and root using 'OTU_outgroup' pruned_tree_alt <- prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)) rooted_tree_alt <- root(pruned_tree_alt, outgroup = "OTU_outgroup") ``` -------------------------------- ### Getting Phylogenetic Tree Dimensions Source: https://github.com/joey711/phyloseq/blob/master/README.html Returns the number of nodes and tips in the phylogenetic tree. ```R tree_dims <- dim(phy_tree(physeq_with_tree)) ``` -------------------------------- ### Getting Sample Data for Specific Samples and Variables (Fourth Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts specific variables from the sample data for a subset of samples using a fourth method. ```R # Get 'Treatment' for 'Sample1' and 'Sample2' sample_subset_vars_alt3 <- sample_data(physeq_obj)[c("Sample1", "Sample2"), "Treatment", drop = FALSE] ``` -------------------------------- ### Getting Number of Taxa Source: https://github.com/joey711/phyloseq/blob/master/README.html Returns the total number of taxa (OTUs/ASVs) in the phyloseq object. ```R num_taxa <- ntaxa(physeq_obj) ``` -------------------------------- ### Create a Phyloseq Object from OTU and Sample Data Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU and sample data. Taxonomy can be added later. ```R library(phyloseq) # Assuming 'otu_table_data' and 'sample_data_frame' are your data physeq_otu_sample <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame)) ``` -------------------------------- ### Getting Taxonomy Table as a Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the taxonomy table from the phyloseq object as a matrix. ```r tax_matrix <- as(tax_table(physeq), "matrix") ``` -------------------------------- ### Create a Phyloseq Object from OTU, Sample, and Taxonomy Tables Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU, sample, and taxonomy data. A phylogenetic tree can be added subsequently. ```R library(phyloseq) # Assuming 'otu_table_data', 'sample_data_frame', 'tax_table_data' are your data physeq_full <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame), tax_table(tax_table_data)) ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Sample Data (No Tree) Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and sample data. A phylogenetic tree is not included. ```R library(phyloseq) # Assuming 'otu_table_data', 'sample_data_frame', 'tax_table_data' are your data physeq_no_tree <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), sample_data(sample_data_frame), tax_table(tax_table_data)) ``` -------------------------------- ### Getting OTU Table as Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the OTU table from the phyloseq object as a matrix. ```r otu_matrix <- as(otu_table(physeq), "matrix") ``` -------------------------------- ### Getting Sample Data for Specific Samples and Variables (Alternative) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts specific variables from the sample data for a subset of samples using a different method. ```R # Get 'Treatment' for 'Sample1' and 'Sample2' sample_subset_vars <- sample_data(physeq_obj)[c("Sample1", "Sample2"), "Treatment", drop = FALSE] ``` -------------------------------- ### Getting Sample Data as a Numeric Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the sample data as a numeric matrix. Note: This will coerce non-numeric data to numeric, potentially losing information. ```r sample_numeric_matrix <- as(sample_data(physeq), "matrix") ``` -------------------------------- ### Getting OTU Table Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the raw OTU count table from the phyloseq object. ```r otu_table(physeq) ``` -------------------------------- ### Create a Sample Data Object Source: https://github.com/joey711/phyloseq/blob/master/README.html This snippet demonstrates how to create a basic sample data object using phyloseq. It's useful for testing or when you have small, custom datasets. ```R library(phyloseq) # Sample data OTU = otu_table(matrix(sample(1:1000, 100, replace = TRUE), nrow=10, ncol=10), taxa_are_rows = TRUE) SAM = sample_data(data.frame( SampleID = paste("Sample", 1:10, sep="_"), Treatment = factor(rep(c("A", "B"), each = 5)), Sex = factor(rep(c("M", "F"), 5)) )) # Create phyloseq object physeq_obj <- phyloseq(OTU, SAM) print(physeq_obj) ``` -------------------------------- ### Create a Phyloseq Object from OTU and Taxonomy Tables Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU and taxonomy tables. Sample data can be added later. ```R library(phyloseq) # Assuming 'otu_table_data' and 'tax_table_data' are your data physeq_otu_tax <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data)) ``` -------------------------------- ### Getting Taxa Names Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves the names of all taxa (OTUs/ASVs) present in the phyloseq object. ```r taxa_names(physeq) ``` -------------------------------- ### Create a Phyloseq Object from OTU and Phylogenetic Tree Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table and a phylogenetic tree. Sample data and taxonomy can be added later. ```R library(phyloseq) # Assuming 'otu_table_data' and 'phylo_tree' are your data physeq_otu_tree <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), phy_tree(phylo_tree)) ``` -------------------------------- ### Creating a Phyloseq Object with Multiple Components Source: https://github.com/joey711/phyloseq/blob/master/README.html Demonstrates the creation of a phyloseq object by combining various components like OTU table, taxonomy table, sample data, and phylogenetic tree. ```R physeq <- phyloseq(otu_table(otu.tab, taxa_are_rows = TRUE), tax_table(as.matrix(tax.tab)), sample_data(sample.dat), phy_tree(tree.obj)) ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to include only the specified taxa. ```R # Prune tree to include 'OTU1' and 'OTU2' pruned_tree <- prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)) ``` -------------------------------- ### Initialize Modal with JavaScript Source: https://github.com/joey711/phyloseq/blob/master/README.html Use this method to programmatically show or hide a modal. Pass 'show' to display it or 'hide' to close it. Options can be passed as the second argument. ```javascript function b(b,d){return this.each(function(){var e=a(this),f=e.data("bs.modal"),g=a.extend({},c.DEFAULTS,e.data(),{"object"==typeof b&&b});f||e.data("bs.modal",f=new c(this,g)),"string"==typeof b?f[b](d):g.show&&f.show(d)})} ``` -------------------------------- ### Getting Phylogenetic Tree as Adjacency Matrix Source: https://github.com/joey711/phyloseq/blob/master/README.html Converts the phylogenetic tree into an adjacency matrix representation. ```R tree_adj_matrix <- as.adjM(phy_tree(physeq_with_tree)) ``` -------------------------------- ### Create a Phyloseq Object from OTU, Taxonomy, and Tree Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with OTU table, taxonomy table, and a phylogenetic tree. Sample data can be added later. ```R library(phyloseq) # Assuming 'otu_table_data', 'tax_table_data', 'phylo_tree' are your data physeq_otu_tax_tree <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE), tax_table(tax_table_data), phy_tree(phylo_tree)) ``` -------------------------------- ### Getting OTU Table with Specific Samples and Taxa (Alternative) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts the OTU table, filtering for specific samples and taxa using a different syntax. ```R # Get OTU table for 'OTU1' from 'Sample1' and 'Sample2' specific_samples_otus_alt <- otu_table(physeq_obj, taxa_are_rows = TRUE)["OTU1", c("Sample1", "Sample2")] ``` -------------------------------- ### Importing OTU Table and Metadata Source: https://github.com/joey711/phyloseq/blob/master/README.html Load an OTU table and sample metadata from CSV files. Ensure the sample names in the metadata match the column names of the OTU table. ```R library(phyloseq) # Load OTU table otu_table <- read.csv("otu_table.csv", row.names=1) # Load sample metadata sample_metadata <- read.csv("sample_metadata.csv", row.names=1) # Create phyloseq object physeq_obj <- phyloseq(otu_table(otu_table, taxa_are_rows = TRUE), sample_data(sample_metadata)) ``` -------------------------------- ### Getting OTU Table Transposed Source: https://github.com/joey711/phyloseq/blob/master/README.html Returns the OTU table with samples as rows and taxa as columns. ```R otu_transposed <- t(otu_table(physeq_obj)) ``` -------------------------------- ### Getting Taxonomy Table as Data Frame Source: https://github.com/joey711/phyloseq/blob/master/README.html Converts the taxonomy table matrix into a data frame. ```R tax_df <- as.data.frame(tax_table(physeq_obj)) ``` -------------------------------- ### Creating a Phyloseq Object from Scratch Source: https://github.com/joey711/phyloseq/blob/master/README.html Constructs a phyloseq object by providing OTU table, taxonomy table, sample data, and tree directly. ```R physeq_new <- phyloseq( otu_table = otu_table(OTU, taxa_are_rows = TRUE), tax_table = tax_table(TAX), sample_data = sample_data(sample_data), phy_tree = tree_obj ) ``` -------------------------------- ### Getting OTU Table with Specific Samples and Taxa (Third Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts the OTU table, filtering for specific samples and taxa using a third method. ```R # Get OTU table for 'OTU1' from 'Sample1' and 'Sample2' specific_samples_otus_alt2 <- otu_table(physeq_obj, taxa_are_rows = TRUE)[, "Sample1", drop = FALSE] specific_samples_otus_alt2 <- specific_samples_otus_alt2["OTU1", , drop = FALSE] ``` -------------------------------- ### Getting OTU Table with Specific Samples and Taxa (Fourth Method) Source: https://github.com/joey711/phyloseq/blob/master/README.html Extracts the OTU table, filtering for specific samples and taxa using a fourth method. ```R # Get OTU table for 'OTU1' from 'Sample1' and 'Sample2' specific_samples_otus_alt3 <- otu_table(physeq_obj, taxa_are_rows = TRUE)["OTU1", , drop = FALSE] specific_samples_otus_alt3 <- specific_samples_otus_alt3[, c("Sample1", "Sample2")] ``` -------------------------------- ### Create a Phyloseq Object from OTU Table Only Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a phyloseq object with only an OTU table. Sample data and taxonomy can be added later. ```R library(phyloseq) # Assuming 'otu_table_data' is your OTU matrix physeq_otu_only <- phyloseq(otu_table(otu_table_data, taxa_are_rows = TRUE)) ``` -------------------------------- ### Getting Sample Names Source: https://github.com/joey711/phyloseq/blob/master/README.html Retrieves a character vector of all sample names present in the phyloseq object. ```R sample_names <- sample_names(physeq_obj) ``` -------------------------------- ### Getting Phylogenetic Tree for Specific Taxa and Rooting Source: https://github.com/joey711/phyloseq/blob/master/README.html Prunes the phylogenetic tree to specific taxa and then roots it. ```R # Prune tree to 'OTU1', 'OTU2' and root using 'OTU_outgroup' pruned_rooted_tree <- root(prune_taxa(c("OTU1", "OTU2"), phy_tree(physeq_with_tree)), outgroup = "OTU_outgroup") ``` -------------------------------- ### Creating a Phyloseq Object with OTU, Taxonomy, Sample Data, and Tree Source: https://github.com/joey711/phyloseq/blob/master/README.html Constructs a complete phyloseq object including OTU table, taxonomy table, sample data, and a phylogenetic tree. ```R physeq <- phyloseq(otu_table(otu.tab, taxa_are_rows = TRUE), tax_table(as.matrix(tax.tab)), sample_data(sample.dat), phy_tree(tree.obj)) ``` -------------------------------- ### Tooltip Initialization and Placement Source: https://github.com/joey711/phyloseq/blob/master/README.html Initializes a tooltip on an element and handles its placement logic, including auto-adjustment based on viewport boundaries. Ensure the tooltip's template and container options are correctly configured. ```javascript c.prototype.show=function(b){var a=this,c=a.tip(),d=a.getUID(a.type);if(a.isWithContent()&&a.enabled){var e=a.tip();a.fixTitle();e.attr("id",d),a.$element.attr("aria-describedby",d),a.options.animation&&e.addClass("fade");var f="function"==typeof a.options.placement?a.options.placement.call(a,e[0],a.$element[0]):a.options.placement,g=/\s?auto?\s?/i,h=g.test(f);h&&(f=f.replace(g,"")||"top"),e.detach().css({top:0,left:0,display:"block"}).addClass(f).data("bs."+a.type,a),a.options.container?e.appendTo(a.options.container):e.insertAfter(a.$element),a.$element.trigger("inserted.bs."+a.type);var i=a.getPosition(),j=e[0].offsetWidth,k=e[0].offsetHeight;if(h){var l=f,m=a.getPosition(a.$viewport);f="bottom"==f&&i.bottom+k>m.bottom?"top":"top"==f&&i.top-km.width?"left":"left"==f&&i.left-j of your HTML document. ```javascript !function(a,b){function c(a,b){var c=b.createElement("p"),d=b.getElementsByTagName("head")[0]||b.documentElement;return c.innerHTML="">"+a,d.insertBefore(c,d.firstChild),c.firstChild.nodeName.toLowerCase()} ``` ```javascript function d(){var a=f.elements;return"string"==typeof a?a.split(" "):a}function e(a,b,c,d){this.elements=a,this.content=c,this.hidden=d,this.callFn=b} ``` ```javascript e.prototype.render=function(){var a=this.content;if("undefined"==typeof this.hidden)return a;var b=f.createElement(this.elements),c=b.style;return c.behavior="url(#default#VML)",this.hidden==="*"?b.innerHTML=a:b.setAttribute(""+this.hidden,a),b} ``` ```javascript function f(a){var b=a.elements;if(b){if("object"==typeof b)return b;if("string"==typeof b)return b.split(" ")} ``` ```javascript return["abbr","article","aside","audio","bdi","canvas","data","datalist","details","dialog","figcaption","figure","footer","header","hgroup","main","mark","meter","nav","output","picture","progress","section","summary","time","video"]} ``` ```javascript function g(a){var b=f(a),c=b.elements,d=b.shivCSS,e=b.supportsUnknownElements;if(!e){return a.createDocumentFragment()}}function h(a,b){var c=f(a),d=c.elements,e=c.hidden,g=c.shivMethods;if(!g||!d||!d.length)return b.createDocumentFragment();var h=b.createDocumentFragment(),i=h.createElement,j=h.createDocumentFragment;h.createElement=function(){for(var a,b=0,c=d.length;c>b;b++)a=d[b];return i(a)};var k=/\[\w\-:]+/g;return h.createDocumentFragment=function(){var a=j();return h.shivMethods&&k.test(a.lastChild.nodeName)&&(h.frag.createElem(a.lastChild),h.frag.createElem(a.lastChild.nodeName)),a},h} ``` ```javascript function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="\_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document); ```