Skip to content

Commit

Permalink
Merge pull request #34 from adrientaudiere/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
adrientaudiere authored Oct 23, 2023
2 parents 2c4bce7 + 79c4993 commit 26990b4
Show file tree
Hide file tree
Showing 37 changed files with 14,649 additions and 216 deletions.
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Version: 0.5
Author: Adrien Taudière <[email protected]>
Maintainer: Adrien Taudière <[email protected]>
Description: Functions to help analyze and visualize metabarcoding data. Mainly build on the top of phyloseq, dada2 and targets R packages.
License: GNU AGPLv3
License: AGPL-3 + file LICENSE
Encoding: UTF-8
LazyData: true
Depends:
Expand Down
2 changes: 1 addition & 1 deletion R/MiscMetabar-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NULL

if (getRversion() >= "2.15.1") {
utils::globalVariables(c(
".id", "%>%", "Ab", "Abundance", "character_method", "col_tax", "combn", "complement", "devtools", "e-value", "Family", "Genus", "grid.draw", "grid.layout", "group_by", "Hill_0", "Hill_1", "Hill_2", "install_github", "log2FoldChange", "logFC", "lwr", "max_Hill", "modality", "multcompLetters", "nb_values", "ott_id", "OTU", "Proportion", "pushViewport", "Query name", "rarefy", "reverse", "rgb", "reverseComplement", "rrarefy", "Sample", "Species", "summarise", "tax", "tax_col", "teststat", "tnrs_match_names", "tol_induced_subtree", "upr", "upViewport", "val", "vegdist", "viewport", "x", "x1", "X1", "x2", "y", "y1", "y2", "ymax", "ymin"
".id", "%>%", "Ab", "Abundance", "character_method", "col_tax", "combn", "complement", "devtools", "e-value", "Family", "Genus", "grid.draw", "grid.layout", "group_by", "Hill_0", "Hill_1", "Hill_2", "install_github", "log2FoldChange", "logFC", "lwr", "max_Hill", "modality", "multcompLetters", "nb_values", "ott_id", "OTU", "Proportion", "pushViewport", "Query name", "rarefy", "reverse", "rgb", "reverseComplement", "rrarefy", "Sample", "Species", "summarise", "tax", "tax_col", "teststat", "tnrs_match_names", "tol_induced_subtree", "upr", "upViewport", "val", "vegdist", "viewport", "x", "x1", "X1", "x2", "y", "y1", "y2", "ymax", "ymin", "Class", "LVL1", "LVL3", "Time", "calc_taxon_abund", "heat_tree", "parse_phyloseq"
))
}

Expand Down
4 changes: 2 additions & 2 deletions R/dada_phyloseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,8 @@ lulu_pq <- function(physeq,

match_list <- utils::read.csv(file = "match_list.txt", sep = "\t")

if (!requireNamespace("lulu")) {
requireNamespace(devtools)
if (!requireNamespace("lulu", quietly = TRUE)) {
requireNamespace(devtools, quietly = TRUE)
install_github("adrientaudiere/lulu")
}

Expand Down
6 changes: 4 additions & 2 deletions R/krona.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' data("GlobalPatterns")
#' GA <- subset_taxa(GlobalPatterns, Phylum == "Acidobacteria")
#' # krona(GA, "Number.of.sequences.html")
#' # krona(GA, "Number.of.ASVs.html", nb_seq = F)
#' # krona(GA, "Number.of.ASVs.html", nb_seq = FALSE)
#' # merge_krona(c("Number.of.sequences.html", "Number.of.ASVs.html"))
#' @return A html file
#' @export
Expand Down Expand Up @@ -101,11 +101,13 @@ krona <-
#' @param output path to the output file
#'
#' @examples
#' \dontrun{
#' data("GlobalPatterns")
#' GA <- subset_taxa(GlobalPatterns, Phylum == "Acidobacteria")
#' # krona(GA, "Number.of.sequences.html")
#' # krona(GA, "Number.of.ASVs.html", nb_seq = F)
#' # krona(GA, "Number.of.ASVs.html", nb_seq = FALSE)
#' # merge_krona(c("Number.of.sequences.html", "Number.of.ASVs.html"))
#' }
#' @return A html file
#' @seealso \code{\link{krona}}
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/miscellanous.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ simplify_taxo <- function(physeq, remove_space = TRUE) {
taxo <- gsub(".__", "", taxo, perl = TRUE)
if (remove_space) {
taxo <- gsub(" ", "", taxo)
taxo <- gsub(" ", "", taxo)
taxo <- gsub("\u00a0", "", taxo)
}
physeq@tax_table <- tax_table(taxo)
return(physeq)
Expand Down Expand Up @@ -273,7 +273,7 @@ funky_color <-
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' @param file_path The path to one fastq file or a list of fastq files
#' @param fastq_files The path to one fastq file or a list of fastq files
#' (see examples)
#' @param folder_output The path to a folder for output files
#' @param n_seq (int; default 1000) : Number of sequences kept (every sequence
Expand Down
74 changes: 38 additions & 36 deletions R/plot_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ circle_pq <-
start_degree = NULL,
row_col = NULL,
grid_col = NULL,
log10transform = FALSE,
log10trans = FALSE,
...) {
if (!inherits(physeq, "phyloseq")) {
stop("physeq must be an object of class 'phyloseq'")
Expand Down Expand Up @@ -491,7 +491,7 @@ circle_pq <-
}
otu_table_ech <- o_t_e_interm

if (log10transform) {
if (log10trans) {
otu_table_ech <- apply(otu_table_ech, 2, function(x) {
log10(1 + x)
})
Expand Down Expand Up @@ -762,10 +762,10 @@ sankey_pq <-
#' data("enterotype")
#' venn_pq(enterotype, fact = "SeqTech")
#' venn_pq(enterotype, fact = "ClinicalStatus")
#' venn_pq(enterotype, fact = "Nationality", print_values = F)
#' venn_pq(enterotype, fact = "ClinicalStatus", print_values = F) +
#' venn_pq(enterotype, fact = "Nationality", print_values = FALSE)
#' venn_pq(enterotype, fact = "ClinicalStatus", print_values = FALSE) +
#' scale_fill_hue()
#' venn_pq(enterotype, fact = "ClinicalStatus", print_values = F) +
#' venn_pq(enterotype, fact = "ClinicalStatus", print_values = FALSE) +
#' scale_fill_hue()
#'
#' @return A \code{\link{ggplot}}2 plot representing Venn diagramm of
Expand Down Expand Up @@ -1382,7 +1382,7 @@ hill_pq <-
)

if (one_plot) {
library("patchwork")
requireNamespace("patchwork", quietly = TRUE)
if (letters) {
res <- ((p_0 + theme(legend.position = "none")) + labs(subtitle = element_blank()) +
(p_1 + theme(legend.position = "none", axis.text.y = element_blank()) + labs(subtitle = element_blank()) + ylab(NULL)) +
Expand Down Expand Up @@ -1684,7 +1684,6 @@ rotl_pq <- function(physeq,
#' tree_label = taxon_names,
#' node_size_trans = "log10 area"
#' )
#' }
#'
#' heat_tree_pq(GPsubset,
#' node_size = n_seq,
Expand All @@ -1694,8 +1693,9 @@ rotl_pq <- function(physeq,
#' node_size_trans = "log10 area"
#' )
#'
#' }
heat_tree_pq <- function(physeq, taxonomic_level = NULL, ...) {
library("metacoder")
requireNamespace("metacoder", quietly = TRUE)
if (!is.null(taxonomic_level)) {
physeq@tax_table <- physeq@tax_table[, taxonomic_level]
}
Expand Down Expand Up @@ -2269,7 +2269,7 @@ plot_tax_pq <-
#' @param nb_seq (logical; default TRUE) If set to FALSE, only the number of ASV
#' is count. Concretely, physeq otu_table is transformed in a binary
#' otu_table (each value different from zero is set to one)
#' @param log10transform (logical, default TRUE) If TRUE,
#' @param log10trans (logical, default TRUE) If TRUE,
#' the number of sequences (or ASV if nb_seq = FALSE) is log10
#' transformed.
#' @return A ggplot2 graphic
Expand All @@ -2279,14 +2279,15 @@ plot_tax_pq <-
#' @examples
#' multitax_bar_pq(data_fungi_sp_known, "Phylum", "Class", "Order", "Time")
#' multitax_bar_pq(data_fungi_sp_known, "Phylum", "Class", "Order")
#' multitax_bar_pq(data_fungi_sp_known, "Phylum", "Class", "Order", nb_seq = FALSE, log10transform = FALSE)
#' multitax_bar_pq(data_fungi_sp_known, "Phylum", "Class", "Order",
#' nb_seq = FALSE, log10trans = FALSE)
multitax_bar_pq <- function(physeq,
lvl1,
lvl2,
lvl3,
fact = NULL,
nb_seq = TRUE,
log10transform = TRUE) {
log10trans = TRUE) {
if (!nb_seq) {
physeq <- as_binary_otu_table(physeq)
}
Expand All @@ -2303,7 +2304,7 @@ multitax_bar_pq <- function(physeq,
"LVL3" = tapply(psm[[lvl3]], psm[[lvl3]], unique)
)

if (log10transform) {
if (log10trans) {
data_gg$Abundance <- log10(data_gg$Abundance)
}

Expand All @@ -2325,7 +2326,7 @@ multitax_bar_pq <- function(physeq,
"LVL3" = tapply(psm[[lvl3]], paste(psm[[fact]], psm[[lvl3]]), unique)
)

if (log10transform) {
if (log10trans) {
data_gg$Abundance <- log10(data_gg$Abundance)
}

Expand Down Expand Up @@ -2531,15 +2532,19 @@ SRS_curve_pq <- function(physeq, clean_pq = FALSE, ...) {
#' @export
#'
#' @examples
#' library("iNEXT")
#' res_iNEXT <- iNEXT_pq(data_fungi_sp_known,
#' merge_sample_by = "Height",
#' q = 1, datatype = "abundance", nboot = 5
#' )
#' ggiNEXT(res_iNEXT)
#' ggiNEXT(res_iNEXT, type = 2)
#' ggiNEXT(res_iNEXT, type = 3)
#'
#' \dontrun{
#' library("iNEXT")
#' res_iNEXT <- iNEXT_pq(
#' data_fungi_sp_known,
#' merge_sample_by = "Height",
#' q = 1,
#' datatype = "abundance",
#' nboot = 2
#' )
#' ggiNEXT(res_iNEXT)
#' ggiNEXT(res_iNEXT, type = 2)
#' ggiNEXT(res_iNEXT, type = 3)
#' }
#' @author Adrien Taudière
#'
#'
Expand Down Expand Up @@ -3003,7 +3008,7 @@ tax_bar_pq <- function(physeq, fact = "Sample", taxa = "Order", percent_bar = FA
#' @param nb_seq (logical; default TRUE) If set to FALSE, only the number of ASV
#' is count. Concretely, physeq `otu_table` is transformed in a binary
#' `otu_table` (each value different from zero is set to one)
#' @param log10transform (logical, default TRUE) If TRUE,
#' @param log10trans (logical, default TRUE) If TRUE,
#' the number of sequences (or ASV if nb_seq = FALSE) is log10
#' transformed.
#' @param ... Other params passed on to [ggridges::geom_density_ridges()]
Expand All @@ -3014,7 +3019,7 @@ tax_bar_pq <- function(physeq, fact = "Sample", taxa = "Order", percent_bar = FA
#' @author Adrien Taudière
#' @examples
#'
#' ridges_pq(data_fungi, "Time", alpha = 0.5, log10transform = FALSE) + xlim(c(0, 1000))
#' ridges_pq(data_fungi, "Time", alpha = 0.5, log10trans = FALSE) + xlim(c(0, 1000))
#' ridges_pq(data_fungi, "Time", alpha = 0.5)
#' ridges_pq(clean_pq(subset_taxa(data_fungi_sp_known, Phylum == "Basidiomycota")))
#' ridges_pq(clean_pq(subset_taxa(data_fungi_sp_known, Phylum == "Basidiomycota")),
Expand All @@ -3029,12 +3034,12 @@ tax_bar_pq <- function(physeq, fact = "Sample", taxa = "Order", percent_bar = FA
ridges_pq <- function(physeq,
fact = NULL,
nb_seq = TRUE,
log10transform = TRUE,
log10trans = TRUE,
...) {
psm <- psmelt(physeq)
psm <- psm %>% filter(Abundance > 0)

if (log10transform) {
if (log10trans) {
psm$Abundance <- log10(psm$Abundance)
}
if (nb_seq) {
Expand Down Expand Up @@ -3073,13 +3078,10 @@ ridges_pq <- function(physeq,
#' @inheritParams clean_pq
#' @param lvl1 (required) Name of the first (higher) taxonomic rank of interest
#' @param lvl2 (required) Name of the second (lower) taxonomic rank of interest
#' @param fact Name of the factor to cluster samples by modalities.
#' Need to be in \code{physeq@sam_data}. If not set, the taxonomic
#' distribution is plot for all samples together.
#' @param nb_seq (logical; default TRUE) If set to FALSE, only the number of ASV
#' is count. Concretely, physeq otu_table is transformed in a binary
#' otu_table (each value different from zero is set to one)
#' @param log10transform (logical, default TRUE) If TRUE,
#' @param log10trans (logical, default TRUE) If TRUE,
#' the number of sequences (or ASV if nb_seq = FALSE) is log10
#' transformed.
#' @param plot_legend (logical, default FALSE) If TRUE, plot che
Expand All @@ -3105,21 +3107,21 @@ ridges_pq <- function(physeq,
#' Phylum == "Basidiomycota"
#' )),
#' "Order", "Class",
#' log10transform = FALSE
#' log10trans = FALSE
#' )
#' treemap_pq(
#' clean_pq(subset_taxa(
#' data_fungi_sp_known,
#' Phylum == "Basidiomycota"
#' )),
#' "Order", "Class",
#' nb_seq = FALSE, log10transform = FALSE
#' nb_seq = FALSE, log10trans = FALSE
#' )
treemap_pq <- function(physeq,
lvl1,
lvl2,
nb_seq = TRUE,
log10transform = TRUE,
log10trans = TRUE,
plot_legend = FALSE,
...) {
if (!nb_seq) {
Expand All @@ -3134,7 +3136,7 @@ treemap_pq <- function(physeq,
group_by(.data[[lvl2]]) %>%
reframe(Abundance = sum(Abundance), LVL1 = unique(.data[[lvl1]]))

if (log10transform) {
if (log10trans) {
psm2$Abundance <- log10(psm2$Abundance)
}

Expand Down Expand Up @@ -3162,7 +3164,7 @@ treemap_pq <- function(physeq,
}

if (nb_seq) {
if (log10transform) {
if (log10trans) {
p <-
p + ggtitle(paste0(
"Nb of sequences (log10 transformed) by ",
Expand All @@ -3174,7 +3176,7 @@ treemap_pq <- function(physeq,
p <- p + ggtitle(paste0("Nb of sequences by ", lvl1, " and ", lvl2))
}
} else {
if (log10transform) {
if (log10trans) {
p <- p + ggtitle(paste0(
"Nb of ASV (log10 transformed) by ",
lvl1, " and ", lvl2
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ navbar:
- text: Filter taxa and samples
href: articles/filter.html
- text: -------
- text: Tutorials with published dataset
- text: Tengeler
href: articles/tengeler.html
- text: -------
- text: "For developpers"
- text: Rules of code
href: articles/Rules.html
Expand Down
Binary file modified data/data_fungi.rda
Binary file not shown.
Binary file modified data/data_fungi_sp_known.rda
Binary file not shown.
8 changes: 4 additions & 4 deletions man/circle_pq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/heat_tree_pq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions man/iNEXT_pq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26990b4

Please sign in to comment.