Skip to content

Commit

Permalink
fix #119 and bump version to 0.10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
david-barnett committed Jul 20, 2023
1 parent 9e12f8b commit 5bf6d1a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: microViz
Title: Microbiome Data Analysis and Visualization
Version: 0.10.10
Version: 0.10.11
Authors@R:
person(given = "David",
family = "Barnett",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# microViz 0.10.11

- Fix: `taxatree_stats_p_adjust` can accept multiple grouping variables without specifying new_var.

# microViz 0.10.10

- Fix: `comp_barplot` taxon ordering is now correct when tax_level is set to "Taxon"
Expand Down
41 changes: 29 additions & 12 deletions R/taxatree_stats_p_adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
#' @details
#' Define how to group the p values for adjustment with the `grouping` argument.
#' The default is to adjust the p values in groups at each taxonomic rank,
#' but you could also adjust per "model" / "taxon" or per "term".
#' Or even group by a combination of rank and term with c("rank", "term")
#'
#' but you could also adjust per "taxon" or per "term".
#' Or even group by a combination of rank and term with c("rank", "term").
#' You should specify the name of the new variable containing the adjusted
#' p values in the new_var argument. If left as NULL the new variable name will
#' be created by pasting together p.adj, the method, and the grouping variable(s)
#' separated by ".".
#'
#' @param data psExtra with taxatree_stats dataframe, or just the dataframe
#' @param grouping
Expand Down Expand Up @@ -95,19 +98,33 @@ taxatree_stats_p_adjust <- function(data,
method,
grouping = "rank",
p = "p.value",
new_var = paste0(
"p.adj.", method, ".", grouping
)) {
if (is(data, "psExtra") && is.data.frame(data@taxatree_stats)) {
new_var = NULL) {
# Input checks
if (!rlang::is_string(method)) rlang::abort("method must be a string")
rlang::arg_match(method, values = stats::p.adjust.methods)
if (!is.character(grouping)) rlang::abort("grouping must be character")
if (!is.null(new_var) && !rlang::is_string(new_var)) {
rlang::abort("new_var must be NULL or a string")
}
if (!is(data, "psExtra") && !is.data.frame(data)) {
rlang::abort("data must be a psExtra or a taxatree_stats dataframe")
}

# Extract and check stats data frame
if (is(data, "psExtra")) {
if (!is.data.frame(data@taxatree_stats)) {
stop("psExtra input must have stats dataframe in taxatree_stats slot")
}
df <- data@taxatree_stats
} else if (inherits(data, "data.frame")) {
df <- data
} else {
stop(
"data must be a psExtra with taxatree_stats or just the stats dataframe"
)
df <- data
}

# set default new variable name
if (is.null(new_var)) {
new_var <- paste0("p.adj.", method, ".", paste(grouping, collapse = "."))
}
# change grouping variable names from alternative nomenclature
if (identical(grouping, "model") || identical(grouping, "taxon_name")) {
grouping <- "taxon"
}
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ date)](https://img.shields.io/docker/v/barnettdavid/microviz-rocker-verse?color=
status](https://david-barnett.r-universe.dev/badges/microViz)](https://david-barnett.r-universe.dev/ui#package:microViz)
[![JOSS
article](https://joss.theoj.org/papers/4547b492f224a26d96938ada81fee3fa/status.svg)](https://joss.theoj.org/papers/4547b492f224a26d96938ada81fee3fa)
[![Citations](https://img.shields.io/badge/Citations-~44-blueviolet)](https://scholar.google.com/scholar?oi=bibs&hl=en&cites=5439940108464463894)
[![Citations](https://img.shields.io/badge/Citations-~50-blueviolet)](https://scholar.google.com/scholar?oi=bibs&hl=en&cites=5439940108464463894)
[![Zenodo
DOI](https://zenodo.org/badge/307119750.svg)](https://zenodo.org/badge/latestdoi/307119750)
<!-- badges: end -->
Expand Down Expand Up @@ -331,8 +331,8 @@ aitchison_perm <- aitchison_dists %>%
n_processes = 1, n_perms = 99, # you should use at least 999!
variables = "bmi_group"
)
#> 2023-06-27 10:28:15.676676 - Starting PERMANOVA with 99 perms with 1 processes
#> 2023-06-27 10:28:15.743616 - Finished PERMANOVA
#> 2023-07-20 17:10:01.831556 - Starting PERMANOVA with 99 perms with 1 processes
#> 2023-07-20 17:10:01.889154 - Finished PERMANOVA

# view the permanova results
perm_get(aitchison_perm) %>% as.data.frame()
Expand All @@ -357,8 +357,8 @@ your permanova directly using the `ord_plot` function with constraints
perm2 <- aitchison_dists %>%
dist_permanova(variables = c("weight", "african", "sex"), seed = 321)
#> Dropping samples with missings: 2
#> 2023-06-27 10:28:15.754227 - Starting PERMANOVA with 999 perms with 1 processes
#> 2023-06-27 10:28:17.410055 - Finished PERMANOVA
#> 2023-07-20 17:10:01.900323 - Starting PERMANOVA with 999 perms with 1 processes
#> 2023-07-20 17:10:03.569987 - Finished PERMANOVA
```

We’ll visualise the effect of nationality and bodyweight on sample
Expand Down Expand Up @@ -452,7 +452,7 @@ and by participating in this project you agree to abide by its terms.
sessionInfo()
#> R version 4.3.0 (2023-04-21)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.3.1
#> Running under: macOS Ventura 13.4.1
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
Expand All @@ -469,27 +469,27 @@ sessionInfo()
#>
#> other attached packages:
#> [1] ggplot2_3.4.2 dplyr_1.1.2 phyloseq_1.44.0 microViz_0.10.10
#> [5] testthat_3.1.8 devtools_2.4.5 usethis_2.2.0
#> [5] testthat_3.1.10 devtools_2.4.5 usethis_2.2.2
#>
#> loaded via a namespace (and not attached):
#> [1] RColorBrewer_1.1-3 shape_1.4.6 rstudioapi_0.14
#> [4] jsonlite_1.8.5 magrittr_2.0.3 farver_2.1.1
#> [7] rmarkdown_2.22 GlobalOptions_0.1.2 fs_1.6.2
#> [1] RColorBrewer_1.1-3 shape_1.4.6 rstudioapi_0.15.0
#> [4] jsonlite_1.8.7 magrittr_2.0.3 farver_2.1.1
#> [7] rmarkdown_2.23 GlobalOptions_0.1.2 fs_1.6.2
#> [10] zlibbioc_1.46.0 vctrs_0.6.3 multtest_2.56.0
#> [13] memoise_2.0.1 Cairo_1.6-0 RCurl_1.98-1.12
#> [16] htmltools_0.5.5 curl_5.0.1 Rhdf5lib_1.22.0
#> [19] rhdf5_2.44.0 htmlwidgets_1.6.2 plyr_1.8.8
#> [22] cachem_1.0.8 commonmark_1.9.0 igraph_1.4.3
#> [22] cachem_1.0.8 commonmark_1.9.0 igraph_1.5.0
#> [25] mime_0.12 lifecycle_1.0.3 iterators_1.0.14
#> [28] pkgconfig_2.0.3 Matrix_1.5-4.1 R6_2.5.1
#> [28] pkgconfig_2.0.3 Matrix_1.6-0 R6_2.5.1
#> [31] fastmap_1.1.1 clue_0.3-64 GenomeInfoDbData_1.2.10
#> [34] shiny_1.7.4 digest_0.6.31 selectr_0.4-2
#> [34] shiny_1.7.4.1 digest_0.6.33 selectr_0.4-2
#> [37] colorspace_2.1-0 S4Vectors_0.38.1 ps_1.7.5
#> [40] pkgload_1.3.2 seriation_1.4.2 vegan_2.6-4
#> [40] pkgload_1.3.2.1 seriation_1.4.2 vegan_2.6-4
#> [43] labeling_0.4.2 fansi_1.0.4 httr_1.4.6
#> [46] mgcv_1.8-42 compiler_4.3.0 remotes_2.4.2
#> [46] mgcv_1.9-0 compiler_4.3.0 remotes_2.4.2.1
#> [49] doParallel_1.0.17 withr_2.5.0 viridis_0.6.3
#> [52] pkgbuild_1.4.0 highr_0.10 MASS_7.3-60
#> [52] pkgbuild_1.4.2 highr_0.10 MASS_7.3-60
#> [55] sessioninfo_1.2.2 rjson_0.2.21 biomformat_1.28.0
#> [58] permute_0.9-7 tools_4.3.0 ape_5.7-1
#> [61] httpuv_1.6.11 glue_1.6.2 callr_3.7.3
Expand All @@ -498,19 +498,19 @@ sessionInfo()
#> [70] cluster_2.1.4 reshape2_1.4.4 ade4_1.7-22
#> [73] generics_0.1.3 gtable_0.3.3 microbiome_1.22.0
#> [76] ca_0.71.1 tidyr_1.3.0 data.table_1.14.8
#> [79] xml2_1.3.4 utf8_1.2.3 XVector_0.40.0
#> [79] xml2_1.3.5 utf8_1.2.3 XVector_0.40.0
#> [82] BiocGenerics_0.46.0 markdown_1.7 foreach_1.5.2
#> [85] pillar_1.9.0 stringr_1.5.0 later_1.3.1
#> [88] circlize_0.4.15 splines_4.3.0 ggtext_0.1.2
#> [91] lattice_0.21-8 corncob_0.3.1 survival_3.5-5
#> [94] tidyselect_1.2.0 registry_0.5-1 ComplexHeatmap_2.16.0
#> [97] Biostrings_2.68.0 miniUI_0.1.1.1 knitr_1.42
#> [97] Biostrings_2.68.0 miniUI_0.1.1.1 knitr_1.43
#> [100] gridExtra_2.3 IRanges_2.34.0 stats4_4.3.0
#> [103] xfun_0.39 Biobase_2.60.0 matrixStats_1.0.0
#> [106] brio_1.1.3 stringi_1.7.12 yaml_2.3.7
#> [109] evaluate_0.21 codetools_0.2-19 tibble_3.2.1
#> [112] cli_3.6.1 xtable_1.8-4 munsell_0.5.0
#> [115] processx_3.8.1 Rcpp_1.0.10 GenomeInfoDb_1.36.0
#> [115] processx_3.8.2 Rcpp_1.0.11 GenomeInfoDb_1.36.0
#> [118] png_0.1-8 parallel_4.3.0 ellipsis_0.3.2
#> [121] prettyunits_1.1.1 profvis_0.3.8 urlchecker_1.0.1
#> [124] bitops_1.0-7 viridisLite_0.4.2 scales_1.2.1
Expand Down
10 changes: 7 additions & 3 deletions man/taxatree_stats_p_adjust.Rd

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

46 changes: 44 additions & 2 deletions tests/testthat/test-taxatree_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,50 @@ lm_models <- phylo %>%
# convert models to stats
lm_stats <- taxatree_models2stats(lm_models)

# test plotting errors
# Test taxatree_stats_p_adjust input checks
test_that("taxatree_stats_p_adjust rejects invalid grouping argument", {
expect_error(
taxatree_stats_p_adjust(lm_stats, method = "BH", grouping = 1),
regexp = "grouping must be character"
)
})
test_that("taxatree_stats_p_adjust rejects invalid new_var argument", {
expect_error(
taxatree_stats_p_adjust(lm_stats, method = "BH", new_var = c("A", "B")),
regexp = "new_var must be NULL or a string"
)
})
test_that("taxatree_stats_p_adjust rejects invalid data argument", {
expect_error(
taxatree_stats_p_adjust(data = phylo, method = "BH"),
regexp = "data must be a psExtra or a taxatree_stats dataframe"
)
})
test_that("taxatree_stats_p_adjust rejects invalid method argument", {
expect_error(
taxatree_stats_p_adjust(data = lm_stats, method = "bh"),
regexp = "`method` must be one of \"holm\", \"hochberg\","
)
expect_error(
taxatree_stats_p_adjust(data = lm_stats, method = c("BH", "holm")),
regexp = "method must be a string"
)
})
# test basic taxatree_stats_p_adjust functionality
test_that("taxatree_stats_p_adjust works correctly with default grouping", {
result <- taxatree_stats_p_adjust(lm_stats, method = "BH")
expect_true("p.adj.BH.rank" %in% colnames(taxatree_stats_get(result)))
})
test_that("taxatree_stats_p_adjust works correctly with 2 variable grouping", {
result <- taxatree_stats_p_adjust(lm_stats, method = "BH", grouping = c("rank", "term"))
expect_true("p.adj.BH.rank.term" %in% colnames(taxatree_stats_get(result)))
})
test_that("taxatree_stats_p_adjust works correctly with provided new_var", {
result <- taxatree_stats_p_adjust(lm_stats, method = "BH", new_var = "new_p")
expect_true("new_p" %in% colnames(taxatree_stats_get(result)))
})

# test taxatree_plots plotting errors
test_that("taxatree_plots throw informative errors", {
expect_error(
object = lm_models %>% taxatree_plots(),
Expand All @@ -59,7 +102,6 @@ test_that("taxatree_plots throw informative errors", {
)
})


test_that("taxatree_plot plotting works", {
local_edition(3)
lm_plots <- taxatree_plots(lm_stats)
Expand Down

0 comments on commit 5bf6d1a

Please sign in to comment.