Skip to content

Commit

Permalink
Merge pull request #93 from adrientaudiere/dev
Browse files Browse the repository at this point in the history
style: Improve code factor notation
  • Loading branch information
adrientaudiere authored Jun 29, 2024
2 parents d0aa5c5 + 5cc9f5a commit 0af6a69
Show file tree
Hide file tree
Showing 500 changed files with 4,220 additions and 3,535 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ jobs:
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: MiscMetabar
Type: Package
Title: Miscellaneous Functions for Metabarcoding Analysis
Version: 0.9.1
Version: 0.9.2
Authors@R: person("Adrien", "Taudière", email = "[email protected]",
role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0003-1088-1182"))
Description: Facilitate the description, transformation, exploration, and reproducibility of metabarcoding analyses. 'MiscMetabar' is mainly built on top of the 'phyloseq', 'dada2' and 'targets' R packages. It helps to build reproducible and robust bioinformatics pipelines in R. 'MiscMetabar' makes ecological analysis of alpha and beta-diversity easier, more reproducible and more powerful by integrating a large number of tools. Important features are described in Taudière A. (2023) <doi:10.21105/joss.06038>.
Expand Down
33 changes: 20 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# MiscMetabar 0.9.1 (in development)
# MiscMetabar 0.9.2 (in development)

- Add param `default_fun` in function `merge_samples2()` in order to replace the default function that change the sample data in case of merging. A useful parameter is `default_fun=diff_fct_diff_class`.
- Add param `kruskal_test` to `hill_pq()` function to prevent user to mis-interpret Tuckey HSD result (and letters) if the global effect of the tested factor on Hill diversity is non significant.
- Add param `vioplot` to hill_pq() function to allow violin plot instead of boxplot.
- Modify `rarefy_sample_count_by_modality` to debug the case of modality with level of length one.

# MiscMetabar 0.9.1

## New functions
- Add functions [taxa_as_rows()] and [taxa_as_columns()] to replace verbose called to [clean_pq()]
- Add function [ggscatt_pq()] to plot and test for effect of a numerical columns in sam_data on Hill number. Its the equivalent for numerical variables of [ggbetween_pq()] which focus on the effect of a factor.
- Add functions [var_par_pq()] , [var_par_rarperm_pq()] and [plot_var_part_pq()] to compute the partition of the variation of community and plot it. It introduce the notion of `rarperm` part in the function name. It refers to the fact that this function compute permutation of samples depth rarefaction to measure the variation due to the random process in rarefaction.
- Add function [hill_test_rarperm_pq()] to test the effect of a factor on hill diversity accounting for the variation due to random nature of the rarefaction by sample depth.
- Add function [rarefy_sample_count_by_modality()] to equalize the number of samples for each levels of a modality (factor)
- Add function [accu_plot_balanced_modality()] to plot accumulation curves with balanced modality (same number of samples per level) and depth rarefaction (same number of sequences per sample)
- Add function [adonis_rarperm_pq()] to compute multiple Permanova analyses on different sample depth rarefaction.
- Add function [ggaluv_pq()] to plot taxonomic distribution in alluvial fashion with ggplot2 (using the [ggalluvial] package)
- Add function [glmutli_pq()] to use automated model selection and multimodel inference with (G)LMs for phyloseq object
- Add functions `taxa_as_rows()` and `taxa_as_columns()` to replace verbose called to `clean_pq()`
- Add function `ggscatt_pq()` to plot and test for effect of a numerical columns in sam_data on Hill number. Its the equivalent for numerical variables of `ggbetween_pq()` which focus on the effect of a factor.
- Add functions `var_par_pq()` , `var_par_rarperm_pq()` and `plot_var_part_pq()` to compute the partition of the variation of community and plot it. It introduce the notion of `rarperm` part in the function name. It refers to the fact that this function compute permutation of samples depth rarefaction to measure the variation due to the random process in rarefaction.
- Add function `hill_test_rarperm_pq()` to test the effect of a factor on hill diversity accounting for the variation due to random nature of the rarefaction by sample depth.
- Add function `rarefy_sample_count_by_modality()` to equalize the number of samples for each levels of a modality (factor)
- Add function `accu_plot_balanced_modality()` to plot accumulation curves with balanced modality (same number of samples per level) and depth rarefaction (same number of sequences per sample)
- Add function `adonis_rarperm_pq()` to compute multiple Permanova analyses on different sample depth rarefaction.
- Add function `ggaluv_pq()` to plot taxonomic distribution in alluvial fashion with ggplot2 (using the [ggalluvial] package)
- Add function `glmutli_pq()` to use automated model selection and multimodel inference with (G)LMs for phyloseq object


## New parameters

- Add param `taxa_ranks` in function [psmelt_samples_pq()] to group results by samples AND taxonomic ranks.
- Add param `hill_scales` in functions [hill_tuckey_pq()] and [hill_pq()] to choose the level of the hill number.
- Add param `taxa_ranks` in function `psmelt_samples_pq()` to group results by samples AND taxonomic ranks.
- Add param `hill_scales` in functions `hill_tuckey_pq()` and `hill_p()` to choose the level of the hill number.
- Add param `na_remove` in function `hill_pq()` to remove samples with NA in the factor fact.


Expand All @@ -31,7 +38,7 @@
- Replace param `variable` by `fact` in function `ggbetween_pq()` and `hill_pq()` (keeping the variable option in `hill_pq()` for backward compatibility)
- Fix a bug in the class of the return object of function `chimera_removal_vs()`. Now it return a matrix to be able to be parsed on to [dada2::getUniques()]

# MiscMetabar 0.7 (in development)
# MiscMetabar 0.7

- Add functions `chimera_detection_vs()` and `chimera_removal_vs()` to process chimera detection and removal using [vsearch](https://github.com/torognes/vsearch) software
- Add functions `filter_trim()`, `sample_data_with_new_names()` and `rename_samples()` to facilitate the use of [targets](https://books.ropensci.org/targets/) for bioinformatic pipeline.
Expand Down
8 changes: 5 additions & 3 deletions R/Deseq2_edgeR.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
################################################################################
#' Plot edgeR results for a phyloseq or a edgeR object.
#'
#' `r lifecycle::badge("maturing")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-maturing-blue" alt="lifecycle-maturing"></a>
#'
#' @inheritParams clean_pq
#' @param contrast (required):This argument specifies what comparison
Expand Down Expand Up @@ -121,7 +122,9 @@ plot_edgeR_pq <-
################################################################################
#' Plot DESeq2 results for a phyloseq or a DESeq2 object.
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @param data (required) a \code{\link{phyloseq-class}} or a
#' \code{\link[DESeq2]{DESeqDataSet-class}} object.
Expand Down Expand Up @@ -367,7 +370,6 @@ plot_deseq2_pq <-
################################################################################
#' Convert phyloseq OTU count data into DGEList for edgeR package
#'
#'
#' @inheritParams clean_pq
#'
#' @param group (required) A character vector or factor giving the experimental
Expand Down
12 changes: 9 additions & 3 deletions R/alpha_div_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#' Calculate hill number and compute Tuckey post-hoc test
#' @description
#'
#' `r lifecycle::badge("maturing")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-maturing-blue" alt="lifecycle-maturing"></a>
#'
#' Note that, by default, this function use a sqrt of the read numbers in the linear
#' model in order to correct for uneven sampling depth.
#' @aliases hill_tuckey_pq
Expand Down Expand Up @@ -104,7 +106,9 @@ hill_tuckey_pq <- function(
#' with different rarefaction even depth
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams clean_pq
#' @param fact (required) Name of the factor in `physeq@sam_data` used to plot
Expand Down Expand Up @@ -268,7 +272,9 @@ hill_test_rarperm_pq <- function(physeq,
################################################################################
#' Automated model selection and multimodel inference with (G)LMs for phyloseq
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams clean_pq
#' @param formula (required) a formula for [glmulti::glmulti()]
Expand Down
62 changes: 45 additions & 17 deletions R/beta_div_test.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
################################################################################
#' @title Performs graph-based permutation tests on phyloseq object
#' @description
#' `r lifecycle::badge("maturing")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-maturing-blue" alt="lifecycle-maturing"></a>
#'
#' A wrapper of [phyloseqGraphTest::graph_perm_test()] for quick plot with
#' important statistics
Expand Down Expand Up @@ -95,7 +97,9 @@ graph_test_pq <- function(physeq,
################################################################################
#' @title Permanova on a phyloseq object
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [vegan::adonis2()] function in the case of `physeq` object.
#' @inheritParams clean_pq
Expand Down Expand Up @@ -217,7 +221,9 @@ adonis_pq <- function(physeq,
#' Permanova (adonis) on permutations of rarefaction even depth
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams adonis_pq
#' @param nperm (int) The number of permutations to perform.
Expand Down Expand Up @@ -329,7 +335,9 @@ adonis_rarperm_pq <- function(physeq,
#' @title Compute and test local contributions to beta diversity (LCBD) of
#' samples
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [adespatial::beta.div()] function in the case of `physeq`
#' object.
Expand Down Expand Up @@ -376,7 +384,9 @@ LCBD_pq <- function(physeq,
################################################################################
#' @title Plot and test local contributions to beta diversity (LCBD) of samples
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [adespatial::beta.div()] function in the case of `physeq`
#' object.
Expand Down Expand Up @@ -526,7 +536,9 @@ plot_LCBD_pq <- function(physeq,
################################################################################
#' @title Plot species contributions to beta diversity (SCBD) of samples
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [adespatial::beta.div()] function in the case of `physeq`
#' object.
Expand Down Expand Up @@ -592,7 +604,9 @@ plot_SCBD_pq <- function(physeq,
################################################################################
#' @title Test and plot multipatt result
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [indicspecies::multipatt()] function in the case of
#' `physeq` object.
Expand Down Expand Up @@ -673,7 +687,9 @@ multipatt_pq <- function(physeq,
################################################################################
#' Run ANCOMBC2 on phyloseq object
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' A wrapper for the [ANCOMBC::ancombc2()] function
#'
Expand Down Expand Up @@ -755,7 +771,9 @@ ancombc_pq <- function(physeq, fact, levels_fact = NULL, tax_level = "Class", ..
################################################################################
#' Filter ancombc_pq results
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @param ancombc_res (required) the result of the ancombc_pq function
#' For the moment only bimodal factors are possible.
Expand Down Expand Up @@ -833,7 +851,9 @@ signif_ancombc <- function(ancombc_res,
################################################################################
#' Plot ANCOMBC2 result for phyloseq object
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams clean_pq
#' @param ancombc_res (required) the result of the ancombc_pq function
Expand Down Expand Up @@ -998,7 +1018,9 @@ plot_ancombc_pq <-
#' Show taxa which are present in only one given level of a modality
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams clean_pq
#' @param modality (required) The name of a column present in the `@sam_data` slot
Expand Down Expand Up @@ -1052,7 +1074,9 @@ taxa_only_in_one_level <- function(physeq,
#' Distribution of sequences across a factor for one taxon
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams clean_pq
#' @param fact (required) Name of the factor in `physeq@sam_data` used to plot
Expand Down Expand Up @@ -1112,7 +1136,10 @@ distri_1_taxa <- function(physeq, fact, taxa_name, digits = 2) {
################################################################################
#' Partition the Variation of a phyloseq object by 2, 3, or 4 Explanatory Matrices
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' The function partitions the variation in otu_table using
#' distance (Bray per default) with respect to two, three, or four explanatory
#' tables, using
Expand Down Expand Up @@ -1173,7 +1200,7 @@ var_par_pq <-
dist_physeq <- phyloseq::distance(physeq, method = dist_method)
}

for (i in 1:length(list_component)) {
for (i in seq_along(list_component)) {
assign(
names(list_component)[i],
as.data.frame(unclass(physeq@sam_data[, list_component[[i]]]))
Expand Down Expand Up @@ -1210,7 +1237,7 @@ var_par_pq <-

if (dbrda_computation) {
res_varpart$dbrda_result <- list()
for (i in 1:length(list_component)) {
for (i in seq_along(list_component)) {
res_varpart$dbrda_result[[i]] <-
anova(vegan::dbrda(
as.formula(paste0(
Expand All @@ -1231,13 +1258,14 @@ var_par_pq <-
################################################################################
#' Partition the Variation of a phyloseq object with rarefaction permutations
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' This is an extension of the function [var_par_pq()]. The main addition is
#' the computation of nperm permutations with rarefaction even depth by
#' sample. The return object
#'
#'
#' @inheritParams clean_pq
#' @param list_component (required) A named list of 2, 3 or four vectors with
#' names from the `@sam_data` slot.
Expand Down
16 changes: 11 additions & 5 deletions R/blast.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#' Blast some sequence against `refseq` slot of a \code{\link{phyloseq-class}}
#' object.
#'
#' `r lifecycle::badge("maturing")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-maturing-blue" alt="lifecycle-maturing"></a>
#'
#' @param physeq (required): a \code{\link{phyloseq-class}} object obtained
#' using the `phyloseq` package.
Expand Down Expand Up @@ -179,7 +180,8 @@ blast_to_phyloseq <- function(physeq,
#' Blast all sequence of `refseq` slot of a \code{\link{phyloseq-class}}
#' object against a custom database.
#'
#' `r lifecycle::badge("experimental")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams blast_to_phyloseq
#' @param fasta_for_db path to a fasta file to make the blast database
Expand Down Expand Up @@ -333,7 +335,8 @@ blast_pq <- function(physeq,
################################################################################
#' Filter undesirable taxa using blast against a custom database.
#'
#' `r lifecycle::badge("experimental")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams blast_to_phyloseq
#' @param fasta_for_db path to a fasta file to make the blast database
Expand Down Expand Up @@ -420,7 +423,8 @@ filter_asv_blast <- function(physeq,
#' Blast some sequence against sequences from of a \code{\link{derep-class}}
#' object.
#'
#' `r lifecycle::badge("experimental")`
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' @inheritParams blast_to_phyloseq
#' @param derep The result of `dada2::derepFastq()`. A list of `derep-class`
Expand Down Expand Up @@ -594,7 +598,9 @@ blast_to_derep <- function(derep,
#' Add information from [blast_pq()] to the `tax_table` slot of a *phyloseq* object
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' <a href="https://adrientaudiere.github.io/MiscMetabar/articles/Rules.html#lifecycle">
#' <img src="https://img.shields.io/badge/lifecycle-experimental-orange" alt="lifecycle-experimental"></a>
#'
#' Basically a wrapper of [blast_pq()] with option `unique_per_seq = TRUE` and
#' `score_filter = FALSE`.
Expand Down
Loading

0 comments on commit 0af6a69

Please sign in to comment.