Skip to content

Commit

Permalink
Merge pull request #80 from adrientaudiere/dev
Browse files Browse the repository at this point in the history
Improve test and examples for CRAN submission
  • Loading branch information
adrientaudiere authored Feb 9, 2024
2 parents e81237d + 00373b7 commit 14da7e5
Show file tree
Hide file tree
Showing 42 changed files with 576 additions and 397 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: MiscMetabar
Type: Package
Title: Miscellaneous Functions for Metabarcoding Analysis
Version: 0.7.3
Version: 0.7.4
Authors@R: person("Adrien", "Taudière", email = "[email protected]",
role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0003-1088-1182"))
Description: The MiscMetabar package aims to facilitate the description, transformation, exploration, and reproducibility of metabarcoding analysis. Mainly build on the top of phyloseq, dada2 R packages. MiscMetabar help to build reproducible and robust bioinformatic pipeline in R. MiscMetabar make ecological analysis of alpha and beta-diversity simple and powerfull by integrating a large number of analysis, some of them from other R packages.
Description: The MiscMetabar package aims to facilitate the description, transformation, exploration, and reproducibility of metabarcoding analysis. Mainly build on the top of phyloseq, dada2 R packages. MiscMetabar help to build reproducible and robust bioinformatic pipeline in R. MiscMetabar make ecological analysis of alpha and beta-diversity simple and powerful by integrating a large number of analysis, some of them from other R packages.
License: AGPL-3
Encoding: UTF-8
LazyData: true
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- Add functions `swarm_clustering()` and `vsearch_clustering()` and add `swarm` method in the function `asv2otu()`
- Add function `physeq_or_string_to_dna()` mostly for internal use
- Add function `cutadapt_remove_primers()` to remove primers using [cutadapt](https://github.com/marcelm/cutadapt/)
- Add internal functions `is_swarm_installed()`, `is_cutadapt_installed()`, `is_vsearch_installed()` and `is_falco_installed()` to test for the availability of external software in order to run examples and test from testthat.

- Submit to CRAN and change code to comply with their rules (patch 0.7.1 to 0.7.4)


## BREAKING CHANGES

Expand Down
7 changes: 5 additions & 2 deletions R/Deseq2_edgeR.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
#' @export
#' @examples
#' data("GlobalPatterns", package = "phyloseq")
#' plot_edgeR_pq(GlobalPatterns, c("SampleType", "Soil", "Feces"),
#' GP_archae <- subset_taxa(GlobalPatterns, GlobalPatterns@tax_table[, 1] == "Archaea")
#' plot_edgeR_pq(GP_archae, c("SampleType", "Soil", "Feces"),
#' color_tax = "Kingdom"
#' )
#' plot_edgeR_pq(GlobalPatterns, c("SampleType", "Soil", "Feces"),
#' \dontrun{
#' plot_edgeR_pq(GP_archae, c("SampleType", "Soil", "Feces"),
#' taxolev = "Class", color_tax = "Kingdom"
#' )
#' }
#' @author Adrien Taudière
#'
#' @return A \code{\link{ggplot}}2 plot representing edgeR results
Expand Down
24 changes: 8 additions & 16 deletions R/beta_div_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ adonis_pq <- function(physeq,
#' @export
#' @seealso [plot_LCBD_pq], [adespatial::beta.div()]
#' @examples
#' data(data_fungi_sp_known)
#' res <- LCBD_pq(data_fungi_sp_known, nperm = 50)
#' res <- LCBD_pq(data_fungi_sp_known, nperm = 5)
#' str(res)
#' length(res$LCBD)
#' length(res$SCBD)
#' LCBD_pq(data_fungi_sp_known, nperm = 50, method = "jaccard")
#' LCBD_pq(data_fungi_sp_known, nperm = 5, method = "jaccard")
#'
#' @author Adrien Taudière
#' This function is mainly a wrapper of the work of others.
Expand Down Expand Up @@ -288,20 +287,20 @@ LCBD_pq <- function(physeq,
#'
#' @examples
#' data(data_fungi)
#' plot_LCBD_pq(data_fungi,
#' plot_LCBD_pq(data_fungi_mini,
#' nperm = 100, only_plot_significant = FALSE,
#' pval = 0.2
#' )
#' plot_LCBD_pq(data_fungi,
#' plot_LCBD_pq(data_fungi_mini,
#' nperm = 100, only_plot_significant = TRUE,
#' pval = 0.2
#' )
#' library("patchwork")
#' plot_LCBD_pq(data_fungi,
#' plot_LCBD_pq(data_fungi_mini,
#' nperm = 100, only_plot_significant = FALSE,
#' sam_variables = c("Time", "Height")
#' )
#' plot_LCBD_pq(data_fungi,
#' plot_LCBD_pq(data_fungi_mini,
#' nperm = 100, only_plot_significant = TRUE, pval = 0.2,
#' sam_variables = c("Time", "Height", "Tree_name")
#' ) &
Expand Down Expand Up @@ -563,12 +562,8 @@ multipatt_pq <- function(physeq,
#' @export
#'
#' @examples
#' data(data_fungi_sp_known)
#' res_height <- ancombc_pq(
#' subset_taxa_pq(
#' data_fungi_sp_known,
#' taxa_sums(data_fungi_sp_known) > 5000
#' ),
#' data_fungi_mini,
#' fact = "Height",
#' levels_fact = c("Low", "High"),
#' verbose = TRUE
Expand All @@ -590,10 +585,7 @@ multipatt_pq <- function(physeq,
#' geom_point()
#'
#' res_time <- ancombc_pq(
#' subset_taxa_pq(
#' data_fungi_sp_known,
#' taxa_sums(data_fungi_sp_known) > 5000
#' ),
#' data_fungi_mini,
#' fact = "Time",
#' levels_fact = c("0", "15"),
#' tax_level = "Family",
Expand Down
17 changes: 13 additions & 4 deletions R/dada_phyloseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ track_wkflow_samples <- function(list_pq_obj, ...) {
#' @param method (default: clusterize)
#' Set the clustering method.
#' - `clusterize` use the [DECIPHER::Clusterize()] fonction,
#' - `vsearch` use the vsearch software (https://github.com/torognes/vsearch/)
#' - `vsearch` use the vsearch software (https://github.com/torognes/vsearch)
#' with arguments `--cluster_size` by default (see args `vsearch_cluster_method`)
#' and `-strand both` (see args `vsearch_args`)
#' - `swarm` use the swarm
Expand All @@ -493,7 +493,7 @@ track_wkflow_samples <- function(list_pq_obj, ...) {
#' set tax_adjust to 0 (default). For the moment only tax_adjust = 0 is
#' robust
#' @param vsearch_cluster_method (default: "--cluster_size) See other possible
#' methods in the [vsearch pdf manual](https://github.com/torognes/vsearch/releases/download/v2.23.0/vsearch_manual.pdf) (e.g. `--cluster_size` or `--cluster_smallmem`)
#' methods in the [vsearch manual](https://github.com/torognes/vsearch/) (e.g. `--cluster_size` or `--cluster_smallmem`)
#' - `--cluster_fast` : Clusterize the fasta sequences in filename, automatically sort by decreasing sequence length beforehand.
#' - `--cluster_size` : Clusterize the fasta sequences in filename, automatically sort by decreasing sequence abundance beforehand.
#' - `--cluster_smallmem` : Clusterize the fasta sequences in filename without automatically modifying their order beforehand. Sequence are expected to be sorted by decreasing sequence length, unless *--usersort* is used.
Expand All @@ -520,6 +520,15 @@ track_wkflow_samples <- function(list_pq_obj, ...) {
#' @return A new object of class `physeq` or a list of cluster if dna_seq
#' args was used.
#'
#' @examples
#' asv2otu(data_fungi_mini)
#' asv2otu(data_fungi_mini, method_clusterize = "longest")
#' if (MiscMetabar:::is_swarm_installed()) {
#' d_swarm <- asv2otu(data_fungi_mini, method = "swarm")
#' }
#' if (MiscMetabar:::is_vsearch_installed()) {
#' d_vs <- asv2otu(data_fungi_mini, method = "vsearch")
#' }
#' @references
#' VSEARCH can be downloaded from
#' \url{https://github.com/torognes/vsearch}.
Expand Down Expand Up @@ -1917,8 +1926,8 @@ plot_guild_pq <-
#' @examples
#' library("phangorn")
#'
#' df <- subset_taxa_pq(data_fungi, taxa_sums(data_fungi) > 9000)
#' df_tree <- build_phytree_pq(df, nb_bootstrap = 5)
#' df <- subset_taxa_pq(data_fungi_mini, taxa_sums(data_fungi_mini) > 9000)
#' df_tree <- build_phytree_pq(df, nb_bootstrap = 2)
#' plot(df_tree$UPGMA)
#' plotBS(df_tree$UPGMA, df_tree$UPGMA_bs, main = "UPGMA")
#' plot(df_tree$NJ, "unrooted")
Expand Down
33 changes: 33 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@
#' @usage data(data_fungi_sp_known)
"data_fungi_sp_known"


#' Fungal OTU in phyloseq format
#'
#' It is a subset of the data_fungi dataset including only Basidiomycota
#' with more than 5000 sequences.
#'
#' Obtain using `data_fungi_mini <- subset_taxa(data_fungi, Phylum == "Basidiomycota")`
#' and then `data_fungi_mini <- subset_taxa_pq(data_fungi_mini, colSums(data_fungi_mini@otu_table) > 5000)`
#'
#'
#' @format A physeq object containing 45 taxa with references sequences
#' described by 14 taxonomic ranks and 137 samples described by 7 sample variables:
#' - *X*: the name of the fastq-file
#' - *Sample_names*: the names of ... the samples
#' - *Treename*: the name of an tree
#' - *Sample_id*: identifier for each sample
#' - *Height*: height of the sample in the tree
#' - *Diameter*: diameter of the trunk
#' - *Time*: time since the dead of the tree
#' @usage data(data_fungi_mini)
#' @format A physeq object containing 45 taxa with references sequences
#' described by 14 taxonomic ranks and 137 samples described by 7 sample variables:
#' - *X*: the name of the fastq-file
#' - *Sample_names*: the names of ... the samples
#' - *Treename*: the name of an tree
#' - *Sample_id*: identifier for each sample
#' - *Height*: height of the sample in the tree
#' - *Diameter*: diameter of the trunk
#' - *Time*: time since the dead of the tree
#' @usage data(data_fungi_mini)
"data_fungi_mini"


#' This tutorial explore the dataset from Tengeler et al. (2020) available in the `mia` package.
#' obtain using `mia::makePhyloseqFromTreeSE(Tengeler2020)`
#'
Expand Down
97 changes: 97 additions & 0 deletions R/miscellanous.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,100 @@ install_pkg_needed <- function(pkg, use_pak = TRUE, bioconductor_pkg = FALSE,
}
}
}

################################################################################
#' Test if cutadapt is installed.
#'
#' @description
#' `r lifecycle::badge("maturing")`
#'
#' Useful for testthat and examples compilation for R CMD CHECK and
#' test coverage
#'
#' @param args_before_cutadapt : (String) A one line bash command to run before
#' to run cutadapt. For examples, "source ~/miniconda3/etc/profile.d/conda.sh && conda activate cutadaptenv &&" allow to bypass the conda init which asks to restart the shell
#' @keywords internal
#' @noRd
#' @return A logical that say if cutadapt is install in
#'
#' @examples
#' MiscMetabar:::is_cutadapt_installed()
#' @author Adrien Taudière

is_cutadapt_installed <- function(args_before_cutadapt = "source ~/miniconda3/etc/profile.d/conda.sh && conda activate cutadaptenv && ") {
writeLines(paste0(args_before_cutadapt, " cutadapt -h"), paste0(tempdir(), "/script_cutadapt.sh"))
cutadapt_error_or_not <- try(system(paste0("bash ", tempdir(), "/script_cutadapt.sh 2>&1"), intern = TRUE), silent = T)
unlink(paste0(tempdir(), "/script_cutadapt.sh"))

return(class(cutadapt_error_or_not) != "try-error")
}

#' Test if falco is installed.
#'
#' @description
#' `r lifecycle::badge("maturing")`
#'
#' Useful for testthat and examples compilation for R CMD CHECK and
#' test coverage
#'
#' @param path (default: falco) Path to falco
#' @keywords internal
#' @noRd
#' @return A logical that say if falco is install in
#'
#' @examples
#' MiscMetabar:::is_falco_installed()
#' @author Adrien Taudière

is_falco_installed <- function(path = "falco") {
return(class(try(system(paste0(path, " 2>&1"), intern = TRUE),
silent = TRUE
)) != "try-error")
}

#' Test if swarm is installed.
#'
#' @description
#' `r lifecycle::badge("maturing")`
#'
#' Useful for testthat and examples compilation for R CMD CHECK and
#' test coverage
#'
#' @param path (default: swarm) Path to falco
#' @keywords internal
#' @noRd
#' @return A logical that say if swarm is install in
#'
#' @examples
#' MiscMetabar:::is_swarm_installed()
#' @author Adrien Taudière

is_swarm_installed <- function(path = "swarm") {
return(class(try(system(paste0(path, " -h 2>&1"), intern = TRUE),
silent = TRUE
)) != "try-error")
}

#' Test if vsearch is installed.
#'
#' @description
#' `r lifecycle::badge("maturing")`
#'
#' Useful for testthat and examples compilation for R CMD CHECK and
#' test coverage
#'
#' @param path (default: vsearch) Path to vsearch
#' @keywords internal
#' @noRd
#' @return A logical that say if vsearch is install in
#'
#' @examples
#' MiscMetabar:::is_vsearch_installed()
#' @author Adrien Taudière

is_vsearch_installed <- function(path = "vsearch") {
return(class(try(system(paste0(path, " 2>&1"), intern = TRUE),
silent = TRUE
)) != "try-error")
}
################################################################################
Loading

0 comments on commit 14da7e5

Please sign in to comment.