### Install MicrobiotaProcess from Bioconductor (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/README.md Installs the released version of the MicrobiotaProcess package from Bioconductor. This requires the BiocManager package to be installed first, and it ensures compatibility with the Bioconductor release. Handles potential issues with HTTPS URLs by suggesting HTTP. ```r ## try http:// if https:// URLs are not supported ## the url of mirror if (!requireNamespace("BiocManager", quietly=TRUE)) install.packages("BiocManager") ## BiocManager::install("BiocUpgrade") ## you may need this BiocManager::install("MicrobiotaProcess") ``` -------------------------------- ### Create MPSE Object from Matrices Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Constructs an MPSE object from abundance matrices, sample metadata, phylogenetic trees, and reference sequences. It initializes the MPSE structure with provided data, suitable for starting microbiome analyses. ```r set.seed(123) abundance_matrix <- matrix(abs(round(rnorm(100, sd=4), 0)), nrow=10, ncol=10) rownames(abundance_matrix) <- paste0("OTU", seq_len(10)) colnames(abundance_matrix) <- paste0("Sample", seq_len(10)) sample_metadata <- data.frame( Sample = colnames(abundance_matrix), Group = rep(c("Control", "Treatment"), each=5), Time = rep(c("Early", "Late"), times=5), row.names = colnames(abundance_matrix) ) mpse <- MPSE( assays = list(Abundance = abundance_matrix), colData = sample_metadata ) print(mpse) ``` -------------------------------- ### Install MicrobiotaProcess Development Version from GitHub (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/README.md Installs the development version of the MicrobiotaProcess package directly from GitHub. This method requires the 'remotes' package to be installed. It is useful for accessing the latest features and bug fixes before they are released on Bioconductor. ```r if (!requireNamespace("remotes", quietly=TRUE)) install.packages("remotes") remotes::install_github("YuLab-SMU/MicrobiotaProcess") ``` -------------------------------- ### Get Rare Curve Data (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/NEWS.md This function retrieves rare curve data, designed to avoid repeated calculations when displaying rare curves. It takes an object and chunk size as input and returns the calculated rare curve data. Useful for optimizing rare curve plotting. ```r rareres <- get_rarecurve(obj, chunks=400) p <- ggrarecurve(rareres) ``` -------------------------------- ### Import Data from QIIME2 Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Imports data from QIIME2 artifacts (.qza files) including OTU tables, taxonomy, sample metadata, reference sequences, and phylogenetic trees into an MPSE object. This function facilitates the integration of QIIME2 analysis results into the MicrobiotaProcess workflow. ```r library(MicrobiotaProcess) mpse <- mp_import_qiime2( otuqza = "table.qza", taxaqza = "taxonomy.qza", mapfilename = "sample_metadata.txt", refseqqza = "rep-seqs.qza", treeqza = "rooted-tree.qza" ) mpse ``` -------------------------------- ### Import Data from DADA2 Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Converts DADA2 pipeline output (sequence table and taxonomy table) into an MPSE object. It can also incorporate sample metadata and a reference tree, automatically hashing sequences to create OTU identifiers and storing original sequences. ```r seqtab <- readRDS("seqtab.nochim.rds") taxa <- readRDS("taxa_tab.rds") mpse <- mp_import_dada2( seqtab = seqtab, taxatab = taxa, sampleda = "sample_metadata.txt", reftree = "tree.nwk" ) mpse ``` -------------------------------- ### Taxonomy Table Handling in Diff Analysis (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/NEWS.md Fixes a bug in `diff_analysis.phyloseq` where `tax_table(ps)` could cause an error if the tax table was NULL. It now correctly accesses the taxonomy table using `ps@tax_table` to prevent issues when the table is missing. ```r tax_table(ps) # Old, potentially erroneous ps@tax_table # New, robust access ``` -------------------------------- ### Convert Between Data Formats Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Facilitates conversion between MPSE objects and other common microbiome data formats like phyloseq, BIOM, and TreeSummarizedExperiment. This allows for interoperability with other R packages and data structures. ```r library(phyloseq) data(GlobalPatterns) mpse <- as.MPSE(GlobalPatterns) ps <- as.phyloseq(mpse) biom_file <- "otu_table.biom" mpse <- mp_import_biom(biom_file) library(TreeSummarizedExperiment) mpse <- as.MPSE(tse_object) ``` -------------------------------- ### Differential Analysis Parameters (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/NEWS.md Updates the method for obtaining dynamic arguments in differential analysis. The `call` argument has been replaced by `someparams`, which encapsulates arguments used in other functions. This improves the flexibility and clarity of passing parameters. ```r someparams <- diff_analysis(...) ``` -------------------------------- ### Perform Environmental Fitting with Ordination Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Correlates environmental variables with ordination axes (e.g., PCoA) to understand their influence on community structure. Requires plotting functions for ordination. Input is an MPSE object, an ordination object, and a list of environmental variables. ```r # Fit environmental vectors to ordination envfit_result <- mpse %>% mp_envfit( .ord = pcoa, .env = c(pH, Temperature, Moisture), permutations = 999, action = "add" ) # Plot ordination with environmental vectors p <- mpse %>% mp_plot_ord( .ord = pcoa, .group = Treatment, .envfit = envfit ) + geom_segment( data = envfit_result, aes(x = 0, y = 0, xend = PC1, yend = PC2), arrow = arrow(length = unit(0.3, "cm")) ) p ``` -------------------------------- ### Perform PCA Ordination and Visualization Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Calculates Principal Component Analysis (PCA) on abundance data and visualizes the results. The plot displays samples colored by treatment and shaped by time, showing variance explained by PC axes. ```r # Calculate PCA mpse <- mpse %>% mp_cal_pca( .abundance = RareAbundance, action = "add" ) # Plot PCA results p <- mpse %>% mp_plot_ord( .ord = pca, .group = Treatment, .color = Treatment, .shape = Time, show.sample = TRUE ) p ``` -------------------------------- ### Complete Microbiome Analysis Pipeline in R Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt This R code demonstrates a comprehensive microbiome analysis pipeline using the MicrobiotaProcess package. It chains operations including normalization, filtering, alpha and beta diversity calculations, differential analysis, and visualization. Dependencies include MicrobiotaProcess, ggplot2, and dplyr. The pipeline takes raw MPSE data and produces a differential abundance cladogram visualization. ```r library(MicrobiotaProcess) library(ggplot2) library(dplyr) # Complete analysis pipeline mpse %>% # Normalization mp_rrarefy(raresize = 5000) %>% # Filtering mp_filter_taxa(.abundance = RareAbundance, min.prevalence = 0.1) %>% # Alpha diversity mp_cal_alpha(.abundance = RareAbundance) %>% # Beta diversity mp_cal_dist(.abundance = RareAbundance, distmethod = "bray") %>% mp_cal_pcoa(.abundance = RareAbundance, distmethod = "bray") %>% # Differential analysis mp_diff_analysis( .abundance = RareAbundance, .group = Treatment, first.test.alpha = 0.05, ldascore = 2, action = "add" ) %>% # Visualization mp_plot_diff_cladogram( .group = Treatment, label.size = 2.5, hilight.alpha = 0.3 ) + scale_fill_diff_cladogram(values = c("Control" = "skyblue", "Treatment" = "orange")) ``` -------------------------------- ### Visualize Taxonomic Composition with Barplot Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates stacked barplots to visualize the relative abundance of taxa within samples. It first calculates abundance at a specified taxonomic level (e.g., Genus) and then plots the composition, allowing for filtering of top taxa and relative abundance display. ```r # Calculate relative abundance at genus level mpse <- mpse %>% mp_cal_abundance( .abundance = Abundance, .group = Genus ) %>% mp_aggregate(.abundance = Abundance, .group = Genus, force = TRUE) # Create composition barplot p <- mpse %>% mp_plot_abundance( .abundance = RelRareAbundanceBySample, .group = Sample, taxa.class = Genus, topn = 20, relative = TRUE, keepUnknown = TRUE, keep.empty = FALSE ) + scale_fill_manual(values = rainbow(20)) + labs(x = "Sample", y = "Relative Abundance (%)") p ``` -------------------------------- ### Customized Alpha Diversity Plot with Comparisons Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates a customized alpha diversity plot (e.g., Shannon index) with manual color scaling for groups and a specific title. It also implies automatic Wilcoxon tests between groups if the plot is displayed. ```r p <- mpse %>% mp_plot_alpha( .group = Treatment, .alpha = Shannon, show.legend = TRUE ) + scale_fill_manual(values = c("Control" = "skyblue", "Treatment" = "orange")) + labs(title = "Shannon Diversity by Treatment") p ``` -------------------------------- ### Perform PCoA Ordination and Visualization Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Performs Principal Coordinates Analysis (PCoA) on a calculated distance matrix and visualizes the results. The plot shows samples colored by group with ellipses representing group centroids. ```r # Perform PCoA on distance matrix mpse <- mpse %>% mp_cal_dist(.abundance = RareAbundance, distmethod = "bray") %>% mp_cal_pcoa(.abundance = RareAbundance, distmethod = "bray") # Visualize PCoA p <- mpse %>% mp_plot_ord( .ord = pcoa, .group = Group, .color = Group, .size = 2, show.sample = TRUE, show.legend = TRUE, ellipse = TRUE ) + scale_color_manual(values = c("Control" = "#00A087FF", "Treatment" = "#3C5488FF")) p ``` -------------------------------- ### Visualize Alpha Diversity Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates publication-ready boxplots to visualize and compare alpha diversity metrics between different sample groups. It integrates with ggplot2 for customization and can include multiple diversity indices in the plot. ```r library(ggplot2) p <- mpse %>% mp_plot_alpha( .group = Group, .alpha = c(Shannon, Simpson, Observe) ) p ``` -------------------------------- ### Summarize Phylum Abundance and OTU Count Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt This R code snippet groups data by Phylum to calculate total abundance and the number of distinct OTUs. It then converts the summarized data back into an MPSE object for further processing. Dependencies include dplyr and the MPSE data structure. ```r phylum_summary <- tbl_mpse %>% dplyr::group_by(Phylum) %>% dplyr::summarize( total_abundance = sum(Abundance), n_otus = n_distinct(OTU) ) mpse_filtered <- tbl_filtered %>% as.MPSE() ``` -------------------------------- ### Test Compositional Differences (PERMANOVA, ANOSIM) Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Performs statistical tests such as PERMANOVA (adonis) and ANOSIM to assess significant differences in community composition between groups based on a specified distance metric. ```r # Perform ADONIS (PERMANOVA) test adonis_result <- mpse %>% mp_adonis( .abundance = RareAbundance, .formula = ~ Group + Time, distmethod = "bray", permutations = 999, action = "get" ) print(adonis_result) # Perform ANOSIM test anosim_result <- mpse %>% mp_anosim( .abundance = RareAbundance, .group = Group, distmethod = "bray", permutations = 999 ) print(anosim_result) ``` -------------------------------- ### Visualize Differential Abundance with Radial Tree Plot Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates a radial tree visualization to display differential taxa, incorporating LDA scores and abundance information. It allows customization of tree type, tip labels, and abundance/effect size display. Requires the 'ggnewscale' package version 0.5.0 or higher for advanced color scaling. ```r library(ggplot2) p <- mpse %>% mp_plot_diff_res( .group = Treatment, layout = "radial", tree.type = "taxatree", tiplab.size = 2, offset.abun = 0.04, pwidth.abun = 0.3, offset.effsize = 0.3, pwidth.effsize = 0.5 ) # Customize colors flag <- packageVersion("ggnewscale") >= "0.5.0" new.fill <- ifelse(flag, "fill_ggnewscale_2", "fill_new") p <- p + scale_fill_manual( aesthetics = new.fill, values = c("Control" = "skyblue", "Treatment" = "orange") ) + scale_fill_manual( values = c("Control" = "skyblue", "Treatment" = "orange") ) p ``` -------------------------------- ### Visualize Differential Abundance with Boxplot and Effect Size Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates a dual-panel visualization combining boxplots of abundance distributions and effect sizes (LDA scores) for differential features. It allows filtering of unknown taxa and specification of taxonomic levels for analysis. ```r # Create dual-panel boxplot visualization p <- mpse %>% mp_plot_diff_boxplot( .group = Treatment, .size = 2, taxa.class = c(Genus, OTU), group.abun = FALSE, removeUnknown = TRUE ) # Apply custom colors to both panels p <- p %>% set_diff_boxplot_color( values = c("Control" = "deepskyblue", "Treatment" = "orange"), guide = guide_legend(title = "Treatment Group") ) p ``` -------------------------------- ### Plot Venn Diagram of Microbiome Data Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Generates a Venn diagram to visualize shared and unique operational taxonomic units (OTUs) between different treatment groups. Requires the ggVennDiagram package. Input is an MPSE object and a control object for Venn diagram generation. ```r library(ggVennDiagram) p <- mpse %>% mp_plot_venn( .venn = vennControl_Treatment, show.name = TRUE ) p ``` -------------------------------- ### Perform Hierarchical Clustering Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Performs hierarchical clustering of samples based on community composition using specified distance and clustering methods. It then visualizes the results as a dendrogram, optionally with a heatmap showing top taxa abundances, and colors sample labels by experimental groups. ```r # Calculate distance and perform clustering mpse <- mpse %>% mp_cal_dist(.abundance = RareAbundance, distmethod = "bray") %>% mp_cal_clust( .abundance = RareAbundance, distmethod = "bray", hclustmethod = "average", action = "add" ) # Visualize dendrogram with heatmap p <- mpse %>% mp_plot_clust( .group = Treatment, taxa.class = Genus, topn = 30, showsample = TRUE ) p ``` -------------------------------- ### Visualize Differential Abundance with Cladogram Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Creates a cladogram to highlight differentially abundant taxa, featuring abbreviated labels for clarity. This visualization method is useful for quickly identifying key taxa with significant differences. Custom color scales can be applied. ```r # Generate cladogram visualization p <- mpse %>% mp_plot_diff_cladogram( .group = Treatment, label.size = 2.5, hilight.alpha = 0.3, bg.tree.size = 0.5, bg.point.size = 2, bg.point.stroke = 0.25, layout = "radial" ) # Customize colors p <- p + scale_fill_diff_cladogram( values = c("Control" = "skyblue", "Treatment" = "orange") ) + scale_size_continuous(range = c(1, 4)) p ``` -------------------------------- ### Export MPSE Object to Other Formats Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Converts an MPSE object into other common bioinformatics formats, such as phyloseq objects, data frames, phylogenetic trees (Newick format), and reference sequences (FASTA format). This facilitates integration with other R packages and tools. ```r # Convert to phyloseq ps <- as.phyloseq(mpse) class(ps) # Extract as data.frame for other tools df <- as.data.frame(mpse) head(df) # Extract tree library(treeio) otu_tree <- mp_extract_tree(mpse, type = "otutree") write.tree(otu_tree@phylo, "otu_tree.nwk") # Extract reference sequences library(Biostrings) refseq <- mp_extract_refseq(mpse) writeXStringSet(refseq, "reference_sequences.fasta") ``` -------------------------------- ### Calculate Alpha Diversity Metrics Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Computes various within-sample alpha diversity metrics, including Shannon, Simpson, Chao1, and ACE. It can operate on rarefied or relative abundance data and adds the results as columns to the sample metadata. ```r mpse <- mpse %>% mp_rrarefy() %>% mp_cal_alpha(.abundance = RareAbundance) alpha_df <- mpse %>% mp_extract_sample() head(alpha_df) mpse <- mpse %>% mp_cal_alpha(.abundance = Abundance, force = TRUE) ``` -------------------------------- ### Extract Abundance Matrices at Different Levels Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Retrieves abundance data from an MPSE object at various taxonomic levels. This includes OTU-level abundance and aggregated abundance at higher taxonomic ranks like genus. The output can be a matrix or a nested tibble, useful for downstream analyses. ```r # Extract OTU-level abundance otu_table <- mpse %>% mp_extract_assays(.abundance = RareAbundance) dim(otu_table) # Extract genus-level abundance from taxatree genus_abundance <- mpse %>% mp_extract_abundance(taxa.class = Genus) # Returns nested tibble with sample-wise abundances genus_abundance %>% tidyr::unnest(RelRareAbundanceBySample) ``` -------------------------------- ### Extract Feature Metadata and Taxonomy Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Retrieves operational taxonomic unit (OTU) or amplicon sequence variant (ASV) information, including taxonomy and differential analysis results, from an MPSE object. The output is a data frame suitable for filtering specific taxa or exporting differential abundance results. ```r # Extract feature data feature_data <- mpse %>% mp_extract_feature() head(feature_data) # Filter for specific taxa bacteroides <- feature_data %>% dplyr::filter(Genus == "Bacteroides") # Export differential taxa write.csv( feature_data %>% dplyr::filter(!is.na(Sign_Treatment)), "differential_taxa.csv" ) ``` -------------------------------- ### Perform Differential Abundance Analysis (LEfSe-like) Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Identifies significantly different microbial features between groups using a two-stage testing approach, similar to LEfSe. It involves non-parametric tests and LDA score calculation for feature selection. ```r # Run differential abundance analysis mpse <- mpse %>% mp_rrarefy() %>% mp_diff_analysis( .abundance = RareAbundance, .group = Treatment, first.test.method = "kruskal.test", first.test.alpha = 0.05, p.adjust = "fdr", fc.method = "generalizedFC", second.test.method = "wilcox.test", second.test.alpha = 0.05, ml.method = "lda", ldascore = 2, action = "add" ) # Results added to taxatree or rowData ``` -------------------------------- ### Apply Tidy Operations with dplyr on MPSE Data Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Applies standard dplyr verbs (e.g., filter, select, summarize) to an MPSE object after converting it into a tidy tibble format. This allows for flexible data manipulation and subsetting of sample and feature information. ```r # Convert to tidy format tbl_mpse <- mpse %>% as_tibble() # Filter samples tbl_filtered <- tbl_mpse %>% dplyr::filter(Treatment == "Control") %>% dplyr::filter(Shannon > 3.0) # Select columns tbl_subset <- tbl_mpse %>% dplyr::select(Sample, OTU, Abundance, Phylum, Genus) ``` -------------------------------- ### Extract Sample Metadata from MPSE Object Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Retrieves all sample-related metadata and computed metrics (e.g., alpha diversity) from an MPSE object. The output is a data frame that can be used for further custom analyses, such as calculating mean Shannon diversity per treatment group. ```r # Extract all sample data sample_data <- mpse %>% mp_extract_sample() head(sample_data) # Use in custom analyses library(dplyr) sample_data %>% group_by(Treatment) %>% summarize( mean_shannon = mean(Shannon), sd_shannon = sd(Shannon) ) ``` -------------------------------- ### Calculate Rarefaction Curves Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Calculates and plots rarefaction curves to assess sampling depth adequacy. It computes species richness against sequencing depth and allows for visualization colored by experimental groups, with separate lines for each sample. ```r # Calculate rarefaction curves mpse <- mpse %>% mp_cal_rarecurve( .abundance = Abundance, chunks = 400 ) # Plot rarefaction curves p <- mpse %>% mp_plot_rarecurve( .rarecurve = RareAbundanceRarecurve, .group = Treatment ) + scale_color_manual(values = c("Control" = "#00A087FF", "Treatment" = "#3C5488FF")) p ``` -------------------------------- ### Rarefy Abundance Data Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Normalizes samples to equal sequencing depth using rarefaction. It can rarefy to the minimum sample depth or a specified depth, storing the result in a new 'RareAbundance' assay within the MPSE object. ```r mpse_rarefied <- mpse %>% mp_rrarefy() mpse_rarefied <- mpse %>% mp_rrarefy(raresize = 5000) SummarizedExperiment::assayNames(mpse_rarefied) ``` -------------------------------- ### Calculate and Plot UpSet Plot Data Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Calculates and visualizes complex intersections of features across multiple sample groups using an UpSet plot. This method is more flexible than Venn diagrams for more than three groups. Requires the ggupset package. Input is an MPSE object and control objects for abundance and upset visualization. ```r # Calculate upset data for multiple groups mpse <- mpse %>% mp_cal_upset( .abundance = Abundance, .group = Treatment, action = "add" ) # Plot UpSet visualization library(ggupset) p <- mpse %>% mp_plot_upset( .upset = upsetControl_Treatment ) p ``` -------------------------------- ### Calculate Beta Diversity Distances (Bray-Curtis, Jaccard) Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Computes between-sample dissimilarity matrices using specified distance metrics like Bray-Curtis or Jaccard. The results can be added to the MPSE object or extracted as a distance matrix. ```r # Calculate Bray-Curtis distance mpse <- mpse %>% mp_cal_dist( .abundance = RareAbundance, distmethod = "bray", action = "add" ) # Calculate multiple distance metrics mpse <- mpse %>% mp_cal_dist(.abundance = RareAbundance, distmethod = "bray") %>% mp_cal_dist(.abundance = RareAbundance, distmethod = "jaccard") # Extract distance matrix dist_bray <- mpse %>% mp_extract_dist(distmethod = "bray") as.matrix(dist_bray)[1:5, 1:5] ``` -------------------------------- ### Perform RDA/CCA Constrained Ordination Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Performs Redundancy Analysis (RDA) or Canonical Correspondence Analysis (CCA) to relate microbial community composition to environmental variables. Generates a triplot visualizing samples, features, and environmental vectors. Requires specifying abundance data and a formula for environmental variables. ```r # Perform RDA mpse <- mpse %>% mp_rda_cca( .abundance = RareAbundance, .formula = ~ pH + Temperature + Moisture, method = "rda", action = "add" ) # Plot RDA results p <- mpse %>% mp_plot_ord( .ord = rda, .group = Treatment, show.sample = TRUE, show.envfit = TRUE ) p ``` -------------------------------- ### Visualize Differential Abundance with Manhattan Plot Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Creates a Manhattan plot to visualize differential abundance results, similar to genome-wide association studies. It displays taxa on the x-axis and significance (e.g., FDR) on the y-axis, with coloring and labeling based on taxonomic classifications. ```r # Create manhattan plot of differential results p <- mpse %>% mp_plot_diff_manhattan( .group = Sign_Treatment, .y = fdr, .size = 2, taxa.class = OTU, anno.taxa.class = Phylum, removeUnknown = FALSE ) p ``` -------------------------------- ### Taxonomy Table to Data Frame (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/NEWS.md Adds `tax_table` information to the results of `get_taxadf`. This function is used to retrieve taxonomy data as a data frame, and the update ensures that the full taxonomy table is included in the output, likely for more comprehensive downstream analysis. ```r result <- get_taxadf(obj) # Result now includes tax_table information ``` -------------------------------- ### Calculate Relative Abundance of Taxa Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Converts raw counts to relative abundances (proportions) at either the sample or group level. The results are stored as an assay within the MPSE object and can be extracted. ```r # Calculate relative abundance by sample mpse <- mpse %>% mp_cal_abundance( .abundance = Abundance, relative = TRUE, action = "add" ) # Result stored as RelRareAbundanceBySample assay assayNames(mpse) # Calculate relative abundance by group mpse <- mpse %>% mp_cal_abundance( .abundance = Abundance, .group = Treatment, relative = TRUE ) # Extract abundance for specific taxa abundance_df <- mpse %>% mp_extract_abundance(taxa.class = Genus) ``` -------------------------------- ### Filter Taxa by Prevalence and Abundance Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Removes low-abundance or rare microbial features based on prevalence across samples or minimum abundance thresholds. It also allows filtering for or against specific taxa by name or taxonomic level. ```r # Filter features present in at least 20% of samples # with minimum abundance of 10 mpse_filtered <- mpse %>% mp_filter_taxa( .abundance = Abundance, min.prevalence = 0.2, min.abundance = 10 ) # Filter keeping only specified taxa mpse_filtered <- mpse %>% mp_filter_taxa( .abundance = Abundance, .term = "Genus", .match = c("Bacteroides", "Prevotella", "Faecalibacterium") ) # Remove specific taxa mpse_filtered <- mpse %>% mp_filter_taxa( .abundance = Abundance, .term = "Kingdom", .match = "Archaea", keep = FALSE ) ``` -------------------------------- ### Updating dplyr Functions (R) Source: https://github.com/yulab-smu/microbiotaprocess/blob/master/NEWS.md This snippet reflects changes made to comply with dplyr version 1.0.0. Specifically, it notes the removal of `rename_` and `group_by_` functions, indicating a shift towards non-standard evaluation in dplyr. ```r # Removed: rename_ # Removed: group_by_ ``` -------------------------------- ### Perform Mantel Test for Distance Matrices Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Tests the correlation between two distance matrices, typically between microbial community dissimilarity and environmental dissimilarity. Requires specifying abundance data, environmental variables, and distance methods. Input is an MPSE object. ```r # Test correlation between community and environmental distance mantel_result <- mpse %>% mp_mantel( .abundance = RareAbundance, .env = c(pH, Temperature, Moisture), distmethod = "bray", env.distmethod = "euclidean", permutations = 999, action = "get" ) print(mantel_result) ``` -------------------------------- ### View Differential Taxa and LDA Scores Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Extracts differentially abundant features from a microbial dataset and displays their LDA scores and p-values. It filters out features with missing significance information. ```r diff_taxa <- mpse %>% mp_extract_feature() %>% dplyr::filter(!is.na(Sign_Treatment)) print(diff_taxa) ``` -------------------------------- ### Calculate Venn Diagram Data Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Calculates the overlap between groups to identify shared and unique features. This function is used to generate data required for constructing Venn diagrams, helping to understand feature distribution across different experimental conditions. ```r # Calculate Venn diagram overlap mpse <- mpse %>% mp_cal_venn( .abundance = Abundance, .group = Treatment, action = "add" ) ``` -------------------------------- ### Aggregate Taxa to Higher Taxonomic Levels Source: https://context7.com/yulab-smu/microbiotaprocess/llms.txt Collapses microbial features to higher taxonomic ranks such as genus or phylum. This function can be chained with other operations, like alpha diversity calculation. ```r # Aggregate to genus level mpse_genus <- mpse %>% mp_aggregate( .abundance = Abundance, .group = Genus, force = TRUE ) mpse_genus # Aggregate to phylum level mpse_phylum <- mpse %>% mp_aggregate( .abundance = RareAbundance, .group = Phylum ) # Can be chained with other operations mpse_genus %>% mp_cal_alpha(.abundance = Abundance, force = TRUE) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.