├── .Rbuildignore ├── .Rhistory ├── .github └── workflows │ └── rcmdcheck.yml ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── aggregate_top_taxa2.R ├── data.R ├── dominant_taxa.R ├── extensions.R ├── find_samples_taxa.R ├── format_to_besthit.R ├── get_group_abundances.R ├── get_microbiome_data.R ├── list_microbiome_data.R ├── peak_methods.R ├── percent_classified.R ├── phy_to_ldf.R ├── pkg_checks.R ├── pkg_utils.R ├── plasticity.R ├── plot_abund_prev.R ├── plot_alpha_diversities.R ├── plot_alpha_rcurve.R ├── plot_area.R ├── plot_diversity_stats.R ├── plot_diversity_stats_utils.R ├── plot_listed_taxa.R ├── plot_ordination_utils.R ├── plot_ordiplot_core.R ├── plot_paired_abundances.R ├── plot_read_distribution.R ├── plot_select_taxa.R ├── plot_sphagetti.R ├── plot_taxa_boxplot.R ├── plot_taxa_composition.R ├── plot_taxa_cv.R ├── plot_taxa_heatmap.R ├── prep_tern_otu.R ├── prep_ternary.R ├── print_ps.R ├── simple_heatmap.R ├── sphagetti_utils.R └── taxa_summary.R ├── README.md ├── data ├── hmp2.rda └── zackular2014.rda ├── docs ├── 404.html ├── LICENSE-text.html ├── articles │ ├── index.html │ ├── microbiomeutilities.html │ ├── microbiomeutilities_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ └── figure-html │ │ │ ├── unnamed-chunk-13-1.png │ │ │ ├── unnamed-chunk-15-1.png │ │ │ ├── unnamed-chunk-16-1.png │ │ │ ├── unnamed-chunk-17-1.png │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ ├── unnamed-chunk-21-1.png │ │ │ ├── unnamed-chunk-22-1.png │ │ │ ├── unnamed-chunk-23-1.png │ │ │ ├── unnamed-chunk-24-1.png │ │ │ ├── unnamed-chunk-25-1.png │ │ │ ├── unnamed-chunk-26-1.png │ │ │ ├── unnamed-chunk-27-1.png │ │ │ ├── unnamed-chunk-28-1.png │ │ │ ├── unnamed-chunk-29-1.png │ │ │ ├── unnamed-chunk-7-1.png │ │ │ └── unnamed-chunk-9-1.png │ ├── microbiomeutilities_ts.html │ └── microbiomeutilities_ts_files │ │ ├── accessible-code-block-0.0.1 │ │ └── empty-anchor.js │ │ └── figure-html │ │ ├── unnamed-chunk-2-1.png │ │ ├── unnamed-chunk-3-1.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-5-1.png │ │ └── unnamed-chunk-6-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── Rplot001.png │ ├── abun_summary.html │ ├── add_refseq.html │ ├── aggregate_top_taxa2.html │ ├── dominant_taxa.html │ ├── find_samples_taxa.html │ ├── format_to_besthit.html │ ├── get_group_abundances.html │ ├── get_microbiome_data.html │ ├── get_tibble.html │ ├── hmp2.html │ ├── index.html │ ├── join_otu_tax.html │ ├── list_microbiome_data.html │ ├── make_pairs.html │ ├── peak-methods.html │ ├── percent_classified.html │ ├── phy_to_ldf.html │ ├── plasticity.html │ ├── plot_abund_prev.html │ ├── plot_alpha_diversities-1.png │ ├── plot_alpha_diversities.html │ ├── plot_alpha_rcurve.html │ ├── plot_area.html │ ├── plot_diversity_stats.html │ ├── plot_diversity_with_stats.html │ ├── plot_diversity_without_stats.html │ ├── plot_listed_taxa.html │ ├── plot_ordination_utils.html │ ├── plot_ordiplot_core.html │ ├── plot_paired_abundances.html │ ├── plot_read_distribution-1.png │ ├── plot_read_distribution.html │ ├── plot_select_taxa.html │ ├── plot_spaghetti.html │ ├── plot_taxa_boxplot.html │ ├── plot_taxa_composition.html │ ├── plot_taxa_cv.html │ ├── plot_taxa_heatmap-1.png │ ├── plot_taxa_heatmap.html │ ├── prep_tern_otu.html │ ├── prep_ternary.html │ ├── print_ps.html │ ├── rarefy_util.html │ ├── simple_heatmap-1.png │ ├── simple_heatmap.html │ ├── taxa_distribution-1.png │ ├── taxa_distribution.html │ ├── taxa_pooler_mcola.html │ ├── taxa_summary.html │ ├── theme_biome_utils.html │ └── zackular2014.html └── sitemap.xml ├── inst ├── NEWS ├── extdata │ ├── Mock_report.html │ ├── beta_stats_test.R │ ├── images │ │ ├── Anonymous-work-in-progress.png │ │ ├── Rmarkdown_image.png │ │ ├── boxplot.png │ │ └── heatmap.png │ ├── microbiomeHD_ref.txt │ ├── microbiomeHD_ref.xlsx │ └── theme_mutilties.R ├── extras │ ├── build.sh │ ├── document.R │ ├── firstlib.R │ ├── format_phylo_tax.R │ ├── hmp2.R │ ├── physeq.rds │ ├── plot_alpha_diversities.R │ ├── plot_taxa_boxplot.R │ ├── plot_taxa_composition.R │ ├── taxa_summary.R │ └── tern_eg.png ├── microutility_template.rmd └── rmarkdown │ └── templates │ └── microbiomeanalysisQC │ ├── skeleton │ └── skeleton.Rmd │ └── template.yaml ├── man ├── add_refseq.Rd ├── aggregate_top_taxa2.Rd ├── dominant_taxa.Rd ├── find_samples_taxa.Rd ├── format_to_besthit.Rd ├── get_group_abundances.Rd ├── get_microbiome_data.Rd ├── get_tibble.Rd ├── hmp2.Rd ├── join_otu_tax.Rd ├── list_microbiome_data.Rd ├── make_pairs.Rd ├── peak-methods.Rd ├── percent_classified.Rd ├── phy_to_ldf.Rd ├── plasticity.Rd ├── plot_abund_prev.Rd ├── plot_alpha_diversities.Rd ├── plot_alpha_rcurve.Rd ├── plot_area.Rd ├── plot_diversity_stats.Rd ├── plot_listed_taxa.Rd ├── plot_ordination_utils.Rd ├── plot_ordiplot_core.Rd ├── plot_paired_abundances.Rd ├── plot_read_distribution.Rd ├── plot_select_taxa.Rd ├── plot_spaghetti.Rd ├── plot_taxa_boxplot.Rd ├── plot_taxa_composition.Rd ├── plot_taxa_cv.Rd ├── plot_taxa_heatmap.Rd ├── prep_tern_otu.Rd ├── prep_ternary.Rd ├── print_ps.Rd ├── rarefy_util.Rd ├── simple_heatmap.Rd ├── taxa_distribution.Rd ├── taxa_pooler_mcola.Rd ├── taxa_summary.Rd ├── theme_biome_utils.Rd └── zackular2014.Rd ├── microbiomeutilities-master.Rproj └── vignettes ├── microbiomeutilities.Rmd └── microbiomeutilities_ts.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.Rproj\.user$ 4 | 5 | # Home page 6 | docs 7 | index.html 8 | index.Rmd 9 | .github 10 | ^\.github$ 11 | 12 | 13 | # Extras 14 | inst/extras/* 15 | 16 | R/.RData 17 | R/*~ 18 | 19 | # Travis scripts 20 | README.Rmd 21 | .travis.yml 22 | -------------------------------------------------------------------------------- /.github/workflows/rcmdcheck.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # 6 | # See https://github.com/r-lib/actions/tree/master/examples#readme for 7 | # additional example workflows available for the R community. 8 | 9 | name: R-CMD-check 10 | 11 | on: 12 | push: 13 | branches: 14 | - main 15 | - master 16 | - devel 17 | 18 | jobs: 19 | R-CMD-check: 20 | runs-on: ${{ matrix.config.os }} 21 | 22 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 23 | 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | config: 28 | - {os: windows-latest, r: '4.0'} 29 | - {os: macOS-latest, r: '4.0'} 30 | - {os: ubuntu-18.04, r: '4.0', rspm: "https://demo.rstudiopm.com/all/__linux__/bionic/latest"} 31 | 32 | env: 33 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 34 | RSPM: ${{ matrix.config.rspm }} 35 | GITHUB_PAT: ${{secrets.PAT}} 36 | 37 | steps: 38 | - uses: actions/checkout@v2 39 | 40 | - uses: r-lib/actions/setup-r@master 41 | with: 42 | r-version: ${{ matrix.config.r }} 43 | 44 | - uses: r-lib/actions/setup-pandoc@master 45 | 46 | - name: Install R packages for CI 47 | run: | 48 | install.packages(c('remotes', 'BiocManager')) 49 | remotes::install_github('r-hub/sysreqs') 50 | BiocManager::install(ask = FALSE) 51 | shell: Rscript {0} 52 | 53 | - name: Query dependencies 54 | run: | 55 | saveRDS(remotes::dev_package_deps(dependencies = TRUE, repos = BiocManager::repositories()), "depends.Rds", version = 2) 56 | shell: Rscript {0} 57 | 58 | - name: Cache R packages 59 | if: runner.os != 'Windows' 60 | uses: actions/cache@v1 61 | with: 62 | path: ${{ env.R_LIBS_USER }} 63 | key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }} 64 | restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- 65 | 66 | - name: Install system dependencies 67 | if: runner.os == 'Linux' 68 | env: 69 | RHUB_PLATFORM: linux-x86_64-ubuntu-gcc 70 | # libcurl4 for Rhtslib 71 | run: | 72 | sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") 73 | sudo -s eval "$sysreqs" 74 | sudo apt-get install libcurl4-openssl-dev libglpk-dev 75 | 76 | - name: Install R dependencies 77 | run: | 78 | remotes::install_github("joey711/phyloseq", repos = BiocManager::repositories()) 79 | remotes::install_github("microbiome/microbiome", repos = BiocManager::repositories()) 80 | BiocManager::install(remotes::dev_package_deps(dependencies = TRUE, repos = BiocManager::repositories())$package) 81 | remotes::install_cran(c("rcmdcheck","covr","magick")) 82 | shell: Rscript {0} 83 | 84 | - name: Check 85 | run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error", check_dir = "check") 86 | shell: Rscript {0} 87 | 88 | - name: Test coverage 89 | if: matrix.config.os == 'ubuntu-18.04' && matrix.config.r == '3.6' 90 | run: | 91 | covr::codecov(token = "${{secrets.CODECOV_TOKEN}}") 92 | shell: Rscript {0} 93 | 94 | - name: Upload check results 95 | if: failure() 96 | uses: actions/upload-artifact@master 97 | with: 98 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 99 | path: check 100 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .Rhistory 6 | .Rhistory 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: required 3 | cache: packages 4 | warnings_are_errors: false 5 | r: devel 6 | r_packages: 7 | - devtools 8 | - ade4 9 | - Cairo 10 | - dplyr 11 | - energy 12 | - FD 13 | #- gcookbook 14 | #- GGally 15 | - ggplot2 16 | - ggrepel 17 | - Hmisc 18 | - knitr 19 | - lme4 20 | - maptree 21 | - MASS 22 | - Matrix 23 | - memoise 24 | #- minet 25 | - moments 26 | #- qvalue 27 | - reshape2 28 | - rmarkdown 29 | - robustbase 30 | - rpart 31 | - scales 32 | - survival 33 | - tgp 34 | - tidyr 35 | - vegan 36 | - ggpubr 37 | - tidyverse 38 | - pheatmap 39 | - data.table 40 | #bioc_packages: 41 | r_github_packages: 42 | - cran/RUnit 43 | - joey711/phyloseq 44 | - microbiome/microbiome 45 | #- microsud/microbiomeutilities 46 | - jimhester/covr 47 | 48 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: microbiomeutilities 2 | Type: Package 3 | Title: microbiomeutilities: Utilities for Microbiome Analytics 4 | Version: 1.00.17 5 | Authors@R: 6 | c(person(given = "Sudarshan", "Shetty", role = c("aut", "cre"), 7 | email = "sudarshanshetty9@gmail.com", 8 | comment = c(ORCID = "0000-0001-7280-9915")), 9 | person("Leo", "Lahti", role = c("aut"), 10 | comment = c(ORCID = "0000-0001-5537-637X")) 11 | ) 12 | Maintainer: Sudarshan Shetty 13 | Description: This is a supporting tool for extending the functionality of both phyloseq and microbiome R packages. 14 | License: BSD_2_clause + file LICENSE 15 | Encoding: UTF-8 16 | LazyData: true 17 | Depends: 18 | R (>= 3.6.0), 19 | phyloseq, 20 | microbiome, 21 | ggplot2, 22 | dplyr 23 | Imports: 24 | reshape2, 25 | stats, 26 | tidyr, 27 | utils, 28 | gghalves, 29 | vegan, 30 | ggpubr, 31 | RColorBrewer, 32 | pheatmap, 33 | ggrepel, 34 | tibble, 35 | scales, 36 | Biostrings 37 | Suggests: 38 | BiocGenerics, 39 | patchwork, 40 | data.table, 41 | plyr, 42 | methods, 43 | knitr, 44 | rmarkdown, 45 | ape, 46 | viridis 47 | BugReports: https://github.com/microsud/microbiomeutilities/issues 48 | VignetteBuilder: knitr 49 | RoxygenNote: 7.2.1 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2017-2020 2 | COPYRIGHT HOLDER: Sudarshan Shetty, Leo Lahti 3 | 4 | 5 | 6 | THERE IS NO WARRANTY FOR THE PROGRAM. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 7 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 8 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 9 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 10 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 11 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 12 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 13 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(add_refseq) 4 | export(aggregate_top_taxa2) 5 | export(dominant_taxa) 6 | export(find_samples_taxa) 7 | export(format_to_besthit) 8 | export(get_group_abundances) 9 | export(get_microbiome_data) 10 | export(get_tibble) 11 | export(join_otu_tax) 12 | export(list_microbiome_data) 13 | export(make_pairs) 14 | export(percent_classified) 15 | export(phy_to_ldf) 16 | export(plasticity) 17 | export(plot_abund_prev) 18 | export(plot_alpha_diversities) 19 | export(plot_alpha_rcurve) 20 | export(plot_area) 21 | export(plot_diversity_stats) 22 | export(plot_listed_taxa) 23 | export(plot_ordination_utils) 24 | export(plot_ordiplot_core) 25 | export(plot_paired_abundances) 26 | export(plot_read_distribution) 27 | export(plot_select_taxa) 28 | export(plot_spaghetti) 29 | export(plot_taxa_boxplot) 30 | export(plot_taxa_composition) 31 | export(plot_taxa_cv) 32 | export(plot_taxa_heatmap) 33 | export(prep_ternary) 34 | export(print_ps) 35 | export(simple_heatmap) 36 | export(taxa_distribution) 37 | export(taxa_summary) 38 | export(theme_biome_utils) 39 | exportMethods(peak_abundance) 40 | exportMethods(peak_base) 41 | exportMethods(peak_sample) 42 | exportMethods(peak_taxonomy) 43 | import(dplyr) 44 | import(ggplot2) 45 | import(microbiome) 46 | import(phyloseq) 47 | import(tidyr) 48 | import(utils) 49 | importFrom(Biostrings,DNAStringSet) 50 | importFrom(RColorBrewer,brewer.pal) 51 | importFrom(gghalves,geom_half_violin) 52 | importFrom(ggpubr,facet) 53 | importFrom(ggpubr,ggarrange) 54 | importFrom(ggpubr,ggboxplot) 55 | importFrom(ggpubr,ggstripchart) 56 | importFrom(ggpubr,ggviolin) 57 | importFrom(ggpubr,rotate_x_text) 58 | importFrom(ggpubr,stat_compare_means) 59 | importFrom(ggrepel,geom_text_repel) 60 | importFrom(grDevices,colorRampPalette) 61 | importFrom(graphics,hist) 62 | importFrom(microbiome,abundances) 63 | importFrom(pheatmap,pheatmap) 64 | importFrom(stats,aggregate) 65 | importFrom(stats,cor) 66 | importFrom(stats,median) 67 | importFrom(stats,quantile) 68 | importFrom(stats,sd) 69 | importFrom(tibble,rownames_to_column) 70 | importFrom(tidyr,pivot_longer) 71 | -------------------------------------------------------------------------------- /R/aggregate_top_taxa2.R: -------------------------------------------------------------------------------- 1 | #' @title Aggregate Top Taxa v2 2 | #' @description Summarize phyloseq: combine other than the most abundant taxa. 3 | #' @details Backup from microbiome R pkg. This function is replaced by 4 | #' aggregate_rare function. 5 | #' @param x \code{\link{phyloseq-class}} object 6 | #' @param top Keep the top-n taxa, and merge the rest under the category 7 | #' 'Other'. Instead of top-n numeric this can also be a character vector 8 | #' listing the groups to combine. 9 | #' @param level Summarization level (from \code{rank_names(pseq)}) 10 | #' @return \code{\link{phyloseq-class}} object 11 | #' @examples 12 | #' data(dietswap) 13 | #' s <- aggregate_top_taxa2(dietswap, top = 3, "Phylum") 14 | #' @export 15 | #' @references See citation('microbiome') 16 | #' @author Contact: Leo Lahti \email{microbiome-admin@@googlegroups.com} 17 | #' @keywords utilities 18 | aggregate_top_taxa2 <- function(x, top, level) { 19 | x <- aggregate_taxa(x, level) 20 | 21 | tops <- top_taxa(x, top) 22 | tax <- tax_table(x) 23 | 24 | inds <- which(!rownames(tax) %in% tops) 25 | 26 | tax[inds, level] <- "Other" 27 | 28 | tax_table(x) <- tax 29 | 30 | tt <- tax_table(x)[, level] 31 | tax_table(x) <- tax_table(tt) 32 | 33 | aggregate_taxa(x, level) 34 | } 35 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Test data 2 | #' 3 | #' Data from a Zackular, Joseph P., et al. "The gut microbiome modulates colon tumorigenesis." MBio 4.6 (2013): e00692 4 | #' -13. 5 | #' 6 | #' @docType data 7 | #' 8 | #' @usage data("zackular2014") 9 | #' 10 | #' @format An object of class \code{"phyloseq"}. 11 | #' 12 | #' @keywords datasets 13 | #' @references 14 | #' \itemize{ 15 | #' \item{}{Zackular, Joseph P., et al. "The gut microbiome modulates colon 16 | #' tumorigenesis." MBio 4.6 (2013): e00692-13., 17 | #' \url{https://mbio.asm.org/content/4/6/e00692-13.short}} 18 | #' } 19 | #' @examples 20 | #' \dontrun{ 21 | #' library(microbiomeutilities) 22 | #' data("zackular2014") 23 | #' pseq <- zackular2014 24 | #' print(zackular2014) 25 | #' } 26 | #' 27 | "zackular2014" 28 | 29 | #' Test data 2 30 | #' 31 | #' Data from a Stansfield J, Dozmorov M. "16s rRNA sequencing data 32 | #' from the Human Microbiome Project 2". Randomly choosen 13 particpants 33 | #' with multiple timepoints for rectum samples. 34 | #' 35 | #' @docType data 36 | #' 37 | #' @usage data("hmp2") 38 | #' 39 | #' @format An object of class \code{"phyloseq"}. 40 | #' 41 | #' @keywords datasets 42 | #' @references 43 | #' \itemize{ 44 | #' \item{}{Stansfield J, Dozmorov M (2019). HMP2Data: 16s rRNA sequencing data 45 | #' from the Human Microbiome Project 2. R package version 1.1.0, 46 | #' \url{ https://bioconductor.org/packages/HMP2Data/}} 47 | #' } 48 | #' @examples 49 | #' \dontrun{ 50 | #' library(microbiomeutilities) 51 | #' data("hmp2") 52 | #' pseq <- hmp2 53 | #' print(hmp2) 54 | #' } 55 | #' 56 | "hmp2" 57 | 58 | -------------------------------------------------------------------------------- /R/dominant_taxa.R: -------------------------------------------------------------------------------- 1 | #' @title Dominant Taxa 2 | #' @description Identify dominant taxa in each sample and give overview. 3 | #' @details Identifies the dominant taxa in each sample and gives an overview of frequency 4 | #' and percent sample that are dominated by each taxon. Can be group wise or overall. 5 | #' @param x \code{\link{phyloseq-class}} object 6 | #' @param level Taxonomic level uses microbiome::aggregate_taxa 7 | #' @param group Provide overview by groups. Default=NULL 8 | #' @return A list of two data frames/tibbles 9 | #' @examples 10 | #' library(microbiomeutilities) 11 | #' library(dplyr) 12 | #' data("zackular2014") 13 | #' p0 <- zackular2014 14 | #' x.d <- dominant_taxa(p0, level = "Genus", group = "DiseaseState") 15 | #' head(x.d$dominant_overview) 16 | #' @export 17 | #' @keywords utilities 18 | dominant_taxa <- function(x, level = NULL, group = NULL) { 19 | 20 | sams <- taxs <- out_dat <- meta_dat <- sample_id <- dominant_taxa <- NULL 21 | 22 | rel.freq <- rel.freq.pct <- NULL 23 | 24 | if (!is(x, "phyloseq")) { 25 | stop("Input is not an object of phyloseq class") 26 | } 27 | if (!is.null(level)) { 28 | x <- aggregate_taxa(x, level = level) 29 | } 30 | sams <- apply(abundances(x), 2, which.max) 31 | taxs <- taxa(x)[apply(abundances(x), 2, which.max)] 32 | out_dat <- data.frame( 33 | sample_id = names(sams), 34 | dominant_taxa = taxs 35 | ) 36 | 37 | meta_dat <- get_tibble(x, 38 | slot="sam_data", 39 | column_id="sample_id") 40 | #meta_dat <- meta(x) 41 | #meta_dat$sample_id <- rownames(meta_dat) 42 | meta_dat <- meta_dat %>% 43 | left_join(out_dat, by="sample_id") 44 | 45 | if (is.null(group)) { 46 | df <- meta_dat %>% 47 | group_by(dominant_taxa) %>% 48 | tally() %>% 49 | mutate( 50 | rel.freq = round(100 * n / sum(n), 1), 51 | rel.freq.pct = paste0(round(100 * n / sum(n), 0), "%") 52 | ) %>% 53 | arrange(desc(n)) 54 | } else { 55 | 56 | .check.group(x, group) 57 | group <- sym(group) 58 | # dominant_taxa <-"dominant_taxa" 59 | df <- meta_dat %>% 60 | group_by(!!group, dominant_taxa) %>% 61 | tally() %>% 62 | mutate( 63 | rel.freq = round(100 * n / sum(n), 1), 64 | rel.freq.pct = paste0(round(100 * n / sum(n), 0), "%") 65 | ) %>% 66 | arrange(desc(n)) 67 | } 68 | 69 | return(list(dominant_overview = df, all_data = meta_dat)) 70 | 71 | } 72 | 73 | 74 | -------------------------------------------------------------------------------- /R/extensions.R: -------------------------------------------------------------------------------- 1 | #' @title Convert Phyloseq Slots to Tibbles 2 | #' @description Utility to convert phyloseq slots to tibbles. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param slot Must be one of c("otu_table", "sam_data", "tax_table"). 5 | #' Default= "otu_table" 6 | #' @param column_id Provide name for the column which will hold the rownames of slot. 7 | #' @return A tibble 8 | #' @examples 9 | #' library(microbiomeutilities) 10 | #' data("zackular2014") 11 | #' p0 <- zackular2014 12 | #' otu_tibble <- get_tibble(p0,slot="otu_table",column_id="OTUID") 13 | #' head(otu_tibble) 14 | #' @export 15 | #' @keywords utilities 16 | 17 | get_tibble <- function(x, 18 | slot="otu_table", 19 | column_id="column_id") { 20 | 21 | if (!is(x, "phyloseq")) { 22 | stop("Input is not an object of phyloseq class") 23 | } 24 | 25 | if(isFALSE(any(slot==getslots.phyloseq(x)))) { 26 | stop("slot must be one of 'otu_table', 'sam_data', 'tax_table'") 27 | } 28 | 29 | if(slot=="otu_table"){ 30 | 31 | tib_dat <- abundances(x) %>% 32 | as.data.frame(stringsAsFactors=FALSE) %>% 33 | rownames_to_column(column_id) %>% 34 | as_tibble() 35 | 36 | return(tib_dat) 37 | 38 | } else if(slot=="sam_data"){ 39 | tib_dat <- meta(x) %>% 40 | as.data.frame(stringsAsFactors=FALSE) %>% 41 | rownames_to_column(column_id) %>% 42 | as_tibble() 43 | 44 | return(tib_dat) 45 | 46 | } else if(slot=="tax_table"){ 47 | tib_dat <- tax_table(x) %>% 48 | as("matrix") %>% 49 | as.data.frame(stringsAsFactors=FALSE) %>% 50 | rownames_to_column(column_id) %>% 51 | as_tibble() 52 | 53 | return(tib_dat) 54 | 55 | } 56 | 57 | 58 | } 59 | 60 | 61 | #' @title Join otu_table and tax_table to Tibble 62 | #' @description Utility to join otu_table and tax_table to tibble. 63 | #' @param x \code{\link{phyloseq-class}} object 64 | #' @param column_id Provide name for the column which will hold the rownames of slot. 65 | #' @return A tibble 66 | #' @examples 67 | #' library(microbiomeutilities) 68 | #' data("zackular2014") 69 | #' p0 <- zackular2014 70 | #' otu_tax <- join_otu_tax(p0,column_id = "OTUID") 71 | #' head(otu_tax) 72 | #' @export 73 | #' @keywords utilities 74 | 75 | join_otu_tax <- function(x, column_id = "OTUID"){ 76 | 77 | otu_tb <- get_tibble(x, slot="otu_table", column_id) 78 | tax_tb <- get_tibble(x, slot="tax_table", column_id) 79 | otu_tb <- tax_tb %>% 80 | left_join(otu_tb, by=column_id) 81 | 82 | } 83 | 84 | 85 | #' @title Add refseq slot for dada2 based phyloseq object 86 | #' @description Utility to add refseq slot for dada2 based phyloseq object. Here, the 87 | #' rownames which are unique sequences, are stored in refseq slot of phyloseq. Sequence 88 | #' ids are converted to ids using tag option. 89 | #' @param x \code{\link{phyloseq-class}} object with seqs as rownames. 90 | #' @param tag Provide name for Ids, Default="ASV". 91 | #' @return \code{\link{phyloseq-class}} object 92 | #' @examples 93 | #' 94 | #' # ps <- add_refseq(p0,tag="ASV") 95 | #' # ps 96 | #' 97 | #' @export 98 | #' @keywords utilities 99 | #' @importFrom Biostrings DNAStringSet 100 | add_refseq <- function(x, tag="ASV"){ 101 | 102 | if (!is(x, "phyloseq")) { 103 | stop("Input is not an object of phyloseq class") 104 | } 105 | 106 | nucl <- Biostrings::DNAStringSet(taxa_names(x)) 107 | names(nucl) <- taxa_names(x) 108 | x <- merge_phyloseq(x, nucl) 109 | 110 | rm(nucl) 111 | 112 | if(is.na(tag) || is.null(tag)){ 113 | taxa_names(x) <- paste0("taxa", seq(ntaxa(x))) 114 | return(x) 115 | } else{ 116 | taxa_names(x) <- paste0(tag, seq(ntaxa(x))) 117 | return(x) 118 | } 119 | 120 | } 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /R/find_samples_taxa.R: -------------------------------------------------------------------------------- 1 | #' @title Find samples dominated by specific taxa 2 | #' @description Finding the samples dominated by user provided taxa in a phyloseq object. 3 | #' This is useful especially if user suspects a taxa to be contaminant and wishes to identify 4 | #' which samples are dominated by the contaminant taxa. 5 | #' @param x \code{\link{phyloseq-class}} object 6 | #' @param taxa this should match the rownames of otu_table(x) 7 | #' @param relative Logical. If TRUE will transform input to relative abundance. Default=FALSE 8 | #' @return A character with sample ids. 9 | #' @examples 10 | #' library(microbiomeutilities) 11 | #' data("zackular2014") 12 | #' p0 <- zackular2014 13 | #' p0.f <- aggregate_taxa(p0, "Genus") 14 | #' bac_dom <- find_samples_taxa(p0.f, taxa = "g__Bacteroides") 15 | #' # get samples dominated by g__Bacteroides 16 | #' ps.sub <- prune_samples(sample_names(p0.f) %in% bac_dom, p0.f) 17 | #' @export 18 | #' @keywords utilities 19 | #' 20 | find_samples_taxa <- function(x, taxa = NULL, relative = FALSE) { 21 | abund <- y <- NULL 22 | 23 | if (!is(x, "phyloseq")) { 24 | stop("Input is not an object of phyloseq class") 25 | } 26 | 27 | if (is.null(taxa)) { 28 | stop("Please specify name of taxa") 29 | } 30 | 31 | if (relative == TRUE) { 32 | abund <- abundances(x, transform = "compositional") 33 | } 34 | 35 | abund <- abundances(x) 36 | 37 | if (taxa %in% taxa_names(x)) { 38 | y <- apply(abund, 2, function(x) { 39 | order(x, decreasing = TRUE)[1] == grep(taxa, 40 | rownames(abund), 41 | perl = TRUE 42 | ) 43 | }) 44 | 45 | return(colnames(abund[, y])) 46 | } else { 47 | stop(paste0(taxa, " does not match any rownames of otu_table!!!")) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /R/get_group_abundances.R: -------------------------------------------------------------------------------- 1 | #' @title Taxa abundance summary by group 2 | #' @description Taxa abundance summary by group. Useful for description of microbiome. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param level Taxonomic level uses microbiome::aggregate_taxa, if NULL with return OTU/ASVs 5 | #' level stats. 6 | #' @param group Provide overview by groups. Default=NULL and will return values for entire 7 | #' dataset, akin to taxa_summary. 8 | #' @param transform Either "compositional" or "counts". Default= compositional 9 | #' @return A data frames/ grouped tibble 10 | #' @examples 11 | #' \dontrun{ 12 | #' library(microbiomeutilities) 13 | #' data("zackular2014") 14 | #' p0 <- zackular2014 15 | #' get_group_abundances(p0, level = "Phylum", group = "DiseaseState") 16 | #' } 17 | #' @export 18 | #' @keywords utilities 19 | #' 20 | get_group_abundances <- function(x, level, group, transform = "compositional") { 21 | 22 | phy_tab <- mean_abundance <- Abundance <- OTUID <- sd_abundance <- NULL 23 | 24 | 25 | if (!is.null(level)) { 26 | x <- aggregate_taxa(x, level = level) 27 | } 28 | 29 | if (isFALSE(any(transform ==c("compositional", "counts")))){ 30 | stop("transform can be only compositional or counts ") 31 | } else if (transform =="compositional"){ 32 | phy_tab <- phy_to_ldf(x, transform.counts = "compositional") 33 | } else { 34 | phy_tab <- phy_to_ldf(x, transform.counts = NULL) 35 | } 36 | 37 | if(is.null(group)){ 38 | message("No group specified, return values for entire data") 39 | phy_tab <- phy_tab %>% 40 | group_by(OTUID) %>% 41 | summarise( 42 | mean_abundance = mean(Abundance, na.rm = T), 43 | sd_abundance = sd(Abundance, na.rm = T) 44 | ) 45 | return(phy_tab) 46 | } else { 47 | group2 <- sym(group) 48 | phy_tab <- phy_tab %>% 49 | group_by(!!group2, OTUID) %>% 50 | summarise( 51 | mean_abundance = mean(Abundance, na.rm = T), 52 | sd_abundance = sd(Abundance, na.rm = T) 53 | ) 54 | return(phy_tab) 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /R/get_microbiome_data.R: -------------------------------------------------------------------------------- 1 | #' @title Download test microbiome data 2 | #' @description Test microbiome data in phyloseq format. 3 | #' @details You can download few example datasets in phyloseq format from Duvallet et al 2017 https://www.nature.com/articles/s41467-017-01973-8.pdf?origin=ppub. The source file for these data is the microbiomedatarepo https://github.com/microsud/microbiomedatarepo. 4 | #' @param disease Disease of interest as shown in list_microbiome_data() 5 | #' @param study Name of the study as shown in list_microbiome_data() 6 | #' @return \code{\link{phyloseq-class}} object. 7 | #' @import microbiome 8 | #' @import phyloseq 9 | #' @export 10 | #' @examples 11 | #' \dontrun{ 12 | #' # Example data 13 | #' library(microbiome) 14 | #' library(microbiomeUtilities) 15 | #' list_microbiome_data() 16 | #' ps1 <- get_microbiome_data(disease = "CDI", "Schubert2014_CDI") 17 | #' print_ps(ps1) 18 | #' } 19 | #' @keywords utilities 20 | get_microbiome_data <- function(disease, study) { 21 | if (grepl(disease, study) == FALSE) { 22 | stop("Disease-Study combination does not exists, check list_microbiome()") 23 | } 24 | 25 | fileloc <- 26 | paste0( 27 | "https://github.com/microsud/microbiomedatarepo/blob/master/datasets/microbiomeDB/", 28 | disease, 29 | "/", 30 | study, 31 | ".rds?raw=true" 32 | ) 33 | 34 | psX <- readRDS(url(fileloc)) 35 | 36 | return(psX) 37 | } 38 | -------------------------------------------------------------------------------- /R/list_microbiome_data.R: -------------------------------------------------------------------------------- 1 | #' @title List of available datasets 2 | #' @description Data are used from Duvallet et al 2017 https://www.nature.com/articles/s41467-017-01973-8.pdf?origin=ppub. 3 | #' @details Data for practice, also an example for importing mothur files from Baxtrer et al 2016. The source file for these data is the microbiomedatarepo https://github.com/microsud/microbiomedatarepo. 4 | #' @param printtab Print in console or not, defaut is TRUE and will print output. 5 | #' @export 6 | #' @examples 7 | #' \dontrun{ 8 | #' library(microbiomeutilities) 9 | #' 10 | #' df <- list_microbiome_data(printtab = FALSE) 11 | #' } 12 | #' 13 | #' @keywords utilities 14 | #' 15 | 16 | list_microbiome_data <- function(printtab = TRUE) { 17 | 18 | # TODO add all the dataset from Duvallet et al 201 as phyloseq objects 19 | Study <- 20 | c( 21 | "Son2015_ASD", 22 | "Kang2013_ASD", 23 | "Schubert2014_CDI", 24 | "Youngster2014_CDI", 25 | "Baxter2016_CRC", 26 | "Zackular2014_CRC", 27 | "Zeller2014_CRC", 28 | "Singh2015_EDD", 29 | "NogueraJulian2016_HIV", 30 | "Dinh2015_HIV", 31 | "Lozupone2013_HIV", 32 | "Gevers2014_IBD", 33 | "Zhang2013_LIV", 34 | "Wong2013_NASH", 35 | "Ross2015_OB", 36 | "Zupancic2012_OB", 37 | "Scher2013_PAR", 38 | "Alkanani2015_T1D", 39 | "Scheperjans2015_PAR", 40 | "Alkanani2015_T1D" 41 | ) 42 | 43 | Disease <- 44 | c( 45 | "ASD", 46 | "ASD", 47 | "CDI", 48 | "CDI", 49 | "CRC", 50 | "CRC", 51 | "CRC", 52 | "EDD", 53 | "HIV", 54 | "HIV", 55 | "HIV", 56 | "IBD", 57 | "LIV", 58 | "NASH", 59 | "OB", 60 | "OB", 61 | "PAR", 62 | "T1D", 63 | "PAR", 64 | "T1D" 65 | ) 66 | 67 | microbiomeDB_pseq <- as.data.frame(cbind(Study, Disease)) 68 | if (printtab == TRUE) { 69 | print(microbiomeDB_pseq) 70 | } else { 71 | return(microbiomeDB_pseq) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /R/peak_methods.R: -------------------------------------------------------------------------------- 1 | #' @name peak-methods 2 | #' 3 | #' @title Peak into \code{\link[phyloseq]{phyloseq}} objects 4 | #' 5 | #' @description 6 | #' These functions work on \code{otu_table}, \code{tax_table}, \code{sample_data} 7 | #' or on \code{data.frame} and \code{matrix}. 8 | #' 9 | #' \code{peak_abundance} returns, user specified number of rows and columns 10 | #' for \code{otu_table}. 11 | #' 12 | #' #' \code{peak_taxonomy} returns, user specified number of rows and columns 13 | #' for \code{tax_table}. 14 | #' 15 | #' \code{peak_sample} returns, user specified number of rows and columns 16 | #' for \code{sample_data}. 17 | #' 18 | #' \code{peak_base} returns, user specified number of rows and columns 19 | #' for \code{data.frame} and \code{matrix}. 20 | #' 21 | #' @param x a 22 | #' \code{\link[phyloseq]{phyloseq}} or \code{data.frame} or 23 | #' \code{matrix} object 24 | #' 25 | #' @param nrows number of rows, to be specified as numeric e.g. 1, or sequence 26 | #' of numeric specified as 1:5. to return first to fifth row. 27 | #' 28 | #' @param ncols number of cols, to be specified as numeric e.g. 1, or sequence 29 | #' of numeric specified as 1:5 to return first to fifth col. 30 | #' 31 | #' @return Print user specified rows and columns 32 | #' 33 | #' @examples 34 | #' data("zackular2014") 35 | #' 36 | #' peak_abundance(zackular2014, nrows=1:3, ncols = 1:3) 37 | #' 38 | #' peak_taxonomy(zackular2014, nrows=1:3, ncols = 1:3) 39 | #' 40 | #' peak_sample(zackular2014, nrows=1:3, ncols = 1:3) 41 | #' 42 | #' dat.frm <- meta(zackular2014) 43 | #' # specify specific columns 44 | #' peak_base(dat.frm, nrows=1:3, ncols = c(1, 3, 4)) 45 | #' 46 | #' matrix_ab <- abundances(zackular2014) 47 | #' peak_base(matrix_ab, nrows=1:3, ncols = 1:3) 48 | #' 49 | NULL 50 | 51 | #' @rdname peak-methods 52 | setGeneric("peak_abundance", signature = c("x"), 53 | function(x, 54 | nrows=1:5, 55 | ncols=1:5) 56 | standardGeneric("peak_abundance")) 57 | 58 | 59 | #' @rdname peak-methods 60 | setGeneric("peak_taxonomy", signature = c("x"), 61 | function(x, 62 | nrows=1:5, 63 | ncols=1:5) 64 | standardGeneric("peak_taxonomy")) 65 | 66 | #' @rdname peak-methods 67 | setGeneric("peak_sample", signature = c("x"), 68 | function(x, 69 | nrows=1:5, 70 | ncols=1:5) 71 | standardGeneric("peak_sample")) 72 | 73 | #' @rdname peak-methods 74 | setGeneric("peak_base", signature = c("x"), 75 | function(x, 76 | nrows=1:5, 77 | ncols=1:5) 78 | standardGeneric("peak_base")) 79 | 80 | 81 | #' @rdname peak-methods 82 | #' @aliases peak_abundance 83 | #' 84 | #' @export 85 | setMethod("peak_abundance", signature = c(x = "phyloseq"), 86 | function(x, 87 | nrows=1:5, 88 | ncols=1:5){ 89 | 90 | if(!.check_pseq(x)){ 91 | stop("input must be a phyloseq object for peak_abundance.", 92 | call. = FALSE) 93 | #abundances(x)[nrows,ncols] 94 | } 95 | 96 | abundances(x)[nrows,ncols] 97 | 98 | } 99 | ) 100 | 101 | 102 | #' @rdname peak-methods 103 | #' @aliases peak_taxonomy 104 | #' 105 | #' @export 106 | setMethod("peak_taxonomy", signature = c(x = "phyloseq"), 107 | function(x, 108 | nrows=1:5, 109 | ncols=1:5){ 110 | 111 | if(!.check_pseq(x)){ 112 | stop("input must be a phyloseq object for peak_taxonomy", 113 | call. = FALSE) 114 | #abundances(x)[nrows,ncols] 115 | } 116 | 117 | tax_table(x)[nrows,ncols] 118 | 119 | } 120 | ) 121 | 122 | 123 | #' @rdname peak-methods 124 | #' @aliases peak_sample 125 | #' 126 | #' @export 127 | setMethod("peak_sample", signature = c(x = "phyloseq"), 128 | function(x, 129 | nrows=1:5, 130 | ncols=1:5){ 131 | 132 | if(!.check_pseq(x)){ 133 | stop("input must be a phyloseq object for peak_sample", 134 | call. = FALSE) 135 | #abundances(x)[nrows,ncols] 136 | } 137 | 138 | meta(x)[nrows,ncols] 139 | 140 | } 141 | ) 142 | 143 | 144 | #' @rdname peak-methods 145 | #' @aliases peak_base 146 | #' 147 | #' @export 148 | setMethod("peak_base", signature = c(x = "ANY"), 149 | function(x, 150 | nrows=1:5, 151 | ncols=1:5){ 152 | 153 | if(!is.data.frame(x) & !is.matrix(x) ){ 154 | 155 | stop("input for peak_base must be data.frame or matrix", 156 | call. = FALSE) 157 | 158 | } 159 | 160 | x[nrows,ncols] 161 | 162 | } 163 | ) 164 | 165 | 166 | #' @param x object to test 167 | #' @noRd 168 | .check_pseq <- function (x) { 169 | length(x) == 1 && is(x) == "phyloseq" 170 | } 171 | -------------------------------------------------------------------------------- /R/phy_to_ldf.R: -------------------------------------------------------------------------------- 1 | #' @title Convert \code{\link{phyloseq-class}} object to long data format 2 | #' @description An alternative to psmelt function from \code{\link{phyloseq-class}} object. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param transform.counts Data transform to be used in plotting 5 | #' (but not in sample/taxon ordering). The options are 'Z-OTU', 'Z-Sample', 6 | #' 'log10' and 'compositional'. See the \code{\link{transform}} function 7 | #' @return A data frame in long format with appropriate transfomation if requested 8 | #' @import tidyr 9 | #' @import dplyr 10 | #' @importFrom tibble rownames_to_column 11 | #' @import microbiome 12 | #' @export 13 | #' @examples 14 | #' \dontrun{ 15 | #' # Example data 16 | #' library(microbiomeutilities) 17 | #' data("zackular2014") 18 | #' pseq <- zackular2014 19 | #' pseq_df <- phy_to_ldf(pseq, transform.counts = NULL) 20 | #' } 21 | #' @keywords utilities 22 | phy_to_ldf <- function(x, transform.counts) { 23 | 24 | if (!is(x, "phyloseq")) { 25 | stop("Input is not an object of phyloseq class") 26 | } 27 | 28 | if (is.null(transform.counts)) { 29 | x <- x 30 | } else if (transform.counts == "log10") { 31 | x <- microbiome::transform(x, "log10") 32 | } else if (transform.counts == "Z-OTU") { 33 | x <- microbiome::transform(x, "Z", "OTU") 34 | } else if (transform.counts == "Z-Sample") { 35 | x <- microbiome::transform(x, "Z", "Sample") 36 | } else if (transform.counts == "compositional") { 37 | x <- microbiome::transform(x, "compositional", "OTU") 38 | } else { 39 | stop("Please provide appropriate transformation") 40 | } 41 | 42 | message("An additonal column Sam_rep with sample names is created for reference purpose") 43 | meta_df <- get_tibble(x, 44 | slot = "sam_data", 45 | column_id = "Sam_rep") 46 | #meta_df <- microbiome::meta(x) 47 | #meta_df$Sam_rep <- rownames(meta_df) 48 | # tax_df <- data.frame(tax_table(x)) %>% 49 | # rownames_to_column("OTUID") 50 | tax_df <- get_tibble(x, 51 | slot = "tax_table", 52 | column_id = "OTUID") 53 | #<- tax_table(x) %>% 54 | # as("matrix") %>% 55 | #as.data.frame() %>% 56 | #rownames_to_column("OTUID") 57 | 58 | otu_df <- data.frame(abundances(x), 59 | check.names = FALSE 60 | ) %>% rownames_to_column("OTUID") 61 | suppressWarnings(suppressMessages(otu_df %>% 62 | left_join(tax_df) %>% 63 | gather_( 64 | "Sam_rep", 65 | "Abundance", setdiff( 66 | colnames(otu_df), 67 | "OTUID" 68 | ) 69 | ) %>% 70 | left_join(meta_df))) 71 | } 72 | -------------------------------------------------------------------------------- /R/pkg_checks.R: -------------------------------------------------------------------------------- 1 | 2 | # Check group variable 3 | .check.group <- function(x, group) { 4 | 5 | if(isFALSE(any(group %in% sample_variables(x)))){ 6 | stop("'group' variable must be in sample_variables(x)") 7 | } 8 | 9 | } 10 | 11 | -------------------------------------------------------------------------------- /R/plasticity.R: -------------------------------------------------------------------------------- 1 | #' @title Plasticity 2 | #' @description Calculated difference in microbiota composition for each individual between 3 | #' two timepoints. 4 | #' @details Using a beta diversity metrics or correlation matrix to identify variability in 5 | #' microbiota of an individual. The code is slight modification from Grembi et. al. see ref below. 6 | #' This is useful for instance if one wants to quantiify changes in microbiota before and after 7 | #' a treatment, dietary modulation, antibiotic treatment, etc. The choice of index is important. 8 | #' For example, Bray-Curtis dissimilarity, the higher values mean higher plasticity/variability. 9 | #' On the contrary, higer spearman correlation values mean lower plasticity. 10 | #' @param x \code{\link{phyloseq-class}} object 11 | #' @param dist.method Any of the methods supported by phyloseq::distance or correlation method cor() 12 | #' @param participant.col Column name with participant IDs 13 | #' @importFrom stats cor 14 | #' @return plot 15 | #' @examples 16 | #' \dontrun{ 17 | #' library(microbiome) 18 | #' library(microbiomeutilities) 19 | #' library(dplyr) 20 | #' library(ggpubr) 21 | #' data(peerj32) 22 | #' pseq <- peerj32$phyloseq 23 | #' pseq.rel <- microbiome::transform(pseq, "compositional") 24 | #' pl <- plasticity(pseq.rel, participant.col = "subject") 25 | #' } 26 | #' @references 27 | #' \itemize{ 28 | #' \item{}{Grembi, J.A., Nguyen, L.H., Haggerty, T.D. et al. Gut microbiota plasticity is 29 | #' correlated with sustained weight loss on a low-carb or low-fat dietary intervention. 30 | #' Sci Rep 10, 1405 (2020).https://www.nature.com/articles/s41598-020-58000-y 31 | #' } 32 | #' } 33 | #' @export 34 | plasticity <- function(x, dist.method = "bray", participant.col) { 35 | mdata <- subject <- sampleids <- x1 <- abund_tab <- matrix_dist <- stab_tab <- NULL 36 | subject_2 <- subject_1 <- stability <- plasticity.value <- S1 <- S2 <- NULL 37 | 38 | if (!is(x, "phyloseq")) { 39 | stop("Input is not an object of phyloseq class") 40 | } 41 | 42 | mdata <- meta(x) 43 | mdata$subject <- as.factor(mdata[, participant.col]) 44 | mdata$sampleids <- rownames(mdata) 45 | 46 | 47 | mdata <- mdata %>% 48 | data.frame() %>% 49 | mutate_at( 50 | .funs = as.character, 51 | .vars = c(sampleids, subject) 52 | ) 53 | 54 | x1 <- prune_taxa(taxa_sums(x) > 0, x) 55 | # dist.method = "pearson" 56 | # x1 <- pseq.rel 57 | if (dist.method %in% c("pearson", "kendall", "spearman")) { 58 | abund_tab <- abundances(x1) 59 | matrix_dist <- cor(abund_tab, abund_tab, method = dist.method, use = "na.or.complete") 60 | } else { 61 | matrix_dist <- phyloseq::distance(x1, dist.method) 62 | } 63 | 64 | stab_tab <- reshape2::melt( 65 | as.matrix(matrix_dist), 66 | varnames = c("S1", "S2"), 67 | value.name = dist.method 68 | ) %>% 69 | mutate_if(is.factor, as.character) %>% 70 | left_join(mdata, by = c("S1" = "sampleids")) %>% 71 | left_join(mdata, by = c("S2" = "sampleids"), suffix = c("_1", "_2")) %>% 72 | filter(S1 != S2) %>% 73 | filter(subject_1 == subject_2) %>% 74 | mutate(subject = subject_1) %>% 75 | dplyr::select(-subject_1, -subject_2) %>% 76 | distinct(subject, .keep_all = TRUE) 77 | return(stab_tab) 78 | } 79 | -------------------------------------------------------------------------------- /R/plot_alpha_diversities.R: -------------------------------------------------------------------------------- 1 | #' @title Creat a plot for alpha diversities calculated using the \code{\link{microbiome}} package 2 | #' @description Utility plot function for diversity measures calcualted by \code{\link{microbiome}} package. 3 | #' @details Uses the \code{\link{microbiome}} package global function to calculate diversities and then returns 4 | #' a plot. 5 | #' @param x \code{\link{phyloseq-class}} object. 6 | #' @param type Either alpha (Diversity Index) or dominance (Dominance Index) or evenness (Evenness Index) 7 | #' @param index.val see global function in \code{\link{microbiome}} package 8 | #' @param variableA Variable of interested to be checked. This will also be used to color the plot 9 | #' @param palette Any of the \code{\link{RColorBrewer}} plettes 10 | #' @param plot.type Three optons c("stripchart", "boxplot", "violin") 11 | #' @return \code{\link{ggplot}} object. This can be further modified using ggpubr 12 | #' @importFrom ggpubr ggstripchart ggboxplot ggviolin facet 13 | #' @export 14 | #' @examples 15 | #' library(microbiome) 16 | #' library(microbiomeutilities) 17 | #' data("zackular2014") 18 | #' p0 <- zackular2014 19 | #' p <- plot_alpha_diversities(p0, 20 | #' type = "dominance", 21 | #' index.val = "all", 22 | #' plot.type = "stripchart", 23 | #' variableA = "DiseaseState", 24 | #' palette = "jco" 25 | #' ) 26 | #' 27 | #' print(p) 28 | #' @keywords visualization analysis 29 | #' index.val <- c("shannon, simpson") 30 | plot_alpha_diversities <- function(x, type, index.val = "all", plot.type, variableA, palette) { 31 | x1 <- x 32 | meta_df <- meta(x1) 33 | meta_df$sam_rep_nw <- rownames(meta_df) 34 | if (type == "diversities") { 35 | adiv <- alpha(x, index = index.val) 36 | adiv$sam_rep_nw <- rownames(adiv) 37 | } 38 | else if (type == "dominance") { 39 | adiv <- dominance(x, index = index.val) 40 | adiv$sam_rep_nw <- rownames(adiv) 41 | } 42 | else if (type == "evenness") { 43 | message("This will take some time") 44 | adiv <- evenness(x, index = index.val) 45 | adiv$sam_rep_nw <- rownames(adiv) 46 | } else if (type == "global") { 47 | adiv <- microbiome::alpha(x, index = index.val) 48 | adiv$sam_rep_nw <- rownames(adiv) 49 | } 50 | adiv.nw <- reshape2::melt(adiv) 51 | colnames(adiv.nw) <- c("sam_rep_nw", "Diversity", "div.val") 52 | meta_df_nw <- reshape2::melt(meta_df) 53 | meta_adiv <- merge.data.frame(meta_df_nw, adiv.nw, by = "sam_rep_nw") 54 | 55 | if (plot.type == "boxplot") { 56 | p <- ggboxplot(meta_adiv, 57 | x = variableA, y = "div.val", 58 | facet.by = "Diversity", add = "jitter", 59 | fill = variableA, 60 | palette = palette 61 | ) 62 | 63 | p2 <- facet(p + theme_bw(), 64 | facet.by = "Diversity", 65 | short.panel.labs = FALSE, 66 | scales = "free", # Allow long labels in panels 67 | panel.labs.background = list(fill = "white") 68 | ) 69 | } else if (plot.type == "stripchart") { 70 | p <- ggstripchart(meta_adiv, 71 | x = variableA, y = "div.val", 72 | facet.by = "Diversity", 73 | color = variableA, 74 | palette = palette 75 | ) 76 | 77 | p2 <- facet(p + theme_bw(), 78 | facet.by = "Diversity", 79 | short.panel.labs = FALSE, 80 | scales = "free", # Allow long labels in panels 81 | panel.labs.background = list(fill = "white") 82 | ) 83 | } else if (plot.type == "violin") { 84 | p <- ggviolin(meta_adiv, 85 | x = variableA, y = "div.val", 86 | facet.by = "Diversity", add = "jitter", 87 | fill = variableA, 88 | palette = palette 89 | ) 90 | 91 | p2 <- facet(p + theme_bw(), 92 | facet.by = "Diversity", 93 | short.panel.labs = FALSE, 94 | scales = "free", # Allow long labels in panels 95 | panel.labs.background = list(fill = "white") 96 | ) 97 | } 98 | 99 | return(p2) 100 | } 101 | -------------------------------------------------------------------------------- /R/plot_alpha_rcurve.R: -------------------------------------------------------------------------------- 1 | #' @title Rarefaction curves for alpha diversity indices 2 | #' @description Calculates alpha diversity idenx at varying sampling units (sequencing depth). 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param index Default:: "observed", 5 | #' @param subsamples Default: c(100,1000, 2000, 3000, 4000, 5000) 6 | #' @param lower.conf Default: 0.025. If type=CI 7 | #' @param upper.conf Default: 0.975. 8 | #' @param group Default: NULL 9 | #' @param linetype.main For ggplot line type for line by group. Default: 1 10 | #' @param line.opacity.main For ggplot alpha to determine opacity for line by group. Default: 0.5 11 | #' @param linetype.type For ggplot line type for line CI or SD. Default: 2 12 | #' @param line.opacity.type For ggplot line type to determine opacity for line CI or SD. Default: 0.25 13 | #' @param label.min TRUE or FALSE. Default: TRUE 14 | #' @param label.size Label min size 15 | #' @param label.color Label min color 16 | #' @param type Either CI (confidence interval) or SD (Standard deviation) Default: CI 17 | #' @examples 18 | #' \dontrun{ 19 | #' library(microbiomeutilities) 20 | #' data("zackular2014") 21 | #' p0 <- zackular2014 22 | #' # e.g. to make range of 23 | #' # subsamples <- seq(0, 5000, by=100)[-1] 24 | #' p <- plot_alpha_rcurve(p0, index="observed", 25 | #' lower.conf = 0.025, upper.conf = 0.975, 26 | #' group="DiseaseState") + 27 | #' scale_color_brewer(palette = "Paired") + 28 | #' scale_fill_brewer(palette = "Paired") 29 | #' print(p ) 30 | #' } 31 | #' @keywords visualization analysis 32 | #' @export 33 | plot_alpha_rcurve <- function(x, 34 | index="observed", 35 | subsamples = c(100,1000, 2000, 3000, 4000, 5000), 36 | lower.conf = 0.025, 37 | upper.conf = 0.975, 38 | group = NULL, 39 | linetype.main = 1, 40 | line.opacity.main = 0.5, 41 | linetype.type = 2, 42 | line.opacity.type = 0.25, 43 | type = "CI", 44 | label.min=TRUE, 45 | label.size = 3, 46 | label.color="grey70"){ 47 | 48 | depth_df <- ps.rar <- adiv <- adiv_nw <- depth_dfx <- NULL 49 | mean.measure <- sd.measure <- sub_sample <- d <- NULL 50 | 51 | 52 | 53 | depth_df <- c() 54 | for (d in subsamples) { 55 | #ps.rar <- rarefy_even_depth(x, sample.size = d, verbose = FALSE) 56 | #adiv <- suppressMessages(alpha(ps.rar, index=index)) 57 | #adiv <- as.data.frame(adiv) 58 | #colnames(adiv) <- index 59 | #adiv_nw <- cbind(adiv, meta(ps.rar)) 60 | #print(colnames(adiv_nw) ) 61 | #adiv_nw$sub_sample <- d 62 | #rownames(adiv_nw) < seq(1:nrow(adiv_nw)) 63 | xd <- rarefy_util(x, d, index=index) 64 | depth_df <- rbind(depth_df,xd) 65 | } 66 | 67 | #unique(depth_df$DiseaseState) 68 | #unique(depth_df$sub_sample) 69 | group <- sym(group) 70 | index <- sym(index) 71 | 72 | depth_dfx <- depth_df %>% 73 | group_by(sub_sample,!!group) %>% 74 | summarise(mean.measure = mean(!!index, na.rm = TRUE), 75 | sd.measure = sd(!!index, na.rm = TRUE), 76 | lower.sd = (mean.measure - sd.measure), 77 | upper.sd = (mean.measure + sd.measure), 78 | lower.ci = quantile(!!index, lower.conf, na.rm = TRUE), 79 | upper.ci = quantile(!!index, upper.conf, na.rm = TRUE)) %>% 80 | as.data.frame() 81 | 82 | 83 | p <- ggplot(depth_dfx, aes(sub_sample, mean.measure)) + 84 | geom_line(aes_string(color=group), 85 | linetype=linetype.main, 86 | alpha=line.opacity.main) 87 | if (label.min==TRUE){ 88 | p <- p + geom_vline(xintercept = min(subsamples), linetype= linetype.type) + 89 | geom_text(aes(x=min(subsamples), 90 | label= paste0("Min. depth- ", min(subsamples), " reads/sample"), 91 | y=mean(mean.measure)), 92 | colour=label.color, angle=90, vjust = 1.2, size=label.size) 93 | } 94 | 95 | 96 | if (type=="CI"){ 97 | p <- p + geom_ribbon(aes_string(ymin="lower.ci", 98 | ymax="upper.ci", 99 | fill = group), 100 | linetype=linetype.type, alpha=line.opacity.type) 101 | } else if (type=="SD"){ 102 | p <- p + geom_errorbar(aes_string(ymin="lower.sd", 103 | ymax="upper.sd", 104 | color = group), 105 | linetype=linetype.type, alpha=line.opacity.type) 106 | } 107 | p <- p + 108 | theme_biome_utils() + 109 | ylab(index) + 110 | xlab("No. of reads") 111 | 112 | return(p) 113 | } 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /R/plot_area.R: -------------------------------------------------------------------------------- 1 | #' @title Area plot 2 | #' @description Create an area plot for longitudinal samples 3 | #' with \code{\link{ggplot2}} package. 4 | #' @param x \code{\link{phyloseq-class}} object. 5 | #' @param xvar Column name to plot on x-axis. 6 | #' @param facet.by Column with variable that has multiple measurements. 7 | #' @param fill.colors brewer.pal(6,"Paired"). Specify colors. 8 | #' @param abund.thres = 0.001 check \code{\link{microbiome}} package aggregate_rare function. 9 | #' @param prev.thres = 0.1 check \code{\link{microbiome}} package aggregate_rare function. 10 | #' @param level Taxonomic level. OTU/ASV level not supported. 11 | #' @param ncol wrap, specify number of columns. 12 | #' @param nrow wrap, specify number of rows. 13 | #' @return \code{\link{ggplot}} object. 14 | #' @export 15 | #' @examples 16 | #' \dontrun{ 17 | #' library(microbiomeutilities) 18 | #' data("hmp2") 19 | #' ps <- hmp2 20 | #' ps.rel <- microbiome::transform(ps, "compositional") 21 | #' p <- plot_area(ps.rel, xvar="visit_number", 22 | #' level = "Phylum", 23 | #' facet.by = "subject_id", 24 | #' fill.colors=brewer.pal(6,"Paired")) 25 | #'} 26 | #' 27 | #' @keywords visualization 28 | #' 29 | plot_area <- function(x, 30 | xvar=NULL, 31 | level = NULL, 32 | facet.by = NULL, 33 | fill.colors=brewer.pal(6,"Paired"), 34 | abund.thres=0.001, 35 | prev.thres=0.5, 36 | ncol=5, 37 | nrow=5){ 38 | 39 | if(is.null(xvar)){ 40 | stop("xvar cannot be empty") 41 | } 42 | if(is.null(facet.by)){ 43 | stop("facet.by cannot be empty") 44 | } 45 | x.lev<-xdf<-comp.plt<-facet_var <- NULL 46 | x.lev <- aggregate_rare(x, 47 | level=level, 48 | detection = abund.thres, 49 | prevalence = prev.thres) 50 | 51 | xdf <- phy_to_ldf(x.lev, transform.counts = NULL) 52 | xdf$facet_var <- xdf[,facet.by] 53 | comp.plt <- ggplot(xdf) 54 | comp.plt <- comp.plt + 55 | geom_area(aes_string(x = xvar, 56 | y = "Abundance", 57 | fill = level)) + 58 | facet_wrap(~facet_var, 59 | scales = "free", 60 | ncol = ncol, 61 | nrow = nrow) + 62 | scale_fill_manual("Taxa", values = fill.colors) 63 | return(comp.plt + theme_biome_utils() + ylab("Relative abundance")) 64 | 65 | } 66 | -------------------------------------------------------------------------------- /R/plot_diversity_stats.R: -------------------------------------------------------------------------------- 1 | #' @title Diversity plot with stats 2 | #' @param x \code{\link{phyloseq-class}} object 3 | #' @param index diversity index. Calculated using microbiome::alpha 4 | #' @param group Grouping variable to compare 5 | #' @param group.colors Colors for plotting groups 6 | #' @param dot.opacity for ggplot alpha to determine opacity for points 7 | #' @param box.opacity for ggplot alpha to determine opacity for box 8 | #' @param violin.opacity for ggplot alpha to determine opacity for violin 9 | #' @param group.order Default is NULL. a list specifing order of x-axis. 10 | #' @param label.format For ggpubr::stat_compare_means "p.signif" 11 | #' E.g. c("H","CRC","nonCRC") 12 | #' @param stats Logical TRUE or FALSE. Calls ggpubr::stat_compare_means. 13 | #' @param ... params for ggpubr::stat_compare_means 14 | #' @importFrom ggpubr stat_compare_means rotate_x_text 15 | #' @importFrom gghalves geom_half_violin 16 | #' @examples 17 | #' \dontrun{ 18 | #' library(microbiomeutilities) 19 | #' library(ggpubr) 20 | #' data("zackular2014") 21 | #' p0 <- zackular2014 22 | #' mycols <- c("brown3", "steelblue", "grey50") 23 | #' p.m <- plot_diversity_stats(p0, 24 | #' group = "DiseaseState", 25 | #' index = "diversity_shannon", 26 | #' group.order = c("H", "CRC", "nonCRC"), 27 | #' group.colors = mycols 28 | #' ) 29 | #' print(p.m) 30 | #' } 31 | #' @keywords visualization analysis 32 | #' @export 33 | plot_diversity_stats <- function(x, index, 34 | group = NULL, 35 | group.colors = c("brown3", "steelblue"), 36 | dot.opacity = 0.25, 37 | box.opacity = 0.25, 38 | violin.opacity = 0.5, 39 | group.order = NULL, 40 | stats = TRUE, 41 | label.format = "p.format", 42 | ...) { 43 | if (stats == TRUE) { 44 | p <- plot_diversity_with_stats(x, index, 45 | group = group, 46 | group.colors = group.colors, 47 | dot.opacity = dot.opacity, 48 | box.opacity = box.opacity, 49 | violin.opacity = violin.opacity, 50 | group.order = group.order, 51 | label.format = label.format 52 | ) 53 | } else if (stats == FALSE) { 54 | p <- plot_diversity_without_stats(x, 55 | index = index, 56 | group = group, 57 | group.colors = group.colors, 58 | dot.opacity = dot.opacity, 59 | box.opacity = box.opacity, 60 | violin.opacity = violin.opacity, 61 | group.order = group.order, 62 | label.format = label.format 63 | ) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /R/plot_diversity_stats_utils.R: -------------------------------------------------------------------------------- 1 | 2 | # Diversity plot with stats 3 | # @param x \code{\link{phyloseq-class}} object 4 | # @param index diversity index. Calculated using microbiome::alpha 5 | # @param group Grouping variable to compare 6 | # @param group.colors Colors for plotting groups 7 | # @param dot.opacity for ggplot alpha to determine opacity for points 8 | # @param box.opacity for ggplot alpha to determine opacity for box 9 | # @param violin.opacity for ggplot alpha to determine opacity for violin 10 | # @param group.order Default is NULL. a list specifing order of x-axis. 11 | # @param dot.size size of point 12 | # E.g. c("H","CRC","nonCRC") 13 | # @param ... params for ggpubr::stat_compare_means 14 | # @importFrom ggpubr stat_compare_means rotate_x_text 15 | # @importFrom gghalves geom_half_violin 16 | # @keywords utilties 17 | plot_diversity_with_stats <- function(x, index, 18 | group = NULL, 19 | group.colors = c("brown3", "steelblue"), 20 | dot.opacity = 0.25, 21 | box.opacity = 0.25, 22 | violin.opacity = 0.5, 23 | dot.size = 2, 24 | group.order = NULL, ...) { 25 | 26 | # x <- ps.c 27 | adiv <- alpha(x, index = index) 28 | df_met <- cbind(adiv, meta(x)) 29 | 30 | if (!is.null(group.order)) { 31 | df_met[, group] <- factor(df_met[, group], 32 | levels = group.order 33 | ) 34 | } 35 | 36 | plt <- ggplot( 37 | data = df_met, 38 | aes_string(group, index, fill = group) 39 | ) + 40 | geom_half_violin( 41 | position = position_nudge(x = 0.15, y = 0), 42 | alpha = violin.opacity, side = "r" 43 | ) + 44 | geom_point(aes_string(y = index, color = group), 45 | position = position_jitter(width = 0.15), 46 | size = dot.size, alpha = dot.opacity 47 | ) + 48 | geom_boxplot( 49 | width = 0.2, outlier.shape = NA, 50 | alpha = box.opacity 51 | ) + 52 | guides(fill = FALSE, color = FALSE) + 53 | scale_fill_manual(values = group.colors) + 54 | scale_colour_manual(values = group.colors) 55 | 56 | if (length(unique(df_met[, group])) == 2) { 57 | plt <- plt + stat_compare_means( 58 | label = "p.format", 59 | tip.length = 0.05, 60 | method = "wilcox.test", ... 61 | ) 62 | } else if (length(unique(df_met[, group])) > 2) { 63 | comps <- make_pairs(df_met[, group]) 64 | plt <- plt + stat_compare_means( 65 | comparisons = comps, 66 | label = "p.format", 67 | tip.length = 0.05, 68 | method = "wilcox.test", ... 69 | ) 70 | } 71 | 72 | plt + theme_biome_utils() + rotate_x_text() 73 | } 74 | 75 | 76 | 77 | ################################################################################## 78 | # @title Diversity plot without stats 79 | # @param x \code{\link{phyloseq-class}} object 80 | # @param index diversity index. Calculated using microbiome::alpha 81 | # @param group Grouping variable to compare 82 | # @param group.colors Colors for plotting groups 83 | # @param dot.opacity for ggplot alpha to determine opacity for points 84 | # @param box.opacity for ggplot alpha to determine opacity for box 85 | # @param dot.size size of point 86 | # @param violin.opacity for ggplot alpha to determine opacity for violin 87 | # @param group.order Default is NULL. a list specifing order of x-axis. 88 | # E.g. c("H","CRC","nonCRC") 89 | # @param ... params for ggpubr::stat_compare_means 90 | # @importFrom ggpubr stat_compare_means rotate_x_text 91 | # @importFrom gghalves geom_half_violin 92 | plot_diversity_without_stats <- function(x, index, 93 | group = NULL, 94 | group.colors = c("brown3", "steelblue"), 95 | dot.opacity = 0.25, 96 | box.opacity = 0.25, 97 | violin.opacity = 0.5, 98 | dot.size = 2, 99 | group.order = NULL, ...) { 100 | 101 | # x <- ps.c 102 | adiv <- alpha(x, index = index) 103 | df_met <- cbind(adiv, meta(x)) 104 | 105 | if (!is.null(group.order)) { 106 | df_met[, group] <- factor(df_met[, group], 107 | levels = group.order 108 | ) 109 | } 110 | 111 | plt <- ggplot( 112 | data = df_met, 113 | aes_string(group, index, fill = group) 114 | ) + 115 | geom_half_violin( 116 | position = position_nudge(x = 0.15, y = 0), 117 | alpha = violin.opacity, side = "r" 118 | ) + 119 | geom_point(aes_string(y = index, color = group), 120 | position = position_jitter(width = 0.15), 121 | size = dot.size, alpha = dot.opacity 122 | ) + 123 | geom_boxplot( 124 | width = 0.2, outlier.shape = NA, 125 | alpha = box.opacity 126 | ) + 127 | guides(fill = FALSE, color = FALSE) + 128 | scale_fill_manual(values = group.colors) + 129 | scale_colour_manual(values = group.colors) 130 | plt <- plt + theme_biome_utils() + rotate_x_text() 131 | return(plt) 132 | } 133 | -------------------------------------------------------------------------------- /R/plot_listed_taxa.R: -------------------------------------------------------------------------------- 1 | #' @title A boxplot for user specified list of taxa 2 | #' @description User specifed OTUs are plotted. 3 | #' @details Useful for instances where user is interested only in some OTUs. For example OTUs 4 | #' reported to be significantly diferent. This can also be used at higher taxonomic 5 | #' levels, output from phyloseq::tax_glom or microbiome::aggregate_taxa. 6 | #' 7 | #' @param x \code{\link{phyloseq-class}} object. 8 | #' @param select.taxa a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024"). 9 | #' @param group Grouping variable to compare 10 | #' @param group.colors Colors for plotting groups 11 | #' @param dot.opacity For ggplot alpha to determine opacity for points 12 | #' @param box.opacity For ggplot alpha to determine opacity for box 13 | #' @param add.violin Loical. If half violoin to the added. Default=TRUE 14 | #' @param violin.opacity If add.violin=TRUE, opacity for violin. 15 | #' @param group.order Default is NULL. a list specifing order of x-axis. 16 | #' @param panel.arrange panels "grid" or "wrap" ggplot's facet_XXX 17 | #' @param ncol if wrap, specify number of columns. 18 | #' @param nrow if wrap, specify number of rows. 19 | #' @return \code{\link{ggplot}} object. This can be further modified using ggpubr. 20 | #' @export 21 | #' @examples 22 | #' \dontrun{ 23 | #' # Example data 24 | #' library(microbiome) 25 | #' library(microbiomeutilities) 26 | #' data("zackular2014") 27 | #' p0 <- zackular2014 28 | #' p0.f <- format_to_besthit(p0) 29 | #' select.taxa <- c("OTU-d__denovo31:Dorea", "OTU-d__denovo24:Blautia") 30 | #' mycols <- c("brown3", "steelblue", "grey50") 31 | #' p <- plot_listed_taxa(p0.f, select.taxa, 32 | #' group = "DiseaseState", 33 | #' add.violin = TRUE, 34 | #' group.colors = mycols 35 | #' ) 36 | #' print(p) 37 | #' } 38 | #' @keywords visualization 39 | #' 40 | 41 | plot_listed_taxa <- function(x, 42 | select.taxa, 43 | group, 44 | group.colors, 45 | dot.opacity = 0.25, 46 | box.opacity = 0.25, 47 | group.order = NULL, 48 | add.violin = TRUE, 49 | violin.opacity = 0.25, 50 | panel.arrange = "grid", 51 | ncol = NULL, 52 | nrow = NULL) { 53 | x.rel <- x.prun <- x.df <- p.box <- p.vio <- p.strp <- NULL 54 | 55 | if(is.na(group) | is.null(group)) { 56 | stop(" 'group' argument cannot be empty") 57 | } 58 | 59 | x.rel <- microbiome::transform(x, "compositional") 60 | 61 | x.prun <- prune_taxa(select.taxa, x.rel) 62 | 63 | x.df <- phy_to_ldf(x.prun, transform.counts = NULL) 64 | 65 | 66 | if (!is.null(group.order)) { 67 | x.df[, group] <- factor(x.df[, group], 68 | levels = group.order 69 | ) 70 | } 71 | 72 | p <- ggplot( 73 | data = x.df, 74 | aes_string( 75 | x = group, y = "Abundance", 76 | fill = group 77 | ) 78 | ) + 79 | geom_point(aes_string(x = group, color = group), 80 | position = position_jitter(width = 0.15), 81 | size = 1, alpha = dot.opacity 82 | ) + 83 | geom_boxplot( 84 | width = 0.2, outlier.shape = NA, 85 | alpha = box.opacity 86 | ) + 87 | guides(fill = FALSE, color = FALSE) 88 | if (add.violin == TRUE) { 89 | p <- p + geom_half_violin( 90 | position = position_nudge(x = 0.15, y = 0), 91 | alpha = violin.opacity, side = "r" 92 | ) 93 | } 94 | 95 | p <- p + 96 | scale_fill_manual(values = group.colors) + 97 | scale_colour_manual(values = group.colors) 98 | 99 | if (panel.arrange == "grid") { 100 | # Make seperate samples based on main varaible 101 | p <- p + facet_grid(~OTUID, scales = "free") 102 | } else if (panel.arrange == "wrap") { 103 | p <- p + facet_wrap(~OTUID, 104 | scales = "free", 105 | ncol = ncol, 106 | nrow = nrow 107 | ) 108 | } 109 | 110 | p <- p + 111 | theme(axis.title.x = element_blank()) 112 | 113 | return(p + theme_biome_utils()) 114 | } 115 | -------------------------------------------------------------------------------- /R/plot_ordination_utils.R: -------------------------------------------------------------------------------- 1 | #' @title Plot species loading with ordinations 2 | #' @description This function extends the plot_ordination function of \code{\link{phyloseq}}to highlight the top taxa loadings 3 | #' on the species ordination. 4 | #' @details This function is useful for visualizing specifc taxa that could be important in explaining variations in ordinations. 5 | #' @param x \code{\link{phyloseq-class}} object 6 | #' @param ordiObject Output of ordinate from package phyloseq. Only NMDS/CCA and Bray supported. 7 | #' @param plot.arrow If arrow should be plotted for species either TRUE or FALSE. 8 | #' @param scale.arrow If arrow is plotted a constant to multiply axis values for clearing visualisations. 9 | #' @param top.taxa Top varying taxa to plot, default is 5. 10 | #' @param color.opt Variable of interest from metadata. 11 | #' @return plot 12 | #' @importFrom ggrepel geom_text_repel 13 | #' @import ggplot2 14 | #' @export 15 | #' @examples 16 | #' \dontrun{ 17 | #' 18 | #' library(microbiomeutilities) 19 | #' library(RColorBrewer) 20 | #' data("zackular2014") 21 | #' ps1 <- zackular2014 22 | #' ps2 <- tax_glom(ps1, "Genus") 23 | #' ps2f <- format_to_besthit(ps2) 24 | #' orddi <- ordinate(ps2f, method = "CCA", distance = "bray") 25 | #' p <- plot_ordination_utils(ps2f, orddi, 26 | #' color = "DiseaseState", plot.arrow = TRUE, 27 | #' scale.arrow = 1.3, top.taxa = 5 28 | #' ) 29 | #' print(p) 30 | #' } 31 | #' @keywords utilities 32 | #' 33 | plot_ordination_utils <- function(x, 34 | ordiObject, 35 | color.opt = NULL, 36 | plot.arrow = TRUE, 37 | scale.arrow = NULL, 38 | top.taxa = 5) { 39 | p.base <- 40 | y.axis <- 41 | x.axis <- 42 | pdf.sam <- 43 | pdf.tax <- 44 | pdf.tax2 <- 45 | id.type <- 46 | best_hit <- 47 | select.top <- dif.tax.ord <- pdf.tax3 <- plot.ord.load <- NULL 48 | p.base <- plot_ordination(x, ordiObject, 49 | color = color.opt, 50 | type = "split" 51 | ) 52 | y.axis <- p.base$labels$y[1] 53 | x.axis <- p.base$labels$x[1] 54 | pdf.base <- p.base$data 55 | # unique(pdf$id.type) 56 | pdf.sam <- subset(pdf.base, id.type == "Samples") 57 | pdf.tax <- subset(pdf.base, id.type == "Taxa") 58 | rownames(pdf.tax) <- pdf.tax$best_hit 59 | pdf.tax2 <- pdf.tax[, 1:2] 60 | select.top <- min(top.taxa, dim(pdf.tax2)[1]) 61 | diff.taxa.ord <- names(sort(apply(abs(pdf.tax2), 1, max), 62 | decreasing = T 63 | ))[1:select.top] 64 | pdf.tax3 <- subset(pdf.tax, best_hit %in% diff.taxa.ord) 65 | plot.ord.load <- 66 | ggplot() + 67 | geom_point( 68 | data = pdf.sam, 69 | aes(pdf.sam 70 | [ 71 | , 72 | 1 73 | ], pdf.sam[, 2], color = pdf.sam[, color.opt]) 74 | ) 75 | plot.ord.load <- plot.ord.load + ggrepel::geom_text_repel( 76 | data = pdf.tax3, 77 | aes(scale.arrow * pdf.tax3[, 1], scale.arrow * pdf.tax3 78 | [ 79 | , 80 | 2 81 | ], label = best_hit) 82 | ) + ggrepel::geom_text_repel() 83 | if (plot.arrow == TRUE) { 84 | plot.ord.load <- plot.ord.load + geom_segment( 85 | data = pdf.tax3, 86 | aes( 87 | x = 0, 88 | xend = scale.arrow * pdf.tax3[, 1], 89 | y = 0, 90 | yend = scale.arrow * pdf.tax3[, 2] 91 | ), 92 | arrow = arrow(length = unit( 93 | 0.4, 94 | "cm" 95 | )), 96 | color = "grey50" 97 | ) 98 | plot.ord.load <- plot.ord.load + theme_bw() + xlab(x.axis) + 99 | ylab(y.axis) 100 | return(plot.ord.load) 101 | } else { 102 | plot.ord.load <- plot.ord.load + theme_bw() + xlab(x.axis) + 103 | ylab(y.axis) 104 | return(plot.ord.load) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /R/plot_read_distribution.R: -------------------------------------------------------------------------------- 1 | #' @title Distribution of reads 2 | #' @description Plots distribution of reads. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param groups Metadata variable to check for groups based sequencing effort. 5 | #' @param plot.type Either density or histogram plot 6 | #' @author Contact: Sudarshan Shetty \email{sudarshanshetty9@@gmail.com} 7 | #' @return A \code{\link{ggplot}} plot object. 8 | #' @export 9 | #' @examples 10 | #' library(microbiome) 11 | #' data(zackular2014) 12 | #' ps0 <- zackular2014 13 | #' p <- plot_read_distribution(ps0, groups = "DiseaseState", plot.type = "density") 14 | #' print(p) 15 | #' @keywords visualization utilities 16 | 17 | plot_read_distribution <- function(x, groups, 18 | plot.type = c( 19 | "density", 20 | "histogram" 21 | )) { 22 | df <- pdfa <- pdfb <- Reads_per_sample <- NULL 23 | title <- "Distribution of reads in the dataset" 24 | 25 | df <- meta(x) 26 | SeqDepth <- sample_sums(x) 27 | 28 | # df <- data.table(as(sample_data(x), "data.frame"), Reads_per_sample = sample_sums(x), 29 | # keep.rownames = TRUE) 30 | 31 | df$Reads_per_sample <- SeqDepth 32 | 33 | if (plot.type == "density") { 34 | p.dfa <- ggplot(df, aes(x = Reads_per_sample, fill = factor(groups))) + 35 | geom_density(alpha = 0.5, fill = "steelblue") + 36 | facet_wrap(groups) + 37 | ggplot2::theme_bw() + 38 | ggplot2::theme(axis.text.x = element_text( 39 | angle = 90, 40 | hjust = 1 41 | )) 42 | } else if (plot.type == "histogram") { 43 | p.dfa <- ggplot(df, aes(x = Reads_per_sample, fill = factor(groups))) + 44 | geom_histogram(alpha = 0.5) + 45 | facet_wrap(groups) + 46 | ggplot2::theme_bw() + 47 | ggplot2::theme(axis.text.x = element_text(angle = 90, hjust = 1)) 48 | } 49 | #print("Done plotting") 50 | return(p.dfa) 51 | } 52 | -------------------------------------------------------------------------------- /R/plot_select_taxa.R: -------------------------------------------------------------------------------- 1 | #' @title A boxplot for user specified list of taxa 2 | #' @description User specifed OTUs are plotted. 3 | #' @details Useful for instances where user is interested only in some OTUs. For example OTUs 4 | #' reported to be significantly diferent. 5 | #' 6 | #' @param x \code{\link{phyloseq-class}} object. 7 | #' @param select.taxa a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024"). 8 | #' @param variableA Variable of interested to be checked. This will also be used to color the plot. 9 | #' @param palette Any of the RColorBrewer plettes. 10 | #' @param plot.type Three optons c("stripchart", "boxplot", "violin") 11 | #' @param group.order Default is NULL. a list specifing order of x-axis. E.g. c("H","CRC","nonCRC") 12 | #' @return \code{\link{ggplot}} object. This can be further modified using ggpubr. 13 | #' @export 14 | #' @examples 15 | #' \dontrun{ 16 | #' # Example data 17 | #' library(microbiome) 18 | #' library(microbiomeutilities) 19 | #' data("zackular2014") 20 | #' p0 <- zackular2014 21 | #' p0.f <- format_to_besthit(p0) 22 | #' select.taxa <- c("OTU-d__denovo31:Dorea", "OTU-d__denovo24:Blautia") 23 | #' p <- plot_select_taxa(p0.f, select.taxa, "DiseaseState", "Paired", plot.type = "stripchart") 24 | #' print(p) 25 | #' } 26 | #' @keywords utilities 27 | #' 28 | 29 | plot_select_taxa <- function(x, select.taxa, variableA, 30 | palette, plot.type, 31 | group.order = NULL) { 32 | x.rel <- x.prun <- x.df <- p.box <- p.vio <- p.strp <- NULL 33 | .Deprecated("plot_listed_taxa", "The microbiomeutilties::plot_select_taxa function is deprecated.") 34 | x.rel <- microbiome::transform(x, "compositional") 35 | 36 | x.prun <- prune_taxa(select.taxa, x.rel) 37 | 38 | x.df <- phy_to_ldf(x.prun, transform.counts = NULL) 39 | 40 | if (!is.null(group.order)) { 41 | x.df[, variableA] <- factor(x.df[, variableA], 42 | levels = group.order 43 | ) 44 | } 45 | 46 | if (plot.type == "boxplot") { 47 | p <- ggpubr::ggboxplot(x.df, variableA, "Abundance", 48 | facet.by = "OTUID", 49 | color = variableA, palette = palette, 50 | legend = "right", add = "jitter", 51 | panel.labs.background = list(fill = "white") 52 | ) 53 | } else if (plot.type == "violin") { 54 | p <- ggpubr::ggviolin(x.df, variableA, "Abundance", 55 | facet.by = "OTUID", 56 | color = variableA, palette = palette, 57 | legend = "right", add = "jitter", 58 | panel.labs.background = list(fill = "white") 59 | ) 60 | } else if (plot.type == "stripchart") { 61 | p <- ggpubr::ggstripchart(x.df, variableA, "Abundance", 62 | facet.by = "OTUID", 63 | color = variableA, palette = palette, 64 | legend = "right", panel.labs.background = list(fill = "white") 65 | ) 66 | } 67 | 68 | return(p) 69 | } 70 | -------------------------------------------------------------------------------- /R/plot_sphagetti.R: -------------------------------------------------------------------------------- 1 | #' @title Spaghetti Plots 2 | #' @param x \code{\link{phyloseq-class}} object 3 | #' @param select.taxa a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024"). 4 | #' @param group Column describing sample that have multiple measurements. For e.g. Subject_Ids 5 | #' which has all subject_ids listed. 6 | #' @param xvar X-axis variable. This can be visit_number for participants in subject_id. 7 | #' @param line.bg.color Line color for background. Default ="#8d99ae", 8 | #' @param bg.opacity Line opacity for background. 9 | #' @param focus.color Line color for focus being plotted. 10 | #' @param focus.line.size Line size for focus being plotted. 11 | #' @param line.size Line size for background. 12 | #' @param ncol if wrap, specify number of columns. 13 | #' @param nrow if wrap, specify number of rows. 14 | #' @param plot.var One of "by_sample":Many sample one taxa or "by_taxa":Many taxa one sample 15 | #' @return \code{\link{ggplot}} object. This can be further modified using ggpubr. 16 | #' @export 17 | #' @examples 18 | #' \dontrun{ 19 | #' # Example data 20 | #' library(microbiomeutilities) 21 | #' data("hmp2") 22 | #' pseq <- hmp2 # Ren 23 | #' pseq.rel <- microbiome::transform(pseq, "compositional") 24 | #' pseq.relF <- format_to_besthit(pseq.rel) 25 | #' # Choose one participant 26 | #' phdf.s <- subset_samples(pseq.relF, subject_id == 27 | #' "Participant_1") 28 | #' # Choose top 12 taxa to visualize 29 | #' ntax <- top_taxa(phdf.s, 12) 30 | #' phdf.s <- prune_taxa(ntax, phdf.s) 31 | #' 32 | #' plot_spaghetti(phdf.s, 33 | #' plot.var = "by_taxa", 34 | #' select.taxa = ntax, 35 | #' xvar = "visit_number", 36 | #' line.bg.color = "#8d99ae", 37 | #' focus.color = "#555b6e", 38 | #' ncol = 3, 39 | #' nrow = 4, 40 | #' line.size = 0.2 41 | #' ) 42 | #' 43 | #' print(p) 44 | #' } 45 | #' @keywords visualization 46 | #' 47 | 48 | plot_spaghetti <- function(x, 49 | plot.var = "by_taxa", 50 | select.taxa = NULL, 51 | xvar = NULL, 52 | group = NULL, 53 | line.bg.color = "#8d99ae", 54 | bg.opacity = 0.5, 55 | focus.color = "brown3", 56 | ncol = NULL, 57 | nrow = NULL, 58 | focus.line.size = 0.5, 59 | line.size = 1) { 60 | if (plot.var == "by_sample") { 61 | if (is.null(group)) { 62 | stop("if plot.var is 'by_sample', specify variable in 'group' argument ") 63 | } 64 | 65 | plot_spaghetti_sample( 66 | x = x, 67 | select.taxa = select.taxa, 68 | xvar = xvar, 69 | group = group, 70 | line.bg.color = line.bg.color, 71 | bg.opacity = bg.opacity, 72 | focus.color = focus.color, 73 | ncol = ncol, 74 | nrow = nrow, 75 | focus.line.size = focus.line.size, 76 | line.size = line.size 77 | ) 78 | } else if (plot.var == "by_taxa") { 79 | plot_spaghetti_taxa( 80 | x = x, 81 | select.taxa = select.taxa, 82 | xvar = xvar, 83 | group = group, 84 | bg.opacity = bg.opacity, 85 | line.bg.color = line.bg.color, 86 | focus.color = focus.color, 87 | ncol = ncol, 88 | nrow = nrow, 89 | focus.line.size = focus.line.size, 90 | line.size = line.size 91 | ) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /R/plot_taxa_boxplot.R: -------------------------------------------------------------------------------- 1 | #' @title Taxonomic Composition Plot boxplot 2 | #' @description Plot taxon abundance for samples. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param taxonomic.level Merge the OTUs (for phyloseq object) into a higher taxonomic level. This has to be one from colnames(tax_table(x)). 5 | #' @param top.otu Top number of taxa to plot. 6 | #' @param group Specify main variable of interest. This should be one of the variables in sample_variables(x). 7 | #' @param keep.other TRUE or FALSE. Default is FALSE. This will not plot taxa group as Other 8 | #' @param title title for the plot 9 | #' @param group.colors Colors for plotting groups 10 | #' @param dot.opacity For ggplot alpha to determine opacity for points 11 | #' @param box.opacity For ggplot alpha to determine opacity for box 12 | #' @param dot.size For ggplot alpha to determine size for points 13 | #' @param add.violin Loical. If half violoin to the added. Default=TRUE 14 | #' @param violin.opacity If add.violin=TRUE, opacity for violin. 15 | #' @param group.order Default is NULL. a list specifing order of x-axis. E.g. c("H","CRC","nonCRC") 16 | #' @return A \code{\link{ggplot}} plot object. 17 | #' @export 18 | #' @import ggplot2 19 | #' @examples 20 | #' \dontrun{ 21 | #' # Example data 22 | #' library(microbiomeutilities) 23 | #' library(RColorBrewer) 24 | #' data("zackular2014") 25 | #' ps0 <- zackular2014 26 | #' mycols <- c("brown3", "steelblue", "grey50") 27 | #' pn <- plot_taxa_boxplot(ps0, 28 | #' taxonomic.level = "Phylum", 29 | #' top.otu = 6, 30 | #' group = "DiseaseState", 31 | #' title = "Relative abudance plot", 32 | #' keep.other = FALSE, 33 | #' group.order = c("H", "CRC", "nonCRC"), 34 | #' group.colors = mycols 35 | #' ) 36 | #' print(pn + theme_biome_utils()) 37 | #' } 38 | #' 39 | #' @keywords visualization 40 | 41 | plot_taxa_boxplot <- function(x, taxonomic.level, 42 | top.otu, 43 | keep.other = FALSE, 44 | group, 45 | title, 46 | group.colors = NULL, 47 | group.order = NULL, 48 | add.violin = TRUE, 49 | violin.opacity = 0.25, 50 | box.opacity = 0.25, 51 | dot.opacity = 0.25, 52 | dot.size = 2) { 53 | Abundance <- Taxa <- RelAbun <- NULL 54 | if (!is.null(x@phy_tree)) { 55 | message("For plotting purpuses the phy_tree will be removed") 56 | x@phy_tree <- NULL 57 | } 58 | else { 59 | message("The phy_tree slot is empty, easy to make the plot") 60 | } 61 | 62 | 63 | # taxic <- as.data.frame(x@tax_table) 64 | taxic <- tax_table(x) %>% 65 | as("matrix") %>% 66 | as.data.frame() 67 | # using abundances function from microbiome as sometime otu_table can have taxa_are_rows FALSE in phyloseq 68 | # otudf <- as.data.frame(abundances(x) 69 | otudf2 <- abundances(x) %>% 70 | as("matrix") %>% 71 | as.data.frame() 72 | taxic$OTU <- row.names(otudf2) 73 | taxmat <- as.matrix(taxic) 74 | new.tax <- tax_table(taxmat) 75 | tax_table(x) <- new.tax 76 | 77 | 78 | # Merge the taxa at a higher taxonomic level 79 | 80 | if (!taxonomic.level == "OTU") { 81 | x <- aggregate_top_taxa2(x, taxonomic.level, top = top.otu) 82 | } 83 | 84 | x1 <- transform(x, "compositional") 85 | 86 | x.df0 <- suppressWarnings(suppressMessages(phy_to_ldf(x1, transform.counts = NULL))) 87 | # x.df0$RelAbun <- as.numeric(x.df0$Abundance * 100) 88 | x.df0$Taxa <- x.df0[, taxonomic.level] 89 | 90 | if (keep.other == FALSE) { 91 | x.df0 <- subset(x.df0, Taxa != "Other") 92 | } 93 | if (!is.null(group.order)) { 94 | x.df0[, group] <- factor(x.df0[, group], 95 | levels = group.order 96 | ) 97 | } 98 | 99 | p <- ggplot(x.df0, aes( 100 | x = x.df0[, group], 101 | y = Abundance, 102 | fill = x.df0[, group] 103 | )) 104 | 105 | p <- p + geom_boxplot(aes_string(fill = group), 106 | width = 0.2, 107 | outlier.shape = NA, 108 | alpha = box.opacity 109 | ) + 110 | geom_jitter(aes_string( 111 | group = x.df0[, group], 112 | color = group 113 | ), 114 | alpha = dot.opacity, size = dot.size 115 | ) 116 | if (add.violin == TRUE) { 117 | p <- p + geom_half_violin( 118 | position = position_nudge(x = 0.15, y = 0), 119 | alpha = violin.opacity, side = "r" 120 | ) 121 | } 122 | p <- p + ggtitle(title) + theme_bw() + 123 | facet_wrap(~Taxa, scales = "free") 124 | 125 | p <- p + ylab("Relative abundance (%)") + xlab(taxonomic.level) + 126 | scale_fill_manual(group, 127 | values = group.colors 128 | ) + 129 | scale_color_manual(group, 130 | values = group.colors 131 | ) + 132 | scale_y_continuous(labels = scales::percent) 133 | 134 | return(p + xlab("")) 135 | } 136 | -------------------------------------------------------------------------------- /R/plot_taxa_cv.R: -------------------------------------------------------------------------------- 1 | #' @title Coefficient of variations 2 | #' @description Plots CV for OTUs/ASVs. 3 | #' @details Check if there are spurious OTUs/ASVs. 4 | #' @param x \code{\link{phyloseq-class}} object. 5 | #' @param plot.type scatter or hist (histogram) 6 | #' @return A \code{\link{ggplot}} plot object. 7 | #' @export 8 | #' @importFrom graphics hist 9 | #' @importFrom stats aggregate median sd 10 | #' @importFrom microbiome abundances 11 | #' @examples 12 | #' \dontrun{ 13 | #' # Example data 14 | #' library(microbiome) 15 | #' library(microbiomeutilities) 16 | #' data("zackular2014") 17 | #' p0 <- zackular2014 18 | #' p <- plot_taxa_cv(p0, plot.type = "hist") 19 | #' print(p) 20 | #' } 21 | #' 22 | #' @keywords utilities 23 | #' 24 | plot_taxa_cv <- function(x, plot.type) { 25 | MeanAbun <- CV <- Phylum <- NULL 26 | cal_cv <- function(x) abs(sd(x) / mean(x)) 27 | x.mean.rel <- apply(abundances(x), 1, function(x) mean(x)) 28 | # head(ps.mean.rel) 29 | x.cvs <- apply(abundances(x), 1, function(x) cal_cv(x)) 30 | # head(ps.cvs) 31 | 32 | # tax.x.df <- as.data.frame(tax_table(x)) 33 | tax.x.df <- tax_table(x) %>% 34 | as("matrix") %>% 35 | as.data.frame() %>% 36 | mutate( 37 | MeanAbun = x.mean.rel, 38 | CV = x.cvs 39 | ) 40 | # tax.x.df$MeanAbun <- cbind(x.mean.rel) 41 | # tax.x.df$CV <- cbind(x.cvs) 42 | h <- hist(tax.x.df$MeanAbun) 43 | 44 | # head(tax.ps.df) 45 | if (plot.type == "scatter") { 46 | cvplot <- ggplot(tax.x.df, 47 | aes(MeanAbun, CV), 48 | label = NA 49 | ) + 50 | geom_point(aes(color = Phylum)) + 51 | scale_x_continuous(breaks = h$breaks) + 52 | theme_bw() + 53 | xlab("Abundance") 54 | } else { 55 | cvplot <- ggplot(tax.x.df, aes(CV)) + 56 | geom_histogram() + 57 | theme_bw() 58 | } 59 | 60 | return(cvplot) 61 | } 62 | -------------------------------------------------------------------------------- /R/plot_taxa_heatmap.R: -------------------------------------------------------------------------------- 1 | #' @title Heatmap using \code{\link{phyloseq-class}} and \code{\link{pheatmap}} 2 | #' @description Plot heatmap using \code{\link{phyloseq-class}} object as input. 3 | #' @param x \code{\link{phyloseq-class}} object. 4 | #' @param subset.top either NA or number of Top OTUs to use for plotting. 5 | #' @param transformation either 'log10', 'clr','Z', 'compositional', or NA 6 | #' @param VariableA main variable of Interest. 7 | #' @param heatcolors is the option for colors in \code{\link{pheatmap}}. Default is to use Spectral 8 | #' @param ... Arguments to be passed \code{\link{pheatmap}}. 9 | #' @return A \code{\link{pheatmap}} plot object. 10 | #' @export 11 | #' @importFrom pheatmap pheatmap 12 | #' @importFrom RColorBrewer brewer.pal 13 | #' @author Sudarshan A. Shetty (sudarshanshetty9@gmail.com) 14 | #' @examples 15 | #' 16 | #' library(microbiomeutilities) 17 | #' library(viridis) 18 | #' library(RColorBrewer) 19 | #' data("zackular2014") 20 | #' ps0 <- zackular2014 21 | #' 22 | #' heat.sample <- plot_taxa_heatmap(ps0, 23 | #' subset.top = 20, 24 | #' VariableA = "DiseaseState", 25 | #' heatcolors = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100), 26 | #' transformation = "log10" 27 | #' ) 28 | #' @keywords visualization 29 | plot_taxa_heatmap <- function(x, subset.top, 30 | transformation, 31 | VariableA, 32 | heatcolors = NULL, ...) { 33 | topOTU <- phyobj1 <- phyobj2 <- otu.mat <- NULL 34 | meta.tab <- select.meta <- color.heatmap <- NULL 35 | 36 | 37 | #x <- ps0 38 | 39 | x <- suppressWarnings(suppressMessages(format_to_besthit(x))) 40 | if (!is.null(subset.top)) { 41 | message(paste0("Top ", subset.top, " OTUs selected", 42 | sep = " " 43 | )) 44 | topOTU <- top_taxa(x, n = subset.top) 45 | } else { 46 | stop("specify a number/value for subset.top") 47 | } 48 | 49 | 50 | if (transformation == "log10") { 51 | message("log10, if zeros in data then log10(1+x) will be used") 52 | phyobj1 <- prune_taxa(topOTU, x) 53 | message("First top taxa were selected and \nthen abundances tranformed to log10(1+X)") 54 | 55 | #prev.tx <- prevalence(phyobj1) 56 | 57 | phyobj2 <- transform(phyobj1, "log10") 58 | } else if (transformation == "compositional") { 59 | phyobjx <- transform(x, "compositional") 60 | phyobj2 <- prune_taxa(topOTU, phyobjx) 61 | 62 | #prev.tx <- prevalence(phyobj2) 63 | 64 | message("First converted to compositional \n then top taxa were selected") 65 | } else if (transformation == "Z-OTU") { 66 | phyobj1 <- prune_taxa(topOTU, x) 67 | 68 | #prev.tx <- prevalence(phyobj1) 69 | 70 | phyobj2 <- transform(phyobj1, "Z") 71 | message("First top taxa were selected and \nthen abundances tranformed to Z values") 72 | } else if (transformation == "clr") { 73 | phyobj1 <- prune_taxa(topOTU, x) 74 | 75 | #prev.tx <- prevalence(phyobj1) 76 | 77 | phyobj2 <- transform(phyobj1, "clr") 78 | message("First top taxa were selected and \nthen abundances tranformed to clr") 79 | } else if (!is.null(transformation)) { 80 | stop("specify a number for transformation, log10, compositional, Z-OTU, clr") 81 | } 82 | 83 | 84 | # format the taxonomy to incluse unique names 85 | # phyobj2 <- format_phyloseq(phyobj2) 86 | 87 | 88 | otu.mat <- abundances(phyobj2) 89 | meta.tab <- meta(phyobj2) 90 | 91 | # choose which variables of interest to include in 92 | # the heatmap 93 | select.meta <- subset(meta.tab, select = c(VariableA)) 94 | 95 | 96 | if (is.null(heatcolors)) { 97 | color.heatmap <- brewer.pal(6, "Spectral") 98 | } else { 99 | color.heatmap <- heatcolors 100 | } 101 | 102 | newnames <- NULL 103 | newnames <- lapply( 104 | rownames(otu.mat), 105 | function(x) bquote(italic(.(x)))) 106 | #row_df <- NULL 107 | #row_df <- as.data.frame(round(prev.tx*100, 2)) 108 | #colnames(row_df) <- c("Prevalence") 109 | 110 | 111 | heatmap <- pheatmap::pheatmap(otu.mat, 112 | labels_row = as.expression(newnames), 113 | annotation_col = select.meta, 114 | #annotation_colors = annotation_colors, 115 | #annotation_row = row_df, 116 | color = color.heatmap, ...) 117 | 118 | 119 | return(list("plot"=heatmap, "tax_tab"=otu.mat)) 120 | 121 | } 122 | 123 | -------------------------------------------------------------------------------- /R/prep_tern_otu.R: -------------------------------------------------------------------------------- 1 | #' @title Create table for ternary plot OTU 2 | #' @description Create a table for ternary plot ggtern package. 3 | #' @details Plots the mean relative abundance of taxa in 3 groups being compared. 4 | #' @param x \code{\link{phyloseq-class}} object. 5 | #' @param abund.thres = 0.0001 check \code{\link{microbiome}} package core function. 6 | #' remove taxa that are detected at 0.0001 in less than prev.thres of samples. 7 | #' @param prev.thres = 0.1 check \code{\link{microbiome}} package core function. 8 | #' @param group Grouping variable to compare, for this plot there has to be three 9 | #' groups in the data 10 | #' @return tibble object. 11 | #' @examples 12 | #' # library(microbiome) 13 | #' # library(microbiomeutilities) 14 | #' # library(dplyr) 15 | #' # data("zackular2014") 16 | #' # p0 <- zackular2014 17 | #' # prep_tern_otu(p0, group="DiseaseState", 18 | #' # abund.thres=0.0001, prev.thres=0.25) 19 | #' @keywords utilities visualization 20 | prep_tern_otu <- function(x, 21 | abund.thres = 0.0001, 22 | prev.thres = 0.1, 23 | group = NULL) { 24 | p0.mr <- p0.mr.cr <- df <- taxa_df <- OTUID <- Sam_rep <- taxa_mean <- NULL 25 | Abundance <- value <- NULL 26 | 27 | if (is.null(group)) { 28 | message("Ternary plot requires 3 groups to compare") 29 | stop("Please provide group variable to compare") 30 | } 31 | 32 | if (length(unique(meta(x)[, group])) < 3) { 33 | message("Ternary plot requires 3 groups to compare") 34 | stop(paste0(group, " variable has less that 3 groups to compare")) 35 | } 36 | 37 | if (length(unique(meta(x)[, group])) > 3) { 38 | message("Ternary plot requires 3 groups to compare") 39 | stop(paste0(group, " variable has more than 3 groups to compare")) 40 | } 41 | 42 | 43 | p0.mr <- transform(x, "compositional") 44 | p0.mr.cr <- core(p0.mr, 45 | detection = abund.thres, 46 | prevalence = prev.thres 47 | ) 48 | 49 | tax_table(p0.mr.cr)[, colnames(tax_table(p0.mr.cr))] <- 50 | gsub(tax_table(p0.mr.cr)[, colnames(tax_table(p0.mr.cr))], 51 | pattern = "[a-z]__", replacement = "" 52 | ) 53 | 54 | p0.mr <- merge_samples(p0.mr.cr, group = group) 55 | 56 | df <- phy_to_ldf(p0.mr, NULL) 57 | 58 | # extract taxonomy 59 | taxa_df <- tax_table(p0.mr) %>% 60 | as("matrix") %>% 61 | as.data.frame() 62 | taxa_df$OTUID <- rownames(taxa_df) 63 | 64 | # taxa_df[,level.color][which(taxa_df[,level.color] == "")] <- "Other" 65 | 66 | # taxa_df$level_var <- taxa_df[,level] 67 | 68 | taxa_mean <- df %>% 69 | group_by(OTUID, Sam_rep) %>% 70 | summarise(value = mean(Abundance)) 71 | 72 | taxa_tern <- smas <- NULL 73 | 74 | taxa_tern <- taxa_mean %>% 75 | group_by(Sam_rep, OTUID) %>% 76 | # mutate(index=row_number()) %>% 77 | pivot_wider(names_from = Sam_rep, values_from = value) %>% 78 | left_join(taxa_df, by = "OTUID") 79 | 80 | return(taxa_tern) 81 | } 82 | -------------------------------------------------------------------------------- /R/prep_ternary.R: -------------------------------------------------------------------------------- 1 | #' @title Create table for Ternary plot 2 | #' @description Create a table for ternary plot ggtern R package. 3 | #' @details Plots the mean relative abundance of taxa in 3 groups being compared. 4 | #' @param x \code{\link{phyloseq-class}} object 5 | #' @param abund.thres = 0.0001 check \code{\link{microbiome}} package core function 6 | #' remove taxa that are dectected at 0.0001 in less than prev.thres of samples 7 | #' @param prev.thres = 0.1 check \code{\link{microbiome}} package core function 8 | #' @param level = "Genus" Taxonomic level. If OTU/ASV level specify="lowest" 9 | #' Does not support phylum level aggregation 10 | #' @param group Grouping variable to compare, for this plot there has to be three 11 | #' groups in the data 12 | #' @return Tibble object. 13 | #' @import dplyr 14 | #' @import tidyr 15 | #' @export 16 | #' @examples 17 | #' library(microbiome) 18 | #' library(microbiomeutilities) 19 | #' library(dplyr) 20 | #' data("zackular2014") 21 | #' p0 <- zackular2014 22 | #' prep_ternary(p0, group = "DiseaseState", abund.thres = 0.0001, level = "Genus", prev.thres = 0.25) 23 | #' @keywords visualization 24 | 25 | prep_ternary <- function(x, 26 | abund.thres = 0.0001, 27 | prev.thres = 0.1, 28 | group = NULL, 29 | level = "lowest") { 30 | p0.agg <- Sam_rep <- Abundance <- value <- taxa_df <- OTUID <- taxa_mean <- NULL 31 | p0.mr.cr <- level_var <- smas <- taxa_tern <- NULL 32 | 33 | if (level == "lowest") { 34 | p <- prep_tern_otu(x, 35 | abund.thres = abund.thres, 36 | prev.thres = prev.thres, 37 | group = group 38 | ) 39 | return(p) 40 | } else { 41 | # x <- p0 42 | p0.mr <- transform(x, "compositional") 43 | tax_table(p0.mr)[, colnames(tax_table(p0.mr))] <- 44 | gsub(tax_table(p0.mr)[, colnames(tax_table(p0.mr))], 45 | pattern = "[a-z]__", replacement = "" 46 | ) 47 | 48 | p0.agg <- aggregate_taxa(p0.mr, level = level) 49 | p0.mr.cr <- core(p0.agg, 50 | detection = abund.thres, 51 | prevalence = prev.thres 52 | ) 53 | # DT::datatable(tax_table(p0.mr.cr)) 54 | 55 | p0.mr <- merge_samples(p0.mr.cr, group = group) 56 | 57 | # extract taxonomy 58 | taxa_df <- tax_table(p0.mr) %>% 59 | as("matrix") %>% 60 | as.data.frame() 61 | taxa_df$OTUID <- rownames(taxa_df) 62 | # taxa_df$unique <- taxa_df[,unique] 63 | 64 | df <- phy_to_ldf(p0.mr, NULL) 65 | # df$level_var <- df[,unique] 66 | # variable goes to Sam_rep column 67 | taxa_mean <- df %>% 68 | group_by(unique, Sam_rep) %>% 69 | summarise(value = mean(Abundance)) 70 | 71 | taxa_tern <- taxa_mean %>% 72 | group_by(Sam_rep, unique) %>% 73 | # mutate(index=row_number()) %>% 74 | pivot_wider(names_from = Sam_rep, values_from = value) %>% 75 | left_join(taxa_df, by = "unique") 76 | 77 | return(taxa_tern) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /R/print_ps.R: -------------------------------------------------------------------------------- 1 | #' @title Overview of \code{\link{phyloseq-class}} 2 | #' @description Prints an overview \code{\link{phyloseq-class}}. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @return Prints information about the \code{\link{phyloseq-class}} object. 5 | #' @import utils 6 | #' @export 7 | #' @author Contact: Sudarshan A. Shetty \email{sudarshanshetty9@@gmail.com} 8 | #' @examples 9 | #' library(microbiomeutilities) 10 | #' data("zackular2014") 11 | #' pseq <- zackular2014 12 | #' print_ps(pseq) 13 | #' @keywords utilities 14 | 15 | print_ps <- function(x) { 16 | comp <- NULL 17 | ave <- round(sum(sample_sums(x)) / nsamples(x), 2) 18 | #message(paste0("01] object is ", class(x))) 19 | message(paste0("01] ntaxa = ", ntaxa(x))) 20 | message(paste0("02] nsamples = ", nsamples(x))) 21 | message(paste0("03] nsamplesvariables = ", length(sample_variables(x)))) 22 | message(paste0("04] nranks = ", length(colnames((tax_table(x)))))) 23 | message(paste0("05] Min. number of reads = ", min(sample_sums(x)))) 24 | message(paste0("06] Max. number of reads = ", max(sample_sums(x)))) 25 | message(paste0("07] Total number of reads = ", sum(sample_sums(x)))) 26 | message(paste0("08] Average number of reads = ", ave)) 27 | message(paste0("09] Median number of reads = ", median(sample_sums(x)))) 28 | message(paste0("10] Sparsity = ", length(which(abundances(x) == 29 | 0)) / length(abundances(x)))) 30 | message(paste0( 31 | "11] Number of singletons = ", 32 | length(taxa_sums(x)[taxa_sums(x) <= 33 | 1]) 34 | )) 35 | message(paste0( 36 | "12] % of taxa that are singletons 37 | (i.e. exactly one read detected across all samples) = ", 38 | mean(taxa_sums(x) == 1) * 100 39 | )) 40 | } 41 | -------------------------------------------------------------------------------- /R/sphagetti_utils.R: -------------------------------------------------------------------------------- 1 | 2 | plot_spaghetti_taxa <- function(x, 3 | select.taxa=NULL, 4 | xvar=NULL, 5 | group, 6 | line.bg.color="#8d99ae", 7 | bg.opacity=0.5, 8 | focus.color="brown3", 9 | ncol=NULL, 10 | nrow=NULL, 11 | focus.line.size=0.5, 12 | line.size=1) { 13 | 14 | if (is.null(xvar)){ 15 | stop("xvar cannot be empty") 16 | } 17 | OTUID <- name2 <- NULL 18 | phdf <- phy_to_ldf(x, transform.counts = NULL) 19 | 20 | # https://www.data-to-viz.com/caveat/spaghetti.html 21 | tmp <- phdf %>% 22 | mutate(name2=OTUID) 23 | 24 | tmp %>% 25 | ggplot(aes_string(x=xvar, y="Abundance")) + 26 | geom_line(data=tmp %>% dplyr::select(-OTUID), 27 | aes(group=name2), 28 | color=line.bg.color, size=line.size, alpha=bg.opacity) + 29 | geom_line(aes(color=OTUID), color=focus.color, size=focus.line.size)+ 30 | theme_biome_utils() + 31 | theme( 32 | legend.position="none" 33 | ) + 34 | facet_wrap(~OTUID, 35 | ncol = ncol, 36 | nrow=nrow) 37 | } 38 | 39 | 40 | ################################################################################ 41 | 42 | 43 | plot_spaghetti_sample <- function(x, 44 | select.taxa=NULL, 45 | xvar=NULL, 46 | group, 47 | line.bg.color="#8d99ae", 48 | bg.opacity=0.5, 49 | focus.color="brown3", 50 | ncol=NULL, 51 | nrow=NULL, 52 | focus.line.size=0.5, 53 | line.size=1){ 54 | 55 | if (is.null(xvar)){ 56 | stop("xvar cannot be empty") 57 | } 58 | 59 | OTUID <- group2 <- name2 <- select.tax <- NULL 60 | 61 | phdf <- phy_to_ldf(x, transform.counts =NULL) %>% 62 | filter(OTUID==select.taxa) 63 | 64 | # https://www.data-to-viz.com/caveat/spaghetti.html 65 | sub.var <- sym(group) 66 | 67 | tmp <- phdf %>% 68 | mutate(name2=OTUID, 69 | group2=!!sub.var) 70 | 71 | tmp %>% 72 | ggplot(aes_string(x=xvar, y="Abundance")) + 73 | geom_line(data=tmp %>% dplyr::select(-group2), 74 | aes(group=!!sub.var), 75 | color=line.bg.color, size=line.size, alpha=bg.opacity) + 76 | geom_line(aes(color=OTUID), color=focus.color, size=focus.line.size)+ 77 | theme_biome_utils() + 78 | theme( 79 | legend.position="none" 80 | ) + 81 | facet_wrap(~group2, 82 | ncol = ncol, 83 | nrow=nrow) 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /R/taxa_summary.R: -------------------------------------------------------------------------------- 1 | #' @title Give taxa summary at specified taxonomic level 2 | #' @description Data frame with mean, max, median standard deviation of relative abundance. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param level Taxonomic level for which summary is required 5 | #' @return returns a data frame with relative abundance summary. 6 | #' @import utils 7 | #' @export 8 | #' @author Contact: Sudarshan A. Shetty \email{sudarshanshetty9@@gmail.com} 9 | #' @examples 10 | #' \dontrun{ 11 | #' # Example data 12 | #' library(microbiomeutilities) 13 | #' data("zackular2014") 14 | #' p0 <- zackular2014 15 | #' p0.rel <- microbiome::transform(p0, "compositional") 16 | #' tx.sum1 <- taxa_summary(p0, "Phylum") 17 | #' 18 | #' tx.sum2 <- taxa_summary(p0.rel, "Phylum") 19 | #' } 20 | #' 21 | #' @keywords utilities 22 | 23 | taxa_summary <- function(x, level) { 24 | pobj <- taxdf <- pobj.ag <- otudf <- outputdf <- NULL 25 | 26 | pobj <- x 27 | 28 | # taxdf <- as.data.frame(pobj@tax_table) 29 | taxdf <- tax_table(pobj) %>% 30 | as("matrix") %>% 31 | as.data.frame() 32 | taxdf$OTU <- rownames(tax_table(pobj)) 33 | tax_table(pobj) <- tax_table(as.matrix(taxdf, quote = FALSE)) 34 | 35 | pobj.ag <- microbiome::aggregate_taxa(pobj, level) 36 | com <- all(sample_sums(pobj.ag) == 1) 37 | if (com == TRUE) { 38 | message("Data provided is compositional \n will use values directly") 39 | 40 | 41 | otudf2 <- as.data.frame(abundances(pobj.ag)) 42 | rownames(otudf2) <- tax_table(pobj.ag)[, level] 43 | } else { 44 | message("Data provided is not compositional \n will first transform") 45 | otudf2 <- as.data.frame(abundances(pobj.ag, "compositional")) 46 | 47 | rownames(otudf2) <- tax_table(pobj.ag)[, level] 48 | } 49 | 50 | output <- NULL 51 | for (j in 1:nrow(otudf2)) { 52 | x2 <- as.numeric(otudf2[j, ]) 53 | mx.rel <- max(x2, na.rm = TRUE) 54 | mean.rel <- mean(x2, na.rm = TRUE) 55 | med.rel <- median(x2, na.rm = TRUE) 56 | Std.dev <- sd(x2, na.rm = TRUE) 57 | 58 | output <- rbind(output, c(row.names(otudf2)[j], mx.rel, mean.rel, med.rel, Std.dev)) 59 | } 60 | 61 | outputdf <- as.data.frame(output) 62 | colnames(outputdf) <- c("Taxa", "Max.Rel.Ab", "Mean.Rel.Ab", "Median.Rel.Ab", "Std.dev") 63 | return(outputdf) 64 | } 65 | -------------------------------------------------------------------------------- /data/hmp2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/data/hmp2.rda -------------------------------------------------------------------------------- /data/zackular2014.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/data/zackular2014.rda -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-22-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-22-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-23-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-23-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-24-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-24-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-25-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-25-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-27-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-27-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-28-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-28-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-29-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/articles/microbiomeutilities_ts_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.17.1.1 2 | pkgdown: 2.0.6 3 | pkgdown_sha: ~ 4 | articles: 5 | microbiomeutilities: microbiomeutilities.html 6 | microbiomeutilities_ts: microbiomeutilities_ts.html 7 | last_built: 2022-11-23T08:04Z 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/plot_alpha_diversities-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/plot_alpha_diversities-1.png -------------------------------------------------------------------------------- /docs/reference/plot_read_distribution-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/plot_read_distribution-1.png -------------------------------------------------------------------------------- /docs/reference/plot_taxa_heatmap-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/plot_taxa_heatmap-1.png -------------------------------------------------------------------------------- /docs/reference/simple_heatmap-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/simple_heatmap-1.png -------------------------------------------------------------------------------- /docs/reference/taxa_distribution-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/docs/reference/taxa_distribution-1.png -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /articles/index.html 8 | 9 | 10 | /articles/microbiomeutilities.html 11 | 12 | 13 | /articles/microbiomeutilities_ts.html 14 | 15 | 16 | /authors.html 17 | 18 | 19 | /index.html 20 | 21 | 22 | /LICENSE-text.html 23 | 24 | 25 | /reference/abun_summary.html 26 | 27 | 28 | /reference/add_refseq.html 29 | 30 | 31 | /reference/aggregate_top_taxa2.html 32 | 33 | 34 | /reference/dominant_taxa.html 35 | 36 | 37 | /reference/find_samples_taxa.html 38 | 39 | 40 | /reference/format_to_besthit.html 41 | 42 | 43 | /reference/get_group_abundances.html 44 | 45 | 46 | /reference/get_microbiome_data.html 47 | 48 | 49 | /reference/get_tibble.html 50 | 51 | 52 | /reference/hmp2.html 53 | 54 | 55 | /reference/index.html 56 | 57 | 58 | /reference/join_otu_tax.html 59 | 60 | 61 | /reference/list_microbiome_data.html 62 | 63 | 64 | /reference/make_pairs.html 65 | 66 | 67 | /reference/peak-methods.html 68 | 69 | 70 | /reference/percent_classified.html 71 | 72 | 73 | /reference/phy_to_ldf.html 74 | 75 | 76 | /reference/plasticity.html 77 | 78 | 79 | /reference/plot_abund_prev.html 80 | 81 | 82 | /reference/plot_alpha_diversities.html 83 | 84 | 85 | /reference/plot_alpha_rcurve.html 86 | 87 | 88 | /reference/plot_area.html 89 | 90 | 91 | /reference/plot_diversity_stats.html 92 | 93 | 94 | /reference/plot_diversity_without_stats.html 95 | 96 | 97 | /reference/plot_diversity_with_stats.html 98 | 99 | 100 | /reference/plot_listed_taxa.html 101 | 102 | 103 | /reference/plot_ordination_utils.html 104 | 105 | 106 | /reference/plot_ordiplot_core.html 107 | 108 | 109 | /reference/plot_paired_abundances.html 110 | 111 | 112 | /reference/plot_read_distribution.html 113 | 114 | 115 | /reference/plot_select_taxa.html 116 | 117 | 118 | /reference/plot_spaghetti.html 119 | 120 | 121 | /reference/plot_taxa_boxplot.html 122 | 123 | 124 | /reference/plot_taxa_composition.html 125 | 126 | 127 | /reference/plot_taxa_cv.html 128 | 129 | 130 | /reference/plot_taxa_heatmap.html 131 | 132 | 133 | /reference/prep_ternary.html 134 | 135 | 136 | /reference/prep_tern_otu.html 137 | 138 | 139 | /reference/print_ps.html 140 | 141 | 142 | /reference/rarefy_util.html 143 | 144 | 145 | /reference/simple_heatmap.html 146 | 147 | 148 | /reference/taxa_distribution.html 149 | 150 | 151 | /reference/taxa_pooler_mcola.html 152 | 153 | 154 | /reference/taxa_summary.html 155 | 156 | 157 | /reference/theme_biome_utils.html 158 | 159 | 160 | /reference/zackular2014.html 161 | 162 | 163 | -------------------------------------------------------------------------------- /inst/NEWS: -------------------------------------------------------------------------------- 1 | 2 | Constant development is in process. 3 | 4 | CHANGES IN VERSION 1.00.16 (2021-04-14) 5 | o Fix `format_to_besthit` to return all slots present in input. 6 | 7 | CHANGES IN VERSION 1.00.15 (2021-01-21) 8 | o Fix `plot_taxa_cv` to deal with taxa_are_rows==FALSE. 9 | 10 | CHANGES IN VERSION 1.00.14 (2021-01-21) 11 | o Added utilities within `peak-methods`. 12 | 13 | CHANGES IN VERSION 1.00.12 (2021-01-18) 14 | o Removed prevalence option `plot_taxa_heatmap`. 15 | 16 | CHANGES IN VERSION 1.00.12 (2021-01-18) 17 | o Bug fix `format_to_besthit`. 18 | 19 | CHANGES IN VERSION 1.00.11 (2020-11-09) 20 | o Small improvement in error handling. 21 | o Phyloseq slots to tibble 22 | o `add_refseq` for storing ASV sequences 23 | 24 | CHANGES IN VERSION 1.00.10 (2020-11-02) 25 | o Improve `get_group_abundances` documentation and code 26 | 27 | CHANGES IN VERSION 1.00.09 (2020-10-21) 28 | o Added longitudinal page to website 29 | o Added new function plot_area 30 | o Added new function plot_paired_abundances 31 | o Added new function plot_spaghetti 32 | 33 | CHANGES IN VERSION 1.00.08 (2020-10-17) 34 | o Cosmetic updates 35 | 36 | CHANGES IN VERSION 1.00.07 (2020-10-15) 37 | o Update to `plot_taxa_heatmap` 38 | o Fixed `plot_abund_prev` options 39 | o Added `plot_alpha_rcurve` 40 | 41 | CHANGES IN VERSION 1.00.06 (2020-10-11) 42 | o Added new function dominant_taxa 43 | o Removed plot_ternary due to clash between ggplot2 and ggtern 44 | o Added new function find_samples_taxa 45 | 46 | CHANGES IN VERSION 1.00.05 (2020-10-11) 47 | o Added new function dominant_taxa 48 | o Added new function get_group_abundances 49 | o removed microbiome_pipeline 50 | 51 | CHANGES IN VERSION 1.00.04 (2020-10-11) 52 | o Added new function plasticity 53 | o modified theme_biome_utils 54 | 55 | CHANGES IN VERSION 1.00.03 (2020-10-04) 56 | o Added new function plot_ternary 57 | o Deprecated plot_select_taxa 58 | 59 | CHANGES IN VERSION 1.00.02 (2020-10-04) 60 | o Added new function plot_listed_taxa 61 | o Deprecated plot_select_taxa 62 | o Added option for half violin in boxplots 63 | 64 | CHANGES IN VERSION 1.00.01 (2020-10-03) 65 | o Added new function plot_abund_prev 66 | o Added new function simple_heatmap 67 | o Added new function taxa_distribution 68 | o Added a custom theme theme_biome_utils 69 | o Added gghalves to imports 70 | o Fixed microbiome_pipeline report 71 | 72 | CHANGES IN VERSION 1.00.00 (2020-10-01) 73 | o Version tested with R version 4.0.2 (2020-06-22) 74 | o Fix typos in documentation 75 | o Add prefix option to format_to_besthit 76 | o Edited phy_to_ldf to speed up conversion 77 | o Removed format_phyloseq function as it is redundant 78 | o Speedup taxa_summary function 79 | o Free up pheatmap option in plot_taxa_heatmap 80 | o Updated for more info from print_ps output 81 | o plot_taxa_boxplot now returns a faceted plot 82 | o Added new function plot_diversity_stats 83 | o R code styling styler::tidyverse_style() 84 | 85 | CHANGES IN VERSION 0.99.02 (2020-02-02) 86 | o diversities to alpha in plot_alpha_diversities function 87 | o fix typos in documentation 88 | 89 | CHANGES IN VERSION 0.99.01 (2018-04-09) 90 | o Cosmetic changes to report generator 91 | 92 | CHANGES IN VERSION 0.99.0 (2018-20-04) 93 | o Added print_ps (utility and alternative to print(ps)) 94 | o Added taxa_summary, returns table with mean, max, median, standard deviation relative abundance 95 | o Use of abundance to extract otu_table to avoid bugs 96 | o Fixes for other bugs in examples and documentation 97 | -------------------------------------------------------------------------------- /inst/extdata/beta_stats_test.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | calculate_beta_stats <- function(){ 5 | 6 | } 7 | library(tibble) 8 | library(microbiomeutilities) 9 | data("zackular2014") 10 | ps <- zackular2014 11 | ps <- microbiome::transform(ps, "compositional") 12 | dist.method= "bray" 13 | ps.dist <- distance(ps, "bray") 14 | 15 | group <- "DiseaseState" 16 | grp <- sym(group) 17 | get_metaf<- function(x){ 18 | df <- meta(x) %>% 19 | rownames_to_column("Var2") 20 | } 21 | ps.meta <- get_metaf(ps) 22 | 23 | ps.meta$group_var <- ps.meta[,group] 24 | 25 | dist_melt <- reshape2::melt( 26 | as.matrix(ps.dist), 27 | varnames = c("S1", "S2")) %>% 28 | mutate_if(is.factor, as.character) %>% 29 | left_join(ps.meta, by = c("S1" = "Var2")) %>% 30 | filter(S1 != S2) 31 | 32 | 33 | 34 | dist_within <- dist_melt %>% 35 | group_by(S2, group_var) %>% 36 | summarise(within.mean.dist=mean(value)) 37 | 38 | ggplot(dist_within, 39 | aes(group_var, within.mean.dist)) + 40 | geom_boxplot() 41 | 42 | 43 | dist_between <- dist_melt %>% 44 | left_join(ps.meta, 45 | by = c("S2" = "Var2"), 46 | suffix = c("_1", "_2")) %>% 47 | filter(group_var_1 != group_var_2) %>% 48 | mutate(comparison= paste0(group_var_1, " vs ", group_var_2)) %>% 49 | group_by(S2, comparison) %>% 50 | summarise(between.mean.dist=mean(value)) 51 | 52 | ggplot(dist_between, 53 | aes(comparison, between.mean.dist)) + 54 | geom_boxplot() + geom_point() + 55 | theme(axis.text.x = element_text(angle=90)) 56 | 57 | head(dist_between) 58 | 59 | table(dist_between$S2) 60 | head(dist_between) 61 | 62 | 63 | 64 | 65 | head(dist_within) 66 | -------------------------------------------------------------------------------- /inst/extdata/images/Anonymous-work-in-progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/images/Anonymous-work-in-progress.png -------------------------------------------------------------------------------- /inst/extdata/images/Rmarkdown_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/images/Rmarkdown_image.png -------------------------------------------------------------------------------- /inst/extdata/images/boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/images/boxplot.png -------------------------------------------------------------------------------- /inst/extdata/images/heatmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/images/heatmap.png -------------------------------------------------------------------------------- /inst/extdata/microbiomeHD_ref.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/microbiomeHD_ref.txt -------------------------------------------------------------------------------- /inst/extdata/microbiomeHD_ref.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extdata/microbiomeHD_ref.xlsx -------------------------------------------------------------------------------- /inst/extdata/theme_mutilties.R: -------------------------------------------------------------------------------- 1 | #' @title simple theme optimised for visual appeal and clarity 2 | #' @description simple theme optimised for visual appeal and clarity. 3 | #' @importFrom scales manual_pal 4 | #' @examples \dontrun{ 5 | #' 6 | #' library(microbiomeUtilities) 7 | #' data("biogeogut") 8 | #' p0 <- biogeogut 9 | 10 | #' select.taxa <- c("OTU-182933:Blautia", "OTU-183089:f__Clostridiaceae") 11 | #' tax_table(p0.f) 12 | #' 13 | #' p0.f <- format_to_besthit(p0) 14 | #' p <- plot_select_taxa(p0.f, select.taxa, "SampleType", "Paired", plot.type = "stripchart") 15 | #' p + theme_microutilities() + scale_colour_Publication() 16 | #' } 17 | #' @keywords utilities 18 | 19 | 20 | theme_mutilties <- function(){ 21 | 22 | theme_bw(base_size=12, base_family="") 23 | theme( 24 | text=element_text(family = "Helvetica", face = "plain", 25 | color = "black", size = 16, 26 | hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9, 27 | margin = margin(), debug = FALSE), 28 | 29 | plot.background = element_rect(colour = NA), 30 | plot.title = element_text(size = rel(1.2), colour = "black"), 31 | panel.background = element_rect(colour = NA), 32 | panel.grid.major = element_blank(), 33 | panel.grid.minor = element_blank(), 34 | panel.border = element_rect(colour = "#1a1a1a", fill=NA, size = 0.25), 35 | axis.ticks = element_line(colour = "#1a1a1a", size = 0.15), 36 | axis.text = element_text(size = rel(1.2), colour = "black"), 37 | axis.title.x = element_text(size = rel(1.0), colour = "black"), 38 | axis.title.y = element_text(size = rel(1.0), colour = "black", angle=90, vjust =2), 39 | axis.text.x = element_text(angle = 90), 40 | axis.title = element_text(size = rel(1)), 41 | legend.background = element_rect(fill = "white", color = "white"), 42 | legend.text = element_text(size = rel(1.0), colour = "black"), 43 | legend.key=element_blank(), 44 | legend.title = element_text(hjust = 0, colour = "black"), 45 | strip.background = element_rect(fill = "white", colour = NA), 46 | strip.text = element_text(colour = "black", size = rel(1.0)), 47 | complete = TRUE) 48 | 49 | } 50 | 51 | 52 | 53 | 54 | scale_color_mutilties <- function(...){ 55 | requireNamespace("scales") 56 | discrete_scale("colour","Publication",manual_pal(values = c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#BF5B17", "#666666", "#1B9E77", "#D95F02", 57 | "#7570B3", "#E7298A", "#66A61E", "#E6AB02", "#A6761D", "#666666", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", 58 | "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00", "#CAB2D6", "#6A3D9A", "#FFFF99", "#B15928", "#FBB4AE", "#B3CDE3", 59 | "#CCEBC5", "#DECBE4", "#FED9A6", "#FFFFCC", "#E5D8BD", "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", 60 | "#F4CAE4", "#E6F5C9", "#FFF2AE", "#F1E2CC", "#CCCCCC", "#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", 61 | "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", 62 | "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3", "#FDB462", "#B3DE69", "#FCCDE5", 63 | "#D9D9D9", "#BC80BD", "#CCEBC5", "#FFED6F")), ...) 64 | 65 | } 66 | 67 | 68 | scale_fill_mutilties <- function(...){ 69 | requireNamespace("scales") 70 | discrete_scale("fill","Publication",manual_pal(values = c("#7FC97F", "#BEAED4", "#FDC086", "#FFFF99", "#386CB0", "#F0027F", "#BF5B17", "#666666", "#1B9E77", "#D95F02", 71 | "#7570B3", "#E7298A", "#66A61E", "#E6AB02", "#A6761D", "#666666", "#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", 72 | "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00", "#CAB2D6", "#6A3D9A", "#FFFF99", "#B15928", "#FBB4AE", "#B3CDE3", 73 | "#CCEBC5", "#DECBE4", "#FED9A6", "#FFFFCC", "#E5D8BD", "#FDDAEC", "#F2F2F2", "#B3E2CD", "#FDCDAC", "#CBD5E8", 74 | "#F4CAE4", "#E6F5C9", "#FFF2AE", "#F1E2CC", "#CCCCCC", "#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", 75 | "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", 76 | "#E5C494", "#B3B3B3", "#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3", "#FDB462", "#B3DE69", "#FCCDE5", 77 | "#D9D9D9", "#BC80BD", "#CCEBC5", "#FFED6F")), ...) 78 | 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /inst/extras/build.sh: -------------------------------------------------------------------------------- 1 | 2 | # https://support.rstudio.com/hc/en-us/articles/200486518-Customizing-Package-Build-Options 3 | /usr/local/bin/R CMD BATCH document.R 4 | /usr/local/bin/R CMD build ../../ #--no-examples --no-build-vignettes 5 | /usr/local/bin/R CMD check microbiomeutilities_0.99.0.tar.gz # --no-build-vignettes #--no-examples 6 | /usr/local/bin/R CMD BiocCheck microbiomeutilities_0.99.0.tar.gz 7 | /usr/local/bin/R CMD INSTALL microbiomeutilities_0.99.0.tar.gz 8 | 9 | -------------------------------------------------------------------------------- /inst/extras/document.R: -------------------------------------------------------------------------------- 1 | library(devtools) 2 | document("../../") 3 | 4 | library(knitr) 5 | knit(input = "../../README.Rmd", output = "../../README.md") 6 | 7 | #setwd("../../") 8 | #library(pkgdown) 9 | #build_site() 10 | 11 | 12 | -------------------------------------------------------------------------------- /inst/extras/format_phylo_tax.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | format_phylo_tax <- function(pobj) { 4 | Domain <- Phylum <- Class <- Order <- Family <- Genus <- Species <- x <- y <- NULL 5 | 6 | x <- pobj 7 | 8 | if (ncol(tax_table(x)) == 6) { 9 | colnames(tax_table(x)) <- c("Domain", "Phylum", "Class", "Order", "Family", "Genus") 10 | } else if (ncol(tax_table(x)) == 7) { 11 | colnames(tax_table(x)) <- c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "Species") 12 | } else { 13 | stop("Taxonomic levels should be either 6 (untill genus) or 7 (until species) level") 14 | } 15 | 16 | 17 | tax_table(x)[, 1][is.na(tax_table(x)[, 1])] <- paste0(tolower(substring("kingdom", 1, 1)), "__") 18 | 19 | tax_table(x)[, 2][is.na(tax_table(x)[, 2])] <- paste0(tolower(substring("Phylum", 1, 1)), "__") 20 | 21 | tax_table(x)[, 3][is.na(tax_table(x)[, 3])] <- paste0(tolower(substring("Class", 1, 1)), "__") 22 | 23 | tax_table(x)[, 4][is.na(tax_table(x)[, 4])] <- paste0(tolower(substring("Order", 1, 1)), "__") 24 | 25 | tax_table(x)[, 5][is.na(tax_table(x)[, 5])] <- paste0(tolower(substring("Family", 1, 1)), "__") 26 | 27 | tax_table(x)[, 6][is.na(tax_table(x)[, 6])] <- paste0(tolower(substring("Genus", 1, 1)), "__") 28 | 29 | if (ncol(tax_table(x)) == 7) { 30 | tax_table(x)[, 7][is.na(tax_table(x)[, 7])] <- paste0(tolower(substring("Species", 1, 1)), "__") 31 | } 32 | 33 | 34 | y <- as.data.frame.matrix(tax_table(x)) 35 | 36 | 37 | y[, 1] <- gsub("k__", "", y[, 1]) 38 | y[, 2] <- gsub("p__", "", y[, 2]) 39 | y[, 3] <- gsub("c__", "", y[, 3]) 40 | y[, 4] <- gsub("o__", "", y[, 4]) 41 | y[, 5] <- gsub("f__", "", y[, 5]) 42 | y[, 6] <- gsub("g__", "", y[, 6]) 43 | 44 | if (ncol(tax_table(y)) == 7) { 45 | y[, 7] <- gsub("s__", "", y[, 7]) 46 | } 47 | 48 | if (ncol(tax_table(x)) == 6) { 49 | tax <- mutate(y, Domain, Domain = ifelse(Domain == "", "Unclassified", Domain)) %>% 50 | mutate(Phylum, 51 | Phylum = ifelse(Phylum == "", paste("k__", Domain, "_", rownames(y), sep = ""), Phylum) 52 | ) %>% 53 | mutate(Class, Class = ifelse(Class == "", ifelse(grepl("__", Phylum), Phylum, paste("c__", 54 | Phylum, "_", rownames(y), 55 | sep = "" 56 | )), Class)) %>% 57 | mutate(Order, Order = ifelse(Order == 58 | "", ifelse(grepl("__", Class), Class, paste("c__", Class, "_", rownames(y), sep = "")), Order)) %>% 59 | mutate(Family, Family = ifelse(Family == "", ifelse(grepl("__", Order), Order, paste("o__", 60 | Order, "_", rownames(y), 61 | sep = "" 62 | )), Family)) %>% 63 | mutate(Genus, Genus = ifelse(Genus == 64 | "", ifelse(grepl("__", Family), Family, paste("f__", Family, "_", rownames(y), sep = "")), 65 | Genus 66 | )) 67 | } else if (ncol(tax_table(x)) == 7) { 68 | tax <- mutate(y, Domain, Domain = ifelse(Domain == "", "Unclassified", Domain)) %>% 69 | mutate(Phylum, 70 | Phylum = ifelse(Phylum == "", paste("k__", Domain, "_", rownames(y), sep = ""), Phylum) 71 | ) %>% 72 | mutate(Class, Class = ifelse(Class == "", ifelse(grepl("__", Phylum), Phylum, paste("c__", 73 | Phylum, "_", rownames(y), 74 | sep = "" 75 | )), Class)) %>% 76 | mutate(Order, Order = ifelse(Order == 77 | "", ifelse(grepl("__", Class), Class, paste("c__", Class, "_", rownames(y), sep = "")), Order)) %>% 78 | mutate(Family, Family = ifelse(Family == "", ifelse(grepl("__", Order), Order, paste("o__", 79 | Order, "_", rownames(y), 80 | sep = "" 81 | )), Family)) %>% 82 | mutate(Genus, Genus = ifelse(Genus == 83 | "", ifelse(grepl("__", Family), Family, paste("f__", Family, "_", rownames(y), sep = "")), 84 | Genus 85 | )) %>% 86 | mutate(Species, Species = ifelse(Species == "", ifelse(grepl("__", Genus), Genus, 87 | paste("g__", Genus, "_", rownames(y), sep = "") 88 | ), Species)) 89 | } 90 | 91 | me <- as.data.frame(x@tax_table) 92 | me$domain <- tax$Domain 93 | me$Phylum <- tax$Phylum 94 | me$Class <- tax$Class 95 | me$Order <- tax$Order 96 | me$Family <- tax$Family 97 | me$Genus <- tax$Genus 98 | 99 | if (ncol(y) == 7) { 100 | me$Species <- tax$Species 101 | } 102 | 103 | taxmat <- as.matrix(me) 104 | new.tax <- tax_table(taxmat) 105 | tax_table(x) <- new.tax 106 | return(x) 107 | } 108 | -------------------------------------------------------------------------------- /inst/extras/hmp2.R: -------------------------------------------------------------------------------- 1 | library(microbiome) 2 | library(tidyr) 3 | set.seed(4235421) 4 | #BiocManager::install("HMP2Data") 5 | library(HMP2Data) 6 | ps <- momspi16S() 7 | df <- meta(ps) %>% 8 | filter(sample_body_site=="rectum") %>% 9 | group_by(subject_id) %>% tally(n()) %>% 10 | arrange(n) %>% 11 | filter(n>=10) 12 | 13 | ps.sub <- subset_samples(ps, subject_id %in% df$subject_id) 14 | ps.sub <- subset_samples(ps.sub, sample_body_site =="rectum") 15 | hmp2 <- prune_taxa(taxa_sums(ps.sub) > 0, ps.sub) 16 | sample_data(hmp2) <- sample_data(hmp2)[,c("size","sample_id","subject_id", 17 | "visit_number", "sample_body_site")] 18 | 19 | labels <- unique(meta(hmp2)$subject_id) 20 | 21 | sample_data(hmp2)$subject_id <- gsub(labels[1], "Participant_1",sample_data(hmp2)$subject_id) 22 | sample_data(hmp2)$subject_id <- gsub(labels[2], "Participant_2",sample_data(hmp2)$subject_id) 23 | sample_data(hmp2)$subject_id <- gsub(labels[3], "Participant_3",sample_data(hmp2)$subject_id) 24 | sample_data(hmp2)$subject_id <- gsub(labels[4], "Participant_4",sample_data(hmp2)$subject_id) 25 | sample_data(hmp2)$subject_id <- gsub(labels[5], "Participant_5",sample_data(hmp2)$subject_id) 26 | sample_data(hmp2)$subject_id <- gsub(labels[6], "Participant_6",sample_data(hmp2)$subject_id) 27 | sample_data(hmp2)$subject_id <- gsub(labels[7], "Participant_7",sample_data(hmp2)$subject_id) 28 | sample_data(hmp2)$subject_id <- gsub(labels[8], "Participant_8",sample_data(hmp2)$subject_id) 29 | sample_data(hmp2)$subject_id <- gsub(labels[9], "Participant_9",sample_data(hmp2)$subject_id) 30 | sample_data(hmp2)$subject_id <- gsub(labels[10], "Participant_10",sample_data(hmp2)$subject_id) 31 | sample_data(hmp2)$subject_id <- gsub(labels[11], "Participant_11",sample_data(hmp2)$subject_id) 32 | sample_data(hmp2)$subject_id <- gsub(labels[12], "Participant_12", sample_data(hmp2)$subject_id) 33 | sample_data(hmp2)$subject_id <- gsub(labels[13], "Participant_13", sample_data(hmp2)$subject_id) 34 | head(meta(hmp2)) 35 | save(hmp2, file = "hmp2.rda") 36 | -------------------------------------------------------------------------------- /inst/extras/physeq.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extras/physeq.rds -------------------------------------------------------------------------------- /inst/extras/plot_alpha_diversities.R: -------------------------------------------------------------------------------- 1 | #' @title Creat a plot for alpha diversities calculated using the \code{\link{microbiome}} package 2 | #' @description Utility plot function for diversity measures calcualted by \code{\link{microbiome}} package. 3 | #' @details Uses the \code{\link{microbiome}} package global function to calcualte diversities and then returns 4 | #' a plot. 5 | #' @param x \code{\link{phyloseq-class}} object. 6 | #' @param type Either diversities (Diversity Index) or dominance (Dominance Index) or evenness (Evenness Index). 7 | #' @param index.val see global function in \code{\link{microbiome}} package. 8 | #' @param variableA Variable of interested to be checked. This will also be used to color the plot 9 | #' @param palette Any of the \code{\link{RColorBrewer}} plettes. 10 | #' @param plot.type Three optons c("stripchart", "boxplot", "violin") 11 | #' @return \code{\link{ggplot}} object. This can be further modified using ggpubr. 12 | #' @import ggpubr 13 | #' @import microbiome 14 | #' @import RColorBrewer 15 | #' @importFrom reshape2 melt 16 | #' @export 17 | #' @examples 18 | #' library(microbiome) 19 | #' library(microbiomeutilities) 20 | #' data("zackular2014") 21 | #' p0 <- zackular2014 22 | #' p <- plot_alpha_diversities(p0, 23 | #' type = "diversities", 24 | #' index.val = "all", 25 | #' plot.type = "stripchart", 26 | #' variableA = "DiseaseState", 27 | #' palette = "jco") 28 | #' 29 | #' print(p) 30 | #' 31 | #' @keywords utilities 32 | #' index.val <- c("shannon, simpson") 33 | plot_alpha_diversities <- function(x, type, index.val = "all", plot.type, variableA, palette){ 34 | 35 | x1 <- x 36 | meta_df <- meta(x1) 37 | meta_df$sam_rep_nw <- rownames(meta_df) 38 | if (type == "diversities"){ 39 | 40 | adiv <- alpha(x, index = index.val) 41 | adiv$sam_rep_nw <- rownames(adiv) 42 | } 43 | else if (type == "dominance"){ 44 | adiv <- dominance(x, index = index.val) 45 | adiv$sam_rep_nw <- rownames(adiv) 46 | } 47 | else if (type == "evenness"){ 48 | message("This will take some time") 49 | adiv <- evenness(x, index = index.val) 50 | adiv$sam_rep_nw <- rownames(adiv) 51 | 52 | } else if (type == "global"){ 53 | adiv <- global(x, index = index.val) 54 | adiv$sam_rep_nw <- rownames(adiv) 55 | } 56 | adiv.nw <- melt(adiv) 57 | colnames(adiv.nw) <- c("sam_rep_nw","Diversity","div.val") 58 | meta_df_nw <- melt(meta_df) 59 | meta_adiv <- merge.data.frame(meta_df_nw, adiv.nw, by = "sam_rep_nw") 60 | 61 | if (plot.type == "boxplot"){ 62 | p <- ggboxplot(meta_adiv, x = variableA, y = "div.val", 63 | facet.by = "Diversity", add = "jitter", 64 | fill = variableA, 65 | palette = palette) 66 | 67 | p2 <- facet(p + theme_bw(), facet.by = "Diversity", 68 | short.panel.labs = FALSE, 69 | scales = "free", # Allow long labels in panels 70 | panel.labs.background = list(fill = "white")) 71 | 72 | } else if (plot.type == "stripchart"){ 73 | p <- ggstripchart(meta_adiv, x = variableA, y = "div.val", 74 | facet.by = "Diversity", 75 | color = variableA, 76 | palette = palette) 77 | 78 | p2 <- facet(p + theme_bw(), facet.by = "Diversity", 79 | short.panel.labs = FALSE, 80 | scales = "free", # Allow long labels in panels 81 | panel.labs.background = list(fill = "white")) 82 | } else if (plot.type == "violin"){ 83 | p <- ggviolin(meta_adiv, x = variableA, y = "div.val", 84 | facet.by = "Diversity", add = "jitter", 85 | fill = variableA, 86 | palette = palette) 87 | 88 | p2 <- facet(p + theme_bw(), facet.by = "Diversity", 89 | short.panel.labs = FALSE, 90 | scales = "free", # Allow long labels in panels 91 | panel.labs.background = list(fill = "white")) 92 | } 93 | 94 | return(p2) 95 | 96 | } 97 | 98 | -------------------------------------------------------------------------------- /inst/extras/plot_taxa_boxplot.R: -------------------------------------------------------------------------------- 1 | #' @title Taxonomic Composition Plot boxplot 2 | #' @description Plot taxon abundance for samples. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param taxonomic.level Merge the OTUs (for phyloseq object) into a higher taxonomic level. This has to be one from colnames(tax_table(x)). 5 | #' @param top.otu Top number of taxa to plot. 6 | #' @param VariableA Specify main variable of interest. This should be one of the variables in sample_variables(x). 7 | #' @param title title for the plot 8 | #' @param color any of the palette supported by ggpubr/RColorBrewer packages or user specified as c("red", "blue"). 9 | #' @return A \code{\link{ggplot}} plot object. 10 | #' @export 11 | #' @examples \dontrun{ 12 | #' # Example data 13 | #' library(microbiomeutilities) 14 | #' library(RColorBrewer) 15 | #' data("zackular2014") 16 | #' ps1 <- zackular2014 17 | #' pn <- plot_taxa_boxplot(ps1, 18 | #' taxonomic.level = "Phylum", 19 | #' top.otu = 3, VariableA = "DiseaseState", 20 | #' title = "Rel plot", color = "Set2") 21 | #' print(pn) 22 | #' } 23 | #' 24 | #' @keywords utilities 25 | 26 | plot_taxa_boxplot <- function(x, taxonomic.level, top.otu, VariableA, title, color = NULL){ 27 | 28 | Abundance <- NULL 29 | if (!is.null(x@phy_tree)){ 30 | 31 | message("For plotting purpuses the phy_tree will be removed") 32 | x@phy_tree = NULL 33 | } 34 | else { 35 | 36 | message("The phy_tree slot is empty, easy to make the plot") 37 | } 38 | 39 | taxic <- as.data.frame(x@tax_table); 40 | # using abundances function from microbiome as sometime otu_table can have taxa_are_rows FALSE in phyloseq 41 | otudf <- as.data.frame(abundances(x)); 42 | taxic$OTU <- row.names(otudf); 43 | taxmat <- as.matrix(taxic); 44 | new.tax <- tax_table(taxmat); 45 | tax_table(x) <- new.tax; 46 | 47 | 48 | # Merge the taxa at a higher taxonomic level 49 | 50 | if (!taxonomic.level == "OTU") { 51 | 52 | x <- aggregate_top_taxa(x, taxonomic.level, top = top.otu) 53 | 54 | } 55 | 56 | x1 <- transform(x, "compositional") 57 | 58 | x.df0 <- suppressWarnings(suppressMessages(phy_to_ldf(x1, transform.counts = NULL))) 59 | 60 | 61 | p <- ggplot(x.df0, aes(x =x.df0[,taxonomic.level], 62 | y=Abundance, 63 | fill = x.df0[,VariableA])) 64 | 65 | p <- p + geom_boxplot(position = position_dodge(1)) + 66 | geom_point(position = position_dodge(width = 0.75), 67 | aes(group = x.df0[, VariableA])) 68 | 69 | p <- p + ggtitle(title) + theme_bw() + 70 | theme(axis.text.x = element_text(face ="italic", 71 | angle = 90)) 72 | 73 | p <- p + ylab("Relative abundance") + xlab(taxonomic.level) + 74 | scale_fill_brewer(VariableA, 75 | palette = color) 76 | 77 | return(p) 78 | 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /inst/extras/taxa_summary.R: -------------------------------------------------------------------------------- 1 | #' @title Give taxa summary at specified taxonomic level 2 | #' @description Data frame with mean, max, median standard deviation of relative abundance. 3 | #' @param x \code{\link{phyloseq-class}} object 4 | #' @param level Taxonomic level for which summary is required 5 | #' @return returns a data frame with relative abundance summary. 6 | #' @import utils 7 | #' @export 8 | #' @author Contact: Sudarshan A. Shetty \email{sudarshanshetty9@@gmail.com} 9 | #' @examples \dontrun{ 10 | #' # Example data 11 | #' library(microbiomeutilities) 12 | #' data("zackular2014") 13 | #' p0 <- zackular2014 14 | #' p0.rel <- microbiome::transform(p0, "compositional") 15 | #' tx.sum1 <- taxa_summary(p0, "Phylum") 16 | #' 17 | #' tx.sum2 <- taxa_summary(p0.rel, "Phylum") 18 | #' } 19 | #' 20 | #' @keywords utilities 21 | 22 | taxa_summary <- function(x, level) { 23 | 24 | pobj <- taxdf <- pobj.ag <- otudf <- outputdf <- NULL 25 | 26 | pobj <- x 27 | 28 | taxdf <- as.data.frame(pobj@tax_table) 29 | taxdf$OTU <- rownames(tax_table(pobj)) 30 | tax_table(pobj) <- tax_table(as.matrix(taxdf, quote = FALSE)) 31 | 32 | pobj.ag <- microbiome::aggregate_taxa(pobj, level) 33 | com <- all(sample_sums(pobj.ag) == 1) 34 | if(com == TRUE){ 35 | 36 | message("Data provided is compositional \n will use values directly") 37 | 38 | 39 | otudf2 <- as.data.frame(abundances(pobj.ag)) 40 | rownames(otudf2) <- tax_table(pobj.ag)[,level] 41 | 42 | } else { 43 | 44 | message("Data provided is not compositional \n will first transform") 45 | otudf2 <- as.data.frame(abundances(pobj.ag, "compositional")) 46 | 47 | rownames(otudf2) <- tax_table(pobj.ag)[,level] 48 | } 49 | 50 | output=NULL 51 | for(j in 1:nrow(otudf2)){ 52 | x2=as.numeric(otudf2[j,]) 53 | mx.rel=max(x2) 54 | mean.rel=mean(x2) 55 | med.rel=median(x2) 56 | Std.dev=sd(x2) 57 | 58 | output=rbind(output,c(row.names(otudf2)[j],mx.rel, mean.rel,med.rel, Std.dev)) 59 | } 60 | 61 | outputdf <- as.data.frame(output) 62 | colnames(outputdf) <- c("Taxa", "Max.Rel.Ab", "Mean.Rel.Ab", "Median.Rel.Ab", "Std.dev") 63 | return(outputdf) 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /inst/extras/tern_eg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsud/microbiomeutilities/046a9f928f35fc2a02dd6cfb9175a0c7ddf65c4b/inst/extras/tern_eg.png -------------------------------------------------------------------------------- /inst/rmarkdown/templates/microbiomeanalysisQC/template.yaml: -------------------------------------------------------------------------------- 1 | name: microbiometemplateQC 2 | -------------------------------------------------------------------------------- /man/add_refseq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extensions.R 3 | \name{add_refseq} 4 | \alias{add_refseq} 5 | \title{Add refseq slot for dada2 based phyloseq object} 6 | \usage{ 7 | add_refseq(x, tag = "ASV") 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object with seqs as rownames.} 11 | 12 | \item{tag}{Provide name for Ids, Default="ASV".} 13 | } 14 | \value{ 15 | \code{\link{phyloseq-class}} object 16 | } 17 | \description{ 18 | Utility to add refseq slot for dada2 based phyloseq object. Here, the 19 | rownames which are unique sequences, are stored in refseq slot of phyloseq. Sequence 20 | ids are converted to ids using tag option. 21 | } 22 | \examples{ 23 | 24 | # ps <- add_refseq(p0,tag="ASV") 25 | # ps 26 | 27 | } 28 | \keyword{utilities} 29 | -------------------------------------------------------------------------------- /man/aggregate_top_taxa2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aggregate_top_taxa2.R 3 | \name{aggregate_top_taxa2} 4 | \alias{aggregate_top_taxa2} 5 | \title{Aggregate Top Taxa v2} 6 | \usage{ 7 | aggregate_top_taxa2(x, top, level) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{top}{Keep the top-n taxa, and merge the rest under the category 13 | 'Other'. Instead of top-n numeric this can also be a character vector 14 | listing the groups to combine.} 15 | 16 | \item{level}{Summarization level (from \code{rank_names(pseq)})} 17 | } 18 | \value{ 19 | \code{\link{phyloseq-class}} object 20 | } 21 | \description{ 22 | Summarize phyloseq: combine other than the most abundant taxa. 23 | } 24 | \details{ 25 | Backup from microbiome R pkg. This function is replaced by 26 | aggregate_rare function. 27 | } 28 | \examples{ 29 | data(dietswap) 30 | s <- aggregate_top_taxa2(dietswap, top = 3, "Phylum") 31 | } 32 | \references{ 33 | See citation('microbiome') 34 | } 35 | \author{ 36 | Contact: Leo Lahti \email{microbiome-admin@googlegroups.com} 37 | } 38 | \keyword{utilities} 39 | -------------------------------------------------------------------------------- /man/dominant_taxa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dominant_taxa.R 3 | \name{dominant_taxa} 4 | \alias{dominant_taxa} 5 | \title{Dominant Taxa} 6 | \usage{ 7 | dominant_taxa(x, level = NULL, group = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{level}{Taxonomic level uses microbiome::aggregate_taxa} 13 | 14 | \item{group}{Provide overview by groups. Default=NULL} 15 | } 16 | \value{ 17 | A list of two data frames/tibbles 18 | } 19 | \description{ 20 | Identify dominant taxa in each sample and give overview. 21 | } 22 | \details{ 23 | Identifies the dominant taxa in each sample and gives an overview of frequency 24 | and percent sample that are dominated by each taxon. Can be group wise or overall. 25 | } 26 | \examples{ 27 | library(microbiomeutilities) 28 | library(dplyr) 29 | data("zackular2014") 30 | p0 <- zackular2014 31 | x.d <- dominant_taxa(p0, level = "Genus", group = "DiseaseState") 32 | head(x.d$dominant_overview) 33 | } 34 | \keyword{utilities} 35 | -------------------------------------------------------------------------------- /man/find_samples_taxa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/find_samples_taxa.R 3 | \name{find_samples_taxa} 4 | \alias{find_samples_taxa} 5 | \title{Find samples dominated by specific taxa} 6 | \usage{ 7 | find_samples_taxa(x, taxa = NULL, relative = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{taxa}{this should match the rownames of otu_table(x)} 13 | 14 | \item{relative}{Logical. If TRUE will transform input to relative abundance. Default=FALSE} 15 | } 16 | \value{ 17 | A character with sample ids. 18 | } 19 | \description{ 20 | Finding the samples dominated by user provided taxa in a phyloseq object. 21 | This is useful especially if user suspects a taxa to be contaminant and wishes to identify 22 | which samples are dominated by the contaminant taxa. 23 | } 24 | \examples{ 25 | library(microbiomeutilities) 26 | data("zackular2014") 27 | p0 <- zackular2014 28 | p0.f <- aggregate_taxa(p0, "Genus") 29 | bac_dom <- find_samples_taxa(p0.f, taxa = "g__Bacteroides") 30 | # get samples dominated by g__Bacteroides 31 | ps.sub <- prune_samples(sample_names(p0.f) \%in\% bac_dom, p0.f) 32 | } 33 | \keyword{utilities} 34 | -------------------------------------------------------------------------------- /man/format_to_besthit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/format_to_besthit.R 3 | \name{format_to_besthit} 4 | \alias{format_to_besthit} 5 | \title{Formatting the \code{\link{phyloseq-class}} Object advanced} 6 | \usage{ 7 | format_to_besthit(x, prefix = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{prefix}{Prefered prefix e.g. OTU-d__denovo161:Roseburia or ASV-d__denovo161:Roseburia} 13 | } 14 | \value{ 15 | \code{\link{phyloseq-class}} object 16 | } 17 | \description{ 18 | Format the phyloseq object to add the best taxonomy in phyloseq object (tax_table and otu_table). 19 | } 20 | \details{ 21 | Most commonly it is observed that the taxonomy file has classification until a given taxonomic level. 22 | row.names for both tax_table and otu_table have best hit, until maximun genus level (species classification with short amplicons is a myth)is made available. This code is a 23 | slight modification of the code from \pkg{ampvis} \code{\link{phyloseq-class}}. 24 | Here, we directly take the phyloseq object as input and make the necessary formatting. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # Example data 29 | library(microbiome) 30 | library(microbiomeutilities) 31 | library(dplyr) 32 | data("zackular2014") 33 | p0 <- zackular2014 34 | p0.f <- format_to_besthit(p0, prefix = "OTU-") 35 | } 36 | } 37 | \keyword{utilities} 38 | -------------------------------------------------------------------------------- /man/get_group_abundances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_group_abundances.R 3 | \name{get_group_abundances} 4 | \alias{get_group_abundances} 5 | \title{Taxa abundance summary by group} 6 | \usage{ 7 | get_group_abundances(x, level, group, transform = "compositional") 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{level}{Taxonomic level uses microbiome::aggregate_taxa, if NULL with return OTU/ASVs 13 | level stats.} 14 | 15 | \item{group}{Provide overview by groups. Default=NULL and will return values for entire 16 | dataset, akin to taxa_summary.} 17 | 18 | \item{transform}{Either "compositional" or "counts". Default= compositional} 19 | } 20 | \value{ 21 | A data frames/ grouped tibble 22 | } 23 | \description{ 24 | Taxa abundance summary by group. Useful for description of microbiome. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | library(microbiomeutilities) 29 | data("zackular2014") 30 | p0 <- zackular2014 31 | get_group_abundances(p0, level = "Phylum", group = "DiseaseState") 32 | } 33 | } 34 | \keyword{utilities} 35 | -------------------------------------------------------------------------------- /man/get_microbiome_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_microbiome_data.R 3 | \name{get_microbiome_data} 4 | \alias{get_microbiome_data} 5 | \title{Download test microbiome data} 6 | \usage{ 7 | get_microbiome_data(disease, study) 8 | } 9 | \arguments{ 10 | \item{disease}{Disease of interest as shown in list_microbiome_data()} 11 | 12 | \item{study}{Name of the study as shown in list_microbiome_data()} 13 | } 14 | \value{ 15 | \code{\link{phyloseq-class}} object. 16 | } 17 | \description{ 18 | Test microbiome data in phyloseq format. 19 | } 20 | \details{ 21 | You can download few example datasets in phyloseq format from Duvallet et al 2017 https://www.nature.com/articles/s41467-017-01973-8.pdf?origin=ppub. The source file for these data is the microbiomedatarepo https://github.com/microsud/microbiomedatarepo. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | # Example data 26 | library(microbiome) 27 | library(microbiomeUtilities) 28 | list_microbiome_data() 29 | ps1 <- get_microbiome_data(disease = "CDI", "Schubert2014_CDI") 30 | print_ps(ps1) 31 | } 32 | } 33 | \keyword{utilities} 34 | -------------------------------------------------------------------------------- /man/get_tibble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extensions.R 3 | \name{get_tibble} 4 | \alias{get_tibble} 5 | \title{Convert Phyloseq Slots to Tibbles} 6 | \usage{ 7 | get_tibble(x, slot = "otu_table", column_id = "column_id") 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{slot}{Must be one of c("otu_table", "sam_data", "tax_table"). 13 | Default= "otu_table"} 14 | 15 | \item{column_id}{Provide name for the column which will hold the rownames of slot.} 16 | } 17 | \value{ 18 | A tibble 19 | } 20 | \description{ 21 | Utility to convert phyloseq slots to tibbles. 22 | } 23 | \examples{ 24 | library(microbiomeutilities) 25 | data("zackular2014") 26 | p0 <- zackular2014 27 | otu_tibble <- get_tibble(p0,slot="otu_table",column_id="OTUID") 28 | head(otu_tibble) 29 | } 30 | \keyword{utilities} 31 | -------------------------------------------------------------------------------- /man/hmp2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{hmp2} 5 | \alias{hmp2} 6 | \title{Test data 2} 7 | \format{ 8 | An object of class \code{"phyloseq"}. 9 | } 10 | \usage{ 11 | data("hmp2") 12 | } 13 | \description{ 14 | Data from a Stansfield J, Dozmorov M. "16s rRNA sequencing data 15 | from the Human Microbiome Project 2". Randomly choosen 13 particpants 16 | with multiple timepoints for rectum samples. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | library(microbiomeutilities) 21 | data("hmp2") 22 | pseq <- hmp2 23 | print(hmp2) 24 | } 25 | 26 | } 27 | \references{ 28 | \itemize{ 29 | \item{}{Stansfield J, Dozmorov M (2019). HMP2Data: 16s rRNA sequencing data 30 | from the Human Microbiome Project 2. R package version 1.1.0, 31 | \url{ https://bioconductor.org/packages/HMP2Data/}} 32 | } 33 | } 34 | \keyword{datasets} 35 | -------------------------------------------------------------------------------- /man/join_otu_tax.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extensions.R 3 | \name{join_otu_tax} 4 | \alias{join_otu_tax} 5 | \title{Join otu_table and tax_table to Tibble} 6 | \usage{ 7 | join_otu_tax(x, column_id = "OTUID") 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{column_id}{Provide name for the column which will hold the rownames of slot.} 13 | } 14 | \value{ 15 | A tibble 16 | } 17 | \description{ 18 | Utility to join otu_table and tax_table to tibble. 19 | } 20 | \examples{ 21 | library(microbiomeutilities) 22 | data("zackular2014") 23 | p0 <- zackular2014 24 | otu_tax <- join_otu_tax(p0,column_id = "OTUID") 25 | head(otu_tax) 26 | } 27 | \keyword{utilities} 28 | -------------------------------------------------------------------------------- /man/list_microbiome_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/list_microbiome_data.R 3 | \name{list_microbiome_data} 4 | \alias{list_microbiome_data} 5 | \title{List of available datasets} 6 | \usage{ 7 | list_microbiome_data(printtab = TRUE) 8 | } 9 | \arguments{ 10 | \item{printtab}{Print in console or not, defaut is TRUE and will print output.} 11 | } 12 | \description{ 13 | Data are used from Duvallet et al 2017 https://www.nature.com/articles/s41467-017-01973-8.pdf?origin=ppub. 14 | } 15 | \details{ 16 | Data for practice, also an example for importing mothur files from Baxtrer et al 2016. The source file for these data is the microbiomedatarepo https://github.com/microsud/microbiomedatarepo. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | library(microbiomeutilities) 21 | 22 | df <- list_microbiome_data(printtab = FALSE) 23 | } 24 | 25 | } 26 | \keyword{utilities} 27 | -------------------------------------------------------------------------------- /man/make_pairs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_utils.R 3 | \name{make_pairs} 4 | \alias{make_pairs} 5 | \title{Make pairs} 6 | \usage{ 7 | make_pairs(x) 8 | } 9 | \arguments{ 10 | \item{x}{list of vector to compare} 11 | } 12 | \description{ 13 | Creates a combination of variables 14 | for use with ggpubr::stat_compare_means. 15 | } 16 | \examples{ 17 | # library(microbiomeutilities) 18 | # data("zackular2014") 19 | # pseq <- zackular2014 20 | # comps <- make_pairs(meta(pseq)$DiseaseState) 21 | } 22 | \keyword{utilities} 23 | -------------------------------------------------------------------------------- /man/peak-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/peak_methods.R 3 | \name{peak-methods} 4 | \alias{peak-methods} 5 | \alias{peak_abundance} 6 | \alias{peak_taxonomy} 7 | \alias{peak_sample} 8 | \alias{peak_base} 9 | \alias{peak_abundance,phyloseq-method} 10 | \alias{peak_taxonomy,phyloseq-method} 11 | \alias{peak_sample,phyloseq-method} 12 | \alias{peak_base,ANY-method} 13 | \title{Peak into \code{\link[phyloseq]{phyloseq}} objects} 14 | \usage{ 15 | peak_abundance(x, nrows = 1:5, ncols = 1:5) 16 | 17 | peak_taxonomy(x, nrows = 1:5, ncols = 1:5) 18 | 19 | peak_sample(x, nrows = 1:5, ncols = 1:5) 20 | 21 | peak_base(x, nrows = 1:5, ncols = 1:5) 22 | 23 | \S4method{peak_abundance}{phyloseq}(x, nrows = 1:5, ncols = 1:5) 24 | 25 | \S4method{peak_taxonomy}{phyloseq}(x, nrows = 1:5, ncols = 1:5) 26 | 27 | \S4method{peak_sample}{phyloseq}(x, nrows = 1:5, ncols = 1:5) 28 | 29 | \S4method{peak_base}{ANY}(x, nrows = 1:5, ncols = 1:5) 30 | } 31 | \arguments{ 32 | \item{x}{a 33 | \code{\link[phyloseq]{phyloseq}} or \code{data.frame} or 34 | \code{matrix} object} 35 | 36 | \item{nrows}{number of rows, to be specified as numeric e.g. 1, or sequence 37 | of numeric specified as 1:5. to return first to fifth row.} 38 | 39 | \item{ncols}{number of cols, to be specified as numeric e.g. 1, or sequence 40 | of numeric specified as 1:5 to return first to fifth col.} 41 | } 42 | \value{ 43 | Print user specified rows and columns 44 | } 45 | \description{ 46 | These functions work on \code{otu_table}, \code{tax_table}, \code{sample_data} 47 | or on \code{data.frame} and \code{matrix}. 48 | 49 | \code{peak_abundance} returns, user specified number of rows and columns 50 | for \code{otu_table}. 51 | 52 | #' \code{peak_taxonomy} returns, user specified number of rows and columns 53 | for \code{tax_table}. 54 | 55 | \code{peak_sample} returns, user specified number of rows and columns 56 | for \code{sample_data}. 57 | 58 | \code{peak_base} returns, user specified number of rows and columns 59 | for \code{data.frame} and \code{matrix}. 60 | } 61 | \examples{ 62 | data("zackular2014") 63 | 64 | peak_abundance(zackular2014, nrows=1:3, ncols = 1:3) 65 | 66 | peak_taxonomy(zackular2014, nrows=1:3, ncols = 1:3) 67 | 68 | peak_sample(zackular2014, nrows=1:3, ncols = 1:3) 69 | 70 | dat.frm <- meta(zackular2014) 71 | # specify specific columns 72 | peak_base(dat.frm, nrows=1:3, ncols = c(1, 3, 4)) 73 | 74 | matrix_ab <- abundances(zackular2014) 75 | peak_base(matrix_ab, nrows=1:3, ncols = 1:3) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /man/percent_classified.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/percent_classified.R 3 | \name{percent_classified} 4 | \alias{percent_classified} 5 | \title{Summarize the percent taxa classification for \code{\link{phyloseq-class}}} 6 | \usage{ 7 | percent_classified(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | } 12 | \value{ 13 | Table with information on percent OTUs classified. 14 | } 15 | \description{ 16 | Summarize the percent taxa classification for \code{\link{phyloseq-class}}. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | library(microbiomeutilities) 21 | data("zackular2014") 22 | pseq <- zackular2014 23 | percent_classified(pseq) 24 | } 25 | 26 | } 27 | \author{ 28 | Contact: Sudarshan A. Shetty \email{sudarshanshetty9@gmail.com} 29 | } 30 | \keyword{utilities} 31 | -------------------------------------------------------------------------------- /man/phy_to_ldf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phy_to_ldf.R 3 | \name{phy_to_ldf} 4 | \alias{phy_to_ldf} 5 | \title{Convert \code{\link{phyloseq-class}} object to long data format} 6 | \usage{ 7 | phy_to_ldf(x, transform.counts) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{transform.counts}{Data transform to be used in plotting 13 | (but not in sample/taxon ordering). The options are 'Z-OTU', 'Z-Sample', 14 | 'log10' and 'compositional'. See the \code{\link{transform}} function} 15 | } 16 | \value{ 17 | A data frame in long format with appropriate transfomation if requested 18 | } 19 | \description{ 20 | An alternative to psmelt function from \code{\link{phyloseq-class}} object. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | # Example data 25 | library(microbiomeutilities) 26 | data("zackular2014") 27 | pseq <- zackular2014 28 | pseq_df <- phy_to_ldf(pseq, transform.counts = NULL) 29 | } 30 | } 31 | \keyword{utilities} 32 | -------------------------------------------------------------------------------- /man/plasticity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plasticity.R 3 | \name{plasticity} 4 | \alias{plasticity} 5 | \title{Plasticity} 6 | \usage{ 7 | plasticity(x, dist.method = "bray", participant.col) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{dist.method}{Any of the methods supported by phyloseq::distance or correlation method cor()} 13 | 14 | \item{participant.col}{Column name with participant IDs} 15 | } 16 | \value{ 17 | plot 18 | } 19 | \description{ 20 | Calculated difference in microbiota composition for each individual between 21 | two timepoints. 22 | } 23 | \details{ 24 | Using a beta diversity metrics or correlation matrix to identify variability in 25 | microbiota of an individual. The code is slight modification from Grembi et. al. see ref below. 26 | This is useful for instance if one wants to quantiify changes in microbiota before and after 27 | a treatment, dietary modulation, antibiotic treatment, etc. The choice of index is important. 28 | For example, Bray-Curtis dissimilarity, the higher values mean higher plasticity/variability. 29 | On the contrary, higer spearman correlation values mean lower plasticity. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | library(microbiome) 34 | library(microbiomeutilities) 35 | library(dplyr) 36 | library(ggpubr) 37 | data(peerj32) 38 | pseq <- peerj32$phyloseq 39 | pseq.rel <- microbiome::transform(pseq, "compositional") 40 | pl <- plasticity(pseq.rel, participant.col = "subject") 41 | } 42 | } 43 | \references{ 44 | \itemize{ 45 | \item{}{Grembi, J.A., Nguyen, L.H., Haggerty, T.D. et al. Gut microbiota plasticity is 46 | correlated with sustained weight loss on a low-carb or low-fat dietary intervention. 47 | Sci Rep 10, 1405 (2020).https://www.nature.com/articles/s41598-020-58000-y 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/plot_abund_prev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_abund_prev.R 3 | \name{plot_abund_prev} 4 | \alias{plot_abund_prev} 5 | \title{Mean Abundance-Prevalence relation} 6 | \usage{ 7 | plot_abund_prev( 8 | x, 9 | lower.conf = 0.025, 10 | upper.conf = 0.975, 11 | bs.iter = 99, 12 | color = "steelblue", 13 | dot.opacity = 0.5, 14 | dot.size = 2, 15 | label.core = FALSE, 16 | label.size = NULL, 17 | label.opacity = NULL, 18 | label.color = "grey70", 19 | mean.abund.thres = NULL, 20 | mean.prev.thres = NULL, 21 | log.scale = TRUE, 22 | nudge.label = NULL, 23 | ... 24 | ) 25 | } 26 | \arguments{ 27 | \item{x}{\code{\link{phyloseq-class}} object} 28 | 29 | \item{lower.conf}{Lower confidence interval =0.025} 30 | 31 | \item{upper.conf}{Upper confidence interval =0.975} 32 | 33 | \item{bs.iter}{Number of bootstrap iterations =99} 34 | 35 | \item{color}{taxa level to color. Preferably at phylum or just a single color} 36 | 37 | \item{dot.opacity}{Numeric for ggplot alpha. Default is 0.5} 38 | 39 | \item{dot.size}{Numeric size of point} 40 | 41 | \item{label.core}{Logical default is FALSE} 42 | 43 | \item{label.size}{If label_core is TRUE specify text size. 44 | Default is NULL} 45 | 46 | \item{label.opacity}{Numeric for ggplot alpha. Defualt is NULL} 47 | 48 | \item{label.color}{Color for labels. Default="grey70"} 49 | 50 | \item{mean.abund.thres}{If label_core is TRUE specify mean 51 | abundance threshold. Default is NULL} 52 | 53 | \item{mean.prev.thres}{If label_core is TRUE specify mean 54 | prevalence threshold. Default is NULL} 55 | 56 | \item{log.scale}{Plot log10 scale. Default is TRUE 57 | abundance criteria. Default is NULL} 58 | 59 | \item{nudge.label}{Argument to pass to ggrepel::geom_text_repel Default is NULL} 60 | 61 | \item{...}{Arguments to pass to sample() function.} 62 | } 63 | \value{ 64 | A \code{\link{ggplot}} plot object. 65 | } 66 | \description{ 67 | Plots Mean Abundance-Prevalence for taxa. Mean abundance, mean prevalence, 68 | and upper and lower confidence interval for each taxa is calculated by random subsampling. 69 | } 70 | \details{ 71 | Check if there are spurious OTUs/ASVs. 72 | } 73 | \examples{ 74 | \dontrun{ 75 | # Example data 76 | library(microbiomeutilities) 77 | asv_ps <- zackular2014 78 | asv_ps <- microbiome::transform(asv_ps, "compositional") 79 | asv_ps <- core(asv_ps, detection = 0.0001, prevalence = 0.5) 80 | asv_ps <- format_to_besthit(asv_ps) 81 | set.seed(2349) 82 | p_v <- plot_abund_prev(asv_ps, size = 20, replace = TRUE) + 83 | geom_vline(xintercept = 0.75, lty = "dashed", alpha = 0.7) + 84 | geom_hline(yintercept = 0.01, lty = "dashed", alpha = 0.7) + 85 | scale_color_brewer(palette = "Paired") 86 | p_v 87 | } 88 | 89 | } 90 | \keyword{analysis} 91 | \keyword{visualization} 92 | -------------------------------------------------------------------------------- /man/plot_alpha_diversities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_alpha_diversities.R 3 | \name{plot_alpha_diversities} 4 | \alias{plot_alpha_diversities} 5 | \title{Creat a plot for alpha diversities calculated using the \code{\link{microbiome}} package} 6 | \usage{ 7 | plot_alpha_diversities( 8 | x, 9 | type, 10 | index.val = "all", 11 | plot.type, 12 | variableA, 13 | palette 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{\code{\link{phyloseq-class}} object.} 18 | 19 | \item{type}{Either alpha (Diversity Index) or dominance (Dominance Index) or evenness (Evenness Index)} 20 | 21 | \item{index.val}{see global function in \code{\link{microbiome}} package} 22 | 23 | \item{plot.type}{Three optons c("stripchart", "boxplot", "violin")} 24 | 25 | \item{variableA}{Variable of interested to be checked. This will also be used to color the plot} 26 | 27 | \item{palette}{Any of the \code{\link{RColorBrewer}} plettes} 28 | } 29 | \value{ 30 | \code{\link{ggplot}} object. This can be further modified using ggpubr 31 | } 32 | \description{ 33 | Utility plot function for diversity measures calcualted by \code{\link{microbiome}} package. 34 | } 35 | \details{ 36 | Uses the \code{\link{microbiome}} package global function to calculate diversities and then returns 37 | a plot. 38 | } 39 | \examples{ 40 | library(microbiome) 41 | library(microbiomeutilities) 42 | data("zackular2014") 43 | p0 <- zackular2014 44 | p <- plot_alpha_diversities(p0, 45 | type = "dominance", 46 | index.val = "all", 47 | plot.type = "stripchart", 48 | variableA = "DiseaseState", 49 | palette = "jco" 50 | ) 51 | 52 | print(p) 53 | } 54 | \keyword{<-} 55 | \keyword{analysis} 56 | \keyword{c("shannon,} 57 | \keyword{index.val} 58 | \keyword{simpson")} 59 | \keyword{visualization} 60 | -------------------------------------------------------------------------------- /man/plot_alpha_rcurve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_alpha_rcurve.R 3 | \name{plot_alpha_rcurve} 4 | \alias{plot_alpha_rcurve} 5 | \title{Rarefaction curves for alpha diversity indices} 6 | \usage{ 7 | plot_alpha_rcurve( 8 | x, 9 | index = "observed", 10 | subsamples = c(100, 1000, 2000, 3000, 4000, 5000), 11 | lower.conf = 0.025, 12 | upper.conf = 0.975, 13 | group = NULL, 14 | linetype.main = 1, 15 | line.opacity.main = 0.5, 16 | linetype.type = 2, 17 | line.opacity.type = 0.25, 18 | type = "CI", 19 | label.min = TRUE, 20 | label.size = 3, 21 | label.color = "grey70" 22 | ) 23 | } 24 | \arguments{ 25 | \item{x}{\code{\link{phyloseq-class}} object} 26 | 27 | \item{index}{Default:: "observed",} 28 | 29 | \item{subsamples}{Default: c(100,1000, 2000, 3000, 4000, 5000)} 30 | 31 | \item{lower.conf}{Default: 0.025. If type=CI} 32 | 33 | \item{upper.conf}{Default: 0.975.} 34 | 35 | \item{group}{Default: NULL} 36 | 37 | \item{linetype.main}{For ggplot line type for line by group. Default: 1} 38 | 39 | \item{line.opacity.main}{For ggplot alpha to determine opacity for line by group. Default: 0.5} 40 | 41 | \item{linetype.type}{For ggplot line type for line CI or SD. Default: 2} 42 | 43 | \item{line.opacity.type}{For ggplot line type to determine opacity for line CI or SD. Default: 0.25} 44 | 45 | \item{type}{Either CI (confidence interval) or SD (Standard deviation) Default: CI} 46 | 47 | \item{label.min}{TRUE or FALSE. Default: TRUE} 48 | 49 | \item{label.size}{Label min size} 50 | 51 | \item{label.color}{Label min color} 52 | } 53 | \description{ 54 | Calculates alpha diversity idenx at varying sampling units (sequencing depth). 55 | } 56 | \examples{ 57 | \dontrun{ 58 | library(microbiomeutilities) 59 | data("zackular2014") 60 | p0 <- zackular2014 61 | # e.g. to make range of 62 | # subsamples <- seq(0, 5000, by=100)[-1] 63 | p <- plot_alpha_rcurve(p0, index="observed", 64 | lower.conf = 0.025, upper.conf = 0.975, 65 | group="DiseaseState") + 66 | scale_color_brewer(palette = "Paired") + 67 | scale_fill_brewer(palette = "Paired") 68 | print(p ) 69 | } 70 | } 71 | \keyword{analysis} 72 | \keyword{visualization} 73 | -------------------------------------------------------------------------------- /man/plot_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_area.R 3 | \name{plot_area} 4 | \alias{plot_area} 5 | \title{Area plot} 6 | \usage{ 7 | plot_area( 8 | x, 9 | xvar = NULL, 10 | level = NULL, 11 | facet.by = NULL, 12 | fill.colors = brewer.pal(6, "Paired"), 13 | abund.thres = 0.001, 14 | prev.thres = 0.5, 15 | ncol = 5, 16 | nrow = 5 17 | ) 18 | } 19 | \arguments{ 20 | \item{x}{\code{\link{phyloseq-class}} object.} 21 | 22 | \item{xvar}{Column name to plot on x-axis.} 23 | 24 | \item{level}{Taxonomic level. OTU/ASV level not supported.} 25 | 26 | \item{facet.by}{Column with variable that has multiple measurements.} 27 | 28 | \item{fill.colors}{brewer.pal(6,"Paired"). Specify colors.} 29 | 30 | \item{abund.thres}{= 0.001 check \code{\link{microbiome}} package aggregate_rare function.} 31 | 32 | \item{prev.thres}{= 0.1 check \code{\link{microbiome}} package aggregate_rare function.} 33 | 34 | \item{ncol}{wrap, specify number of columns.} 35 | 36 | \item{nrow}{wrap, specify number of rows.} 37 | } 38 | \value{ 39 | \code{\link{ggplot}} object. 40 | } 41 | \description{ 42 | Create an area plot for longitudinal samples 43 | with \code{\link{ggplot2}} package. 44 | } 45 | \examples{ 46 | \dontrun{ 47 | library(microbiomeutilities) 48 | data("hmp2") 49 | ps <- hmp2 50 | ps.rel <- microbiome::transform(ps, "compositional") 51 | p <- plot_area(ps.rel, xvar="visit_number", 52 | level = "Phylum", 53 | facet.by = "subject_id", 54 | fill.colors=brewer.pal(6,"Paired")) 55 | } 56 | 57 | } 58 | \keyword{visualization} 59 | -------------------------------------------------------------------------------- /man/plot_diversity_stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_diversity_stats.R 3 | \name{plot_diversity_stats} 4 | \alias{plot_diversity_stats} 5 | \title{Diversity plot with stats} 6 | \usage{ 7 | plot_diversity_stats( 8 | x, 9 | index, 10 | group = NULL, 11 | group.colors = c("brown3", "steelblue"), 12 | dot.opacity = 0.25, 13 | box.opacity = 0.25, 14 | violin.opacity = 0.5, 15 | group.order = NULL, 16 | stats = TRUE, 17 | label.format = "p.format", 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{\code{\link{phyloseq-class}} object} 23 | 24 | \item{index}{diversity index. Calculated using microbiome::alpha} 25 | 26 | \item{group}{Grouping variable to compare} 27 | 28 | \item{group.colors}{Colors for plotting groups} 29 | 30 | \item{dot.opacity}{for ggplot alpha to determine opacity for points} 31 | 32 | \item{box.opacity}{for ggplot alpha to determine opacity for box} 33 | 34 | \item{violin.opacity}{for ggplot alpha to determine opacity for violin} 35 | 36 | \item{group.order}{Default is NULL. a list specifing order of x-axis.} 37 | 38 | \item{stats}{Logical TRUE or FALSE. Calls ggpubr::stat_compare_means.} 39 | 40 | \item{label.format}{For ggpubr::stat_compare_means "p.signif" 41 | E.g. c("H","CRC","nonCRC")} 42 | 43 | \item{...}{params for ggpubr::stat_compare_means} 44 | } 45 | \description{ 46 | Diversity plot with stats 47 | } 48 | \examples{ 49 | \dontrun{ 50 | library(microbiomeutilities) 51 | library(ggpubr) 52 | data("zackular2014") 53 | p0 <- zackular2014 54 | mycols <- c("brown3", "steelblue", "grey50") 55 | p.m <- plot_diversity_stats(p0, 56 | group = "DiseaseState", 57 | index = "diversity_shannon", 58 | group.order = c("H", "CRC", "nonCRC"), 59 | group.colors = mycols 60 | ) 61 | print(p.m) 62 | } 63 | } 64 | \keyword{analysis} 65 | \keyword{visualization} 66 | -------------------------------------------------------------------------------- /man/plot_listed_taxa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_listed_taxa.R 3 | \name{plot_listed_taxa} 4 | \alias{plot_listed_taxa} 5 | \title{A boxplot for user specified list of taxa} 6 | \usage{ 7 | plot_listed_taxa( 8 | x, 9 | select.taxa, 10 | group, 11 | group.colors, 12 | dot.opacity = 0.25, 13 | box.opacity = 0.25, 14 | group.order = NULL, 15 | add.violin = TRUE, 16 | violin.opacity = 0.25, 17 | panel.arrange = "grid", 18 | ncol = NULL, 19 | nrow = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{\code{\link{phyloseq-class}} object.} 24 | 25 | \item{select.taxa}{a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024").} 26 | 27 | \item{group}{Grouping variable to compare} 28 | 29 | \item{group.colors}{Colors for plotting groups} 30 | 31 | \item{dot.opacity}{For ggplot alpha to determine opacity for points} 32 | 33 | \item{box.opacity}{For ggplot alpha to determine opacity for box} 34 | 35 | \item{group.order}{Default is NULL. a list specifing order of x-axis.} 36 | 37 | \item{add.violin}{Loical. If half violoin to the added. Default=TRUE} 38 | 39 | \item{violin.opacity}{If add.violin=TRUE, opacity for violin.} 40 | 41 | \item{panel.arrange}{panels "grid" or "wrap" ggplot's facet_XXX} 42 | 43 | \item{ncol}{if wrap, specify number of columns.} 44 | 45 | \item{nrow}{if wrap, specify number of rows.} 46 | } 47 | \value{ 48 | \code{\link{ggplot}} object. This can be further modified using ggpubr. 49 | } 50 | \description{ 51 | User specifed OTUs are plotted. 52 | } 53 | \details{ 54 | Useful for instances where user is interested only in some OTUs. For example OTUs 55 | reported to be significantly diferent. This can also be used at higher taxonomic 56 | levels, output from phyloseq::tax_glom or microbiome::aggregate_taxa. 57 | } 58 | \examples{ 59 | \dontrun{ 60 | # Example data 61 | library(microbiome) 62 | library(microbiomeutilities) 63 | data("zackular2014") 64 | p0 <- zackular2014 65 | p0.f <- format_to_besthit(p0) 66 | select.taxa <- c("OTU-d__denovo31:Dorea", "OTU-d__denovo24:Blautia") 67 | mycols <- c("brown3", "steelblue", "grey50") 68 | p <- plot_listed_taxa(p0.f, select.taxa, 69 | group = "DiseaseState", 70 | add.violin = TRUE, 71 | group.colors = mycols 72 | ) 73 | print(p) 74 | } 75 | } 76 | \keyword{visualization} 77 | -------------------------------------------------------------------------------- /man/plot_ordination_utils.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_ordination_utils.R 3 | \name{plot_ordination_utils} 4 | \alias{plot_ordination_utils} 5 | \title{Plot species loading with ordinations} 6 | \usage{ 7 | plot_ordination_utils( 8 | x, 9 | ordiObject, 10 | color.opt = NULL, 11 | plot.arrow = TRUE, 12 | scale.arrow = NULL, 13 | top.taxa = 5 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{\code{\link{phyloseq-class}} object} 18 | 19 | \item{ordiObject}{Output of ordinate from package phyloseq. Only NMDS/CCA and Bray supported.} 20 | 21 | \item{color.opt}{Variable of interest from metadata.} 22 | 23 | \item{plot.arrow}{If arrow should be plotted for species either TRUE or FALSE.} 24 | 25 | \item{scale.arrow}{If arrow is plotted a constant to multiply axis values for clearing visualisations.} 26 | 27 | \item{top.taxa}{Top varying taxa to plot, default is 5.} 28 | } 29 | \value{ 30 | plot 31 | } 32 | \description{ 33 | This function extends the plot_ordination function of \code{\link{phyloseq}}to highlight the top taxa loadings 34 | on the species ordination. 35 | } 36 | \details{ 37 | This function is useful for visualizing specifc taxa that could be important in explaining variations in ordinations. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | 42 | library(microbiomeutilities) 43 | library(RColorBrewer) 44 | data("zackular2014") 45 | ps1 <- zackular2014 46 | ps2 <- tax_glom(ps1, "Genus") 47 | ps2f <- format_to_besthit(ps2) 48 | orddi <- ordinate(ps2f, method = "CCA", distance = "bray") 49 | p <- plot_ordination_utils(ps2f, orddi, 50 | color = "DiseaseState", plot.arrow = TRUE, 51 | scale.arrow = 1.3, top.taxa = 5 52 | ) 53 | print(p) 54 | } 55 | } 56 | \keyword{utilities} 57 | -------------------------------------------------------------------------------- /man/plot_ordiplot_core.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_ordiplot_core.R 3 | \name{plot_ordiplot_core} 4 | \alias{plot_ordiplot_core} 5 | \title{Plotting core microbiota on ordinations} 6 | \usage{ 7 | plot_ordiplot_core( 8 | x, 9 | ordiObject, 10 | prevalences, 11 | detections, 12 | min.prevalence, 13 | color.opt, 14 | shape, 15 | Samples = c(TRUE, FALSE) 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{\code{\link{phyloseq-class}} object} 20 | 21 | \item{ordiObject}{Output of ordinate from package phyloseq. Only NMDS and Bray supported.} 22 | 23 | \item{prevalences}{Prevalences as supported by microbiome package.} 24 | 25 | \item{detections}{Detections as supported by microbiome package.} 26 | 27 | \item{min.prevalence}{Minimum prevalence value to plot.} 28 | 29 | \item{color.opt}{Variable of interest from metadata.} 30 | 31 | \item{shape}{Variable of interest from metadata.} 32 | 33 | \item{Samples}{c("TRUE" or "FALSE")} 34 | } 35 | \value{ 36 | plot 37 | } 38 | \description{ 39 | This function will plot the ordaination along with highligthing the core microbes 40 | on the species ordination. 41 | } 42 | \details{ 43 | This function is useful for visualizing core taxa in a 2D ordination plot. 44 | } 45 | \examples{ 46 | \dontrun{ 47 | 48 | library(microbiomeutilities) 49 | library(RColorBrewer) 50 | data("zackular2014") 51 | p0 <- zackular2014 52 | ps1 <- format_to_besthit(p0) 53 | ps1 <- subset_samples(ps1, DiseaseState == "H") 54 | ps1 <- prune_taxa(taxa_sums(ps1) > 0, ps1) 55 | prev.thres <- seq(.05, 1, .05) 56 | det.thres <- 10^seq(log10(1e-4), log10(.2), length = 10) 57 | pseq.rel <- microbiome::transform(ps1, "compositional") 58 | ord.bray <- ordinate(pseq.rel, "NMDS", "bray") 59 | 60 | p <- plot_ordiplot_core(pseq.rel, ord.bray, 61 | prev.thres, det.thres, 62 | min.prevalence = 0.9, 63 | color.opt = "DiseaseState", shape = NULL, Sample = TRUE 64 | ) 65 | p 66 | } 67 | } 68 | \keyword{utilities} 69 | -------------------------------------------------------------------------------- /man/plot_paired_abundances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_paired_abundances.R 3 | \name{plot_paired_abundances} 4 | \alias{plot_paired_abundances} 5 | \title{A paired-boxplot for user specified list of taxa} 6 | \usage{ 7 | plot_paired_abundances( 8 | x, 9 | select.taxa = NULL, 10 | group = NULL, 11 | group.colors = NULL, 12 | dot.opacity = 0.25, 13 | dot.size = 2, 14 | add.box = FALSE, 15 | box.opacity = 0.25, 16 | group.order = NULL, 17 | add.violin = TRUE, 18 | violin.opacity = 0.25, 19 | ncol = NULL, 20 | nrow = NULL, 21 | line = NULL, 22 | line.down = "#7209b7", 23 | line.stable = "#8d99ae", 24 | line.up = "#14213d", 25 | line.na.value = "grey50", 26 | line.guide = "legend", 27 | line.opacity = 0.25, 28 | line.size = 1, 29 | jitter.width = 0 30 | ) 31 | } 32 | \arguments{ 33 | \item{x}{\code{\link{phyloseq-class}} object.} 34 | 35 | \item{select.taxa}{a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024").} 36 | 37 | \item{group}{Grouping variable to compare. x axis, eg. before-after, t1-t2.} 38 | 39 | \item{group.colors}{Colors for plotting groups.} 40 | 41 | \item{dot.opacity}{For ggplot alpha to determine opacity for points.} 42 | 43 | \item{dot.size}{For ggplot point size.} 44 | 45 | \item{add.box}{Logical. If boxplot to the added. Default=TRUE} 46 | 47 | \item{box.opacity}{For ggplot alpha to determine opacity for box.} 48 | 49 | \item{group.order}{Default is NULL. a list specifying order of x-axis.} 50 | 51 | \item{add.violin}{Logical. If half violin to the added. Default=TRUE} 52 | 53 | \item{violin.opacity}{If add.violin=TRUE, opacity for violin.} 54 | 55 | \item{ncol}{If 2 or more taxa to plot, specify number of columns.} 56 | 57 | \item{nrow}{If 2 or more taxa to plot, specify number of rows.} 58 | 59 | \item{line}{Variable to use for lines. E.g. "subject" before-after} 60 | 61 | \item{line.down}{Line Color for change when negative. Decreased abundance.} 62 | 63 | \item{line.stable}{Line Color for no change.} 64 | 65 | \item{line.up}{Line Color for change when positive. Increased abundance.} 66 | 67 | \item{line.na.value}{"grey50" for no/missing observations.} 68 | 69 | \item{line.guide}{"none" to plot guide for line.} 70 | 71 | \item{line.opacity}{Line opacity.} 72 | 73 | \item{line.size}{Size of line to plot.} 74 | 75 | \item{jitter.width}{Value to avoid over plotting by moving points.} 76 | } 77 | \value{ 78 | \code{\link{ggplot}} object. This can be further modified using ggpubr. 79 | } 80 | \description{ 81 | User specified taxa are plotted. 82 | } 83 | \details{ 84 | Useful for instances where user is interested only in some taxa and thier change after 85 | an intervention. This can also be used at higher taxonomic 86 | levels, output from phyloseq::tax_glom or microbiome::aggregate_taxa. 87 | } 88 | \examples{ 89 | \dontrun{ 90 | library(microbiome) 91 | library(microbiomeutilities) 92 | library(gghalves) 93 | library(tidyr) 94 | data(peerj32) # Source: https://peerj.com/articles/32/ 95 | pseq <- peerj32$phyloseq # Ren 96 | pseq.rel <- microbiome::transform(pseq, "compositional") 97 | select.taxa <- c("Akkermansia", "Dialister") 98 | group.colors <- c("brown3", "steelblue", "grey70") 99 | p <- plot_paired_abundances(pseq.rel, 100 | select.taxa = select.taxa, 101 | group = "time", 102 | group.colors = group.colors, 103 | dot.opacity = 0.25, 104 | dot.size = 2, 105 | group.order = NULL, 106 | line = "subject" 107 | ) 108 | p 109 | } 110 | } 111 | \keyword{visualization} 112 | -------------------------------------------------------------------------------- /man/plot_read_distribution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_read_distribution.R 3 | \name{plot_read_distribution} 4 | \alias{plot_read_distribution} 5 | \title{Distribution of reads} 6 | \usage{ 7 | plot_read_distribution(x, groups, plot.type = c("density", "histogram")) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{groups}{Metadata variable to check for groups based sequencing effort.} 13 | 14 | \item{plot.type}{Either density or histogram plot} 15 | } 16 | \value{ 17 | A \code{\link{ggplot}} plot object. 18 | } 19 | \description{ 20 | Plots distribution of reads. 21 | } 22 | \examples{ 23 | library(microbiome) 24 | data(zackular2014) 25 | ps0 <- zackular2014 26 | p <- plot_read_distribution(ps0, groups = "DiseaseState", plot.type = "density") 27 | print(p) 28 | } 29 | \author{ 30 | Contact: Sudarshan Shetty \email{sudarshanshetty9@gmail.com} 31 | } 32 | \keyword{utilities} 33 | \keyword{visualization} 34 | -------------------------------------------------------------------------------- /man/plot_select_taxa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_select_taxa.R 3 | \name{plot_select_taxa} 4 | \alias{plot_select_taxa} 5 | \title{A boxplot for user specified list of taxa} 6 | \usage{ 7 | plot_select_taxa( 8 | x, 9 | select.taxa, 10 | variableA, 11 | palette, 12 | plot.type, 13 | group.order = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{\code{\link{phyloseq-class}} object.} 18 | 19 | \item{select.taxa}{a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024").} 20 | 21 | \item{variableA}{Variable of interested to be checked. This will also be used to color the plot.} 22 | 23 | \item{palette}{Any of the RColorBrewer plettes.} 24 | 25 | \item{plot.type}{Three optons c("stripchart", "boxplot", "violin")} 26 | 27 | \item{group.order}{Default is NULL. a list specifing order of x-axis. E.g. c("H","CRC","nonCRC")} 28 | } 29 | \value{ 30 | \code{\link{ggplot}} object. This can be further modified using ggpubr. 31 | } 32 | \description{ 33 | User specifed OTUs are plotted. 34 | } 35 | \details{ 36 | Useful for instances where user is interested only in some OTUs. For example OTUs 37 | reported to be significantly diferent. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | # Example data 42 | library(microbiome) 43 | library(microbiomeutilities) 44 | data("zackular2014") 45 | p0 <- zackular2014 46 | p0.f <- format_to_besthit(p0) 47 | select.taxa <- c("OTU-d__denovo31:Dorea", "OTU-d__denovo24:Blautia") 48 | p <- plot_select_taxa(p0.f, select.taxa, "DiseaseState", "Paired", plot.type = "stripchart") 49 | print(p) 50 | } 51 | } 52 | \keyword{utilities} 53 | -------------------------------------------------------------------------------- /man/plot_spaghetti.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_sphagetti.R 3 | \name{plot_spaghetti} 4 | \alias{plot_spaghetti} 5 | \title{Spaghetti Plots} 6 | \usage{ 7 | plot_spaghetti( 8 | x, 9 | plot.var = "by_taxa", 10 | select.taxa = NULL, 11 | xvar = NULL, 12 | group = NULL, 13 | line.bg.color = "#8d99ae", 14 | bg.opacity = 0.5, 15 | focus.color = "brown3", 16 | ncol = NULL, 17 | nrow = NULL, 18 | focus.line.size = 0.5, 19 | line.size = 1 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{\code{\link{phyloseq-class}} object} 24 | 25 | \item{plot.var}{One of "by_sample":Many sample one taxa or "by_taxa":Many taxa one sample} 26 | 27 | \item{select.taxa}{a character list of taxa to be plotted. eg. select.taxa <- c("OTU-370251", "OTU-311173", "OTU-341024").} 28 | 29 | \item{xvar}{X-axis variable. This can be visit_number for participants in subject_id.} 30 | 31 | \item{group}{Column describing sample that have multiple measurements. For e.g. Subject_Ids 32 | which has all subject_ids listed.} 33 | 34 | \item{line.bg.color}{Line color for background. Default ="#8d99ae",} 35 | 36 | \item{bg.opacity}{Line opacity for background.} 37 | 38 | \item{focus.color}{Line color for focus being plotted.} 39 | 40 | \item{ncol}{if wrap, specify number of columns.} 41 | 42 | \item{nrow}{if wrap, specify number of rows.} 43 | 44 | \item{focus.line.size}{Line size for focus being plotted.} 45 | 46 | \item{line.size}{Line size for background.} 47 | } 48 | \value{ 49 | \code{\link{ggplot}} object. This can be further modified using ggpubr. 50 | } 51 | \description{ 52 | Spaghetti Plots 53 | } 54 | \examples{ 55 | \dontrun{ 56 | # Example data 57 | library(microbiomeutilities) 58 | data("hmp2") 59 | pseq <- hmp2 # Ren 60 | pseq.rel <- microbiome::transform(pseq, "compositional") 61 | pseq.relF <- format_to_besthit(pseq.rel) 62 | # Choose one participant 63 | phdf.s <- subset_samples(pseq.relF, subject_id == 64 | "Participant_1") 65 | # Choose top 12 taxa to visualize 66 | ntax <- top_taxa(phdf.s, 12) 67 | phdf.s <- prune_taxa(ntax, phdf.s) 68 | 69 | plot_spaghetti(phdf.s, 70 | plot.var = "by_taxa", 71 | select.taxa = ntax, 72 | xvar = "visit_number", 73 | line.bg.color = "#8d99ae", 74 | focus.color = "#555b6e", 75 | ncol = 3, 76 | nrow = 4, 77 | line.size = 0.2 78 | ) 79 | 80 | print(p) 81 | } 82 | } 83 | \keyword{visualization} 84 | -------------------------------------------------------------------------------- /man/plot_taxa_boxplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_taxa_boxplot.R 3 | \name{plot_taxa_boxplot} 4 | \alias{plot_taxa_boxplot} 5 | \title{Taxonomic Composition Plot boxplot} 6 | \usage{ 7 | plot_taxa_boxplot( 8 | x, 9 | taxonomic.level, 10 | top.otu, 11 | keep.other = FALSE, 12 | group, 13 | title, 14 | group.colors = NULL, 15 | group.order = NULL, 16 | add.violin = TRUE, 17 | violin.opacity = 0.25, 18 | box.opacity = 0.25, 19 | dot.opacity = 0.25, 20 | dot.size = 2 21 | ) 22 | } 23 | \arguments{ 24 | \item{x}{\code{\link{phyloseq-class}} object} 25 | 26 | \item{taxonomic.level}{Merge the OTUs (for phyloseq object) into a higher taxonomic level. This has to be one from colnames(tax_table(x)).} 27 | 28 | \item{top.otu}{Top number of taxa to plot.} 29 | 30 | \item{keep.other}{TRUE or FALSE. Default is FALSE. This will not plot taxa group as Other} 31 | 32 | \item{group}{Specify main variable of interest. This should be one of the variables in sample_variables(x).} 33 | 34 | \item{title}{title for the plot} 35 | 36 | \item{group.colors}{Colors for plotting groups} 37 | 38 | \item{group.order}{Default is NULL. a list specifing order of x-axis. E.g. c("H","CRC","nonCRC")} 39 | 40 | \item{add.violin}{Loical. If half violoin to the added. Default=TRUE} 41 | 42 | \item{violin.opacity}{If add.violin=TRUE, opacity for violin.} 43 | 44 | \item{box.opacity}{For ggplot alpha to determine opacity for box} 45 | 46 | \item{dot.opacity}{For ggplot alpha to determine opacity for points} 47 | 48 | \item{dot.size}{For ggplot alpha to determine size for points} 49 | } 50 | \value{ 51 | A \code{\link{ggplot}} plot object. 52 | } 53 | \description{ 54 | Plot taxon abundance for samples. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | # Example data 59 | library(microbiomeutilities) 60 | library(RColorBrewer) 61 | data("zackular2014") 62 | ps0 <- zackular2014 63 | mycols <- c("brown3", "steelblue", "grey50") 64 | pn <- plot_taxa_boxplot(ps0, 65 | taxonomic.level = "Phylum", 66 | top.otu = 6, 67 | group = "DiseaseState", 68 | title = "Relative abudance plot", 69 | keep.other = FALSE, 70 | group.order = c("H", "CRC", "nonCRC"), 71 | group.colors = mycols 72 | ) 73 | print(pn + theme_biome_utils()) 74 | } 75 | 76 | } 77 | \keyword{visualization} 78 | -------------------------------------------------------------------------------- /man/plot_taxa_composition.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_taxa_composition.R 3 | \name{plot_taxa_composition} 4 | \alias{plot_taxa_composition} 5 | \title{Taxonomic Composition Plot} 6 | \usage{ 7 | plot_taxa_composition( 8 | x, 9 | sample.sort = NULL, 10 | taxonomic.level = "Phylum", 11 | transform = "compositional", 12 | otu.sort = NULL, 13 | palette = brewer.pal(12, "Paired"), 14 | x.label = "sample", 15 | plot.type = "barplot", 16 | average_by = NULL, 17 | verbose = FALSE, 18 | mar = c(5, 12, 1, 1), 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{\code{\link{phyloseq-class}} object} 24 | 25 | \item{sample.sort}{Order samples. Various criteria are available: 26 | \itemize{ 27 | \item NULL or 'none': No sorting 28 | \item A single character string: indicate the metadata field to be used for ordering 29 | \item A character vector: sample IDs indicating the sample ordering. 30 | \item 'neatmap' Order samples based on the neatmap approach. See \code{\link{neatsort}}. By default, 'NMDS' method with 'bray' distance is used. For other options, arrange the samples manually with the function. 31 | }} 32 | 33 | \item{taxonomic.level}{Merge the OTUs (for phyloseq object) into a higher taxonomic level. This has to be one from colnames(tax_table(x)).} 34 | 35 | \item{transform}{Data transform to be used in plotting (but not in sample/taxon ordering). The options are 'Z-OTU', 'Z-Sample', 'log10' and 'compositional'. See the \code{\link{transform}} function.} 36 | 37 | \item{otu.sort}{Order taxa. Same options as for the sample.sort argument but instead of metadata, taxonomic table is used. Also possible to sort by 'abundance'.} 38 | 39 | \item{palette}{The number and palette \code{\link{RColorBrewer}} has to be specified e.g brewer.pal(12, "Paired").} 40 | 41 | \item{x.label}{Specify how to label the x axis. This should be one of the variables in sample_variables(x).} 42 | 43 | \item{plot.type}{Plot type: 'barplot' or 'lineplot'.} 44 | 45 | \item{average_by}{Variable to group.} 46 | 47 | \item{verbose}{verbose.} 48 | 49 | \item{mar}{Figure margins.} 50 | 51 | \item{...}{Arguments to be passed (for \code{\link{neatsort}} function)} 52 | } 53 | \value{ 54 | A \code{\link{ggplot}} plot object. 55 | } 56 | \description{ 57 | Plot taxon abundance for samples. It is a legacy function from \code{\link{microbiome}}. 58 | } 59 | \examples{ 60 | \dontrun{ 61 | # Example data 62 | library(microbiome) 63 | library(microbiomeutilities) 64 | data("biogeogut") 65 | pseq <- biogeogut 66 | plot_taxa_composition(pseq, taxonomic.level = "Phylum") 67 | } 68 | } 69 | \keyword{visualization} 70 | -------------------------------------------------------------------------------- /man/plot_taxa_cv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_taxa_cv.R 3 | \name{plot_taxa_cv} 4 | \alias{plot_taxa_cv} 5 | \title{Coefficient of variations} 6 | \usage{ 7 | plot_taxa_cv(x, plot.type) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object.} 11 | 12 | \item{plot.type}{scatter or hist (histogram)} 13 | } 14 | \value{ 15 | A \code{\link{ggplot}} plot object. 16 | } 17 | \description{ 18 | Plots CV for OTUs/ASVs. 19 | } 20 | \details{ 21 | Check if there are spurious OTUs/ASVs. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | # Example data 26 | library(microbiome) 27 | library(microbiomeutilities) 28 | data("zackular2014") 29 | p0 <- zackular2014 30 | p <- plot_taxa_cv(p0, plot.type = "hist") 31 | print(p) 32 | } 33 | 34 | } 35 | \keyword{utilities} 36 | -------------------------------------------------------------------------------- /man/plot_taxa_heatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_taxa_heatmap.R 3 | \name{plot_taxa_heatmap} 4 | \alias{plot_taxa_heatmap} 5 | \title{Heatmap using \code{\link{phyloseq-class}} and \code{\link{pheatmap}}} 6 | \usage{ 7 | plot_taxa_heatmap( 8 | x, 9 | subset.top, 10 | transformation, 11 | VariableA, 12 | heatcolors = NULL, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{\code{\link{phyloseq-class}} object.} 18 | 19 | \item{subset.top}{either NA or number of Top OTUs to use for plotting.} 20 | 21 | \item{transformation}{either 'log10', 'clr','Z', 'compositional', or NA} 22 | 23 | \item{VariableA}{main variable of Interest.} 24 | 25 | \item{heatcolors}{is the option for colors in \code{\link{pheatmap}}. Default is to use Spectral} 26 | 27 | \item{...}{Arguments to be passed \code{\link{pheatmap}}.} 28 | } 29 | \value{ 30 | A \code{\link{pheatmap}} plot object. 31 | } 32 | \description{ 33 | Plot heatmap using \code{\link{phyloseq-class}} object as input. 34 | } 35 | \examples{ 36 | 37 | library(microbiomeutilities) 38 | library(viridis) 39 | library(RColorBrewer) 40 | data("zackular2014") 41 | ps0 <- zackular2014 42 | 43 | heat.sample <- plot_taxa_heatmap(ps0, 44 | subset.top = 20, 45 | VariableA = "DiseaseState", 46 | heatcolors = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100), 47 | transformation = "log10" 48 | ) 49 | } 50 | \author{ 51 | Sudarshan A. Shetty (sudarshanshetty9@gmail.com) 52 | } 53 | \keyword{visualization} 54 | -------------------------------------------------------------------------------- /man/prep_tern_otu.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prep_tern_otu.R 3 | \name{prep_tern_otu} 4 | \alias{prep_tern_otu} 5 | \title{Create table for ternary plot OTU} 6 | \usage{ 7 | prep_tern_otu(x, abund.thres = 1e-04, prev.thres = 0.1, group = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object.} 11 | 12 | \item{abund.thres}{= 0.0001 check \code{\link{microbiome}} package core function. 13 | remove taxa that are detected at 0.0001 in less than prev.thres of samples.} 14 | 15 | \item{prev.thres}{= 0.1 check \code{\link{microbiome}} package core function.} 16 | 17 | \item{group}{Grouping variable to compare, for this plot there has to be three 18 | groups in the data} 19 | } 20 | \value{ 21 | tibble object. 22 | } 23 | \description{ 24 | Create a table for ternary plot ggtern package. 25 | } 26 | \details{ 27 | Plots the mean relative abundance of taxa in 3 groups being compared. 28 | } 29 | \examples{ 30 | # library(microbiome) 31 | # library(microbiomeutilities) 32 | # library(dplyr) 33 | # data("zackular2014") 34 | # p0 <- zackular2014 35 | # prep_tern_otu(p0, group="DiseaseState", 36 | # abund.thres=0.0001, prev.thres=0.25) 37 | } 38 | \keyword{utilities} 39 | \keyword{visualization} 40 | -------------------------------------------------------------------------------- /man/prep_ternary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prep_ternary.R 3 | \name{prep_ternary} 4 | \alias{prep_ternary} 5 | \title{Create table for Ternary plot} 6 | \usage{ 7 | prep_ternary( 8 | x, 9 | abund.thres = 1e-04, 10 | prev.thres = 0.1, 11 | group = NULL, 12 | level = "lowest" 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{\code{\link{phyloseq-class}} object} 17 | 18 | \item{abund.thres}{= 0.0001 check \code{\link{microbiome}} package core function 19 | remove taxa that are dectected at 0.0001 in less than prev.thres of samples} 20 | 21 | \item{prev.thres}{= 0.1 check \code{\link{microbiome}} package core function} 22 | 23 | \item{group}{Grouping variable to compare, for this plot there has to be three 24 | groups in the data} 25 | 26 | \item{level}{= "Genus" Taxonomic level. If OTU/ASV level specify="lowest" 27 | Does not support phylum level aggregation} 28 | } 29 | \value{ 30 | Tibble object. 31 | } 32 | \description{ 33 | Create a table for ternary plot ggtern R package. 34 | } 35 | \details{ 36 | Plots the mean relative abundance of taxa in 3 groups being compared. 37 | } 38 | \examples{ 39 | library(microbiome) 40 | library(microbiomeutilities) 41 | library(dplyr) 42 | data("zackular2014") 43 | p0 <- zackular2014 44 | prep_ternary(p0, group = "DiseaseState", abund.thres = 0.0001, level = "Genus", prev.thres = 0.25) 45 | } 46 | \keyword{visualization} 47 | -------------------------------------------------------------------------------- /man/print_ps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print_ps.R 3 | \name{print_ps} 4 | \alias{print_ps} 5 | \title{Overview of \code{\link{phyloseq-class}}} 6 | \usage{ 7 | print_ps(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | } 12 | \value{ 13 | Prints information about the \code{\link{phyloseq-class}} object. 14 | } 15 | \description{ 16 | Prints an overview \code{\link{phyloseq-class}}. 17 | } 18 | \examples{ 19 | library(microbiomeutilities) 20 | data("zackular2014") 21 | pseq <- zackular2014 22 | print_ps(pseq) 23 | } 24 | \author{ 25 | Contact: Sudarshan A. Shetty \email{sudarshanshetty9@gmail.com} 26 | } 27 | \keyword{utilities} 28 | -------------------------------------------------------------------------------- /man/rarefy_util.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_utils.R 3 | \name{rarefy_util} 4 | \alias{rarefy_util} 5 | \title{#@param mat otu table rows as taxa names 6 | #@param names_fun either rownames or colnames 7 | #@param list_names vector of names that should appear in boldface} 8 | \usage{ 9 | rarefy_util(ps, sample.size, index) 10 | } 11 | \description{ 12 | #@param mat otu table rows as taxa names 13 | #@param names_fun either rownames or colnames 14 | #@param list_names vector of names that should appear in boldface 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/simple_heatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simple_heatmap.R 3 | \name{simple_heatmap} 4 | \alias{simple_heatmap} 5 | \title{Simple Heatmap} 6 | \usage{ 7 | simple_heatmap( 8 | x, 9 | group.facet = "DiseaseState", 10 | group.order = c("H", "CRC", "nonCRC"), 11 | abund.thres = 0.01, 12 | prev.thres = 0.1, 13 | level = "Genus", 14 | scale.color = "log10", 15 | na.fill = "white", 16 | color.fill = NULL, 17 | taxa.arrange = TRUE, 18 | panel.arrange = NULL, 19 | remove.other = TRUE, 20 | ncol = NULL, 21 | nrow = NULL 22 | ) 23 | } 24 | \arguments{ 25 | \item{x}{\code{\link{phyloseq-class}} object.} 26 | 27 | \item{group.facet}{Variable to make facet/panel the plot.} 28 | 29 | \item{group.order}{Default is NULL. a list specifing order of x-axis. 30 | E.g. c("H","CRC","nonCRC")} 31 | 32 | \item{abund.thres}{= 0.01 check \code{\link{microbiome}} package aggregate_rare function.} 33 | 34 | \item{prev.thres}{= 0.1 check \code{\link{microbiome}} package aggregate_rare function.} 35 | 36 | \item{level}{= "Genus" Taxonomic level. OTU/ASV level not supported. Check plot_taxa_heatmap} 37 | 38 | \item{scale.color}{Scale the tiles colors "log10" or "sqrt"} 39 | 40 | \item{na.fill}{Color to fill NAs. e.g. "white"} 41 | 42 | \item{color.fill}{User specified color vectors.} 43 | 44 | \item{taxa.arrange}{Arrange the order of taxa. User can supply a list of vectors.} 45 | 46 | \item{panel.arrange}{panels "grid" or "wrap" ggplot's facet_XXX} 47 | 48 | \item{remove.other}{Rare clubbed as Other to be removed. Logical TRUE/FALSE.} 49 | 50 | \item{ncol}{if wrap, specify number of columns.} 51 | 52 | \item{nrow}{if wrap, specify number of rows.} 53 | } 54 | \value{ 55 | \code{\link{ggplot}} object. 56 | } 57 | \description{ 58 | Create a simple heatmap with \code{\link{ggplot2}} package. 59 | } 60 | \details{ 61 | Wrapper converts \code{\link{phyloseq-class}} object to long data frame 62 | and generates a heatmap. 63 | } 64 | \examples{ 65 | library(microbiome) 66 | library(microbiomeutilities) 67 | library(dplyr) 68 | data("zackular2014") 69 | p0 <- zackular2014 70 | p0.rel <- transform(p0, "compositional") 71 | p <- simple_heatmap(p0.rel, 72 | group.facet = "DiseaseState", 73 | group.order = c("H", "CRC", "nonCRC"), 74 | abund.thres = 0.01, 75 | prev.thres = 0.1, 76 | level = "Genus", 77 | scale.color = "log10", 78 | na.fill = "white", 79 | color.fill = NULL, 80 | taxa.arrange = TRUE, 81 | remove.other = TRUE, 82 | panel.arrange = "wrap", 83 | ncol = 2, 84 | nrow = 2 85 | ) 86 | 87 | print(p) 88 | } 89 | \keyword{visualization} 90 | -------------------------------------------------------------------------------- /man/taxa_distribution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_utils.R 3 | \name{taxa_distribution} 4 | \alias{taxa_distribution} 5 | \title{Distribution of taxa} 6 | \usage{ 7 | taxa_distribution( 8 | x, 9 | color.level = "Phylum", 10 | color.taxa = brewer.pal(12, "Paired") 11 | ) 12 | } 13 | \arguments{ 14 | \item{x}{\code{\link{phyloseq-class}} object} 15 | 16 | \item{color.level}{Taxonomic level to color} 17 | 18 | \item{color.taxa}{vector of colors specified by user 19 | Default is brewer.pal(12,"Paired")} 20 | } 21 | \value{ 22 | ggplot2 object 23 | } 24 | \description{ 25 | Plots distribution of taxa. 26 | } 27 | \examples{ 28 | library(microbiomeutilities) 29 | data("zackular2014") 30 | pseq <- zackular2014 31 | p <- taxa_distribution(pseq) 32 | p 33 | } 34 | \keyword{utilities} 35 | -------------------------------------------------------------------------------- /man/taxa_pooler_mcola.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_utils.R 3 | \name{taxa_pooler_mcola} 4 | \alias{taxa_pooler_mcola} 5 | \title{Pool Taxa} 6 | \usage{ 7 | taxa_pooler_mcola(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | } 12 | \description{ 13 | Creates a list of dataframes at different taxonomic levels. 14 | } 15 | \examples{ 16 | # library(phyloseq) 17 | # library(microbiome) 18 | # data("zackular2014") 19 | # sub.sm <- sample(sample_names(zackular2014), 20) 20 | # pseq <- prune_samples(sub.sm,zackular2014) 21 | # taxa_pooler_mcola(pseq) 22 | } 23 | \keyword{utilities} 24 | -------------------------------------------------------------------------------- /man/taxa_summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/taxa_summary.R 3 | \name{taxa_summary} 4 | \alias{taxa_summary} 5 | \title{Give taxa summary at specified taxonomic level} 6 | \usage{ 7 | taxa_summary(x, level) 8 | } 9 | \arguments{ 10 | \item{x}{\code{\link{phyloseq-class}} object} 11 | 12 | \item{level}{Taxonomic level for which summary is required} 13 | } 14 | \value{ 15 | returns a data frame with relative abundance summary. 16 | } 17 | \description{ 18 | Data frame with mean, max, median standard deviation of relative abundance. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | # Example data 23 | library(microbiomeutilities) 24 | data("zackular2014") 25 | p0 <- zackular2014 26 | p0.rel <- microbiome::transform(p0, "compositional") 27 | tx.sum1 <- taxa_summary(p0, "Phylum") 28 | 29 | tx.sum2 <- taxa_summary(p0.rel, "Phylum") 30 | } 31 | 32 | } 33 | \author{ 34 | Contact: Sudarshan A. Shetty \email{sudarshanshetty9@gmail.com} 35 | } 36 | \keyword{utilities} 37 | -------------------------------------------------------------------------------- /man/theme_biome_utils.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_utils.R 3 | \name{theme_biome_utils} 4 | \alias{theme_biome_utils} 5 | \title{Custom theme for microbiomeutilities pkg} 6 | \usage{ 7 | theme_biome_utils() 8 | } 9 | \description{ 10 | Opiniated elegant theme. 11 | } 12 | \keyword{utilities} 13 | -------------------------------------------------------------------------------- /man/zackular2014.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{zackular2014} 5 | \alias{zackular2014} 6 | \title{Test data} 7 | \format{ 8 | An object of class \code{"phyloseq"}. 9 | } 10 | \usage{ 11 | data("zackular2014") 12 | } 13 | \description{ 14 | Data from a Zackular, Joseph P., et al. "The gut microbiome modulates colon tumorigenesis." MBio 4.6 (2013): e00692 15 | -13. 16 | } 17 | \examples{ 18 | \dontrun{ 19 | library(microbiomeutilities) 20 | data("zackular2014") 21 | pseq <- zackular2014 22 | print(zackular2014) 23 | } 24 | 25 | } 26 | \references{ 27 | \itemize{ 28 | \item{}{Zackular, Joseph P., et al. "The gut microbiome modulates colon 29 | tumorigenesis." MBio 4.6 (2013): e00692-13., 30 | \url{https://mbio.asm.org/content/4/6/e00692-13.short}} 31 | } 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /microbiomeutilities-master.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: ISO8859-1 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageBuildArgs: --resave-data 19 | PackageRoxygenize: rd,collate,namespace 20 | --------------------------------------------------------------------------------