Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #89 #90

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions R/corncob.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,6 @@ run_corncob <- function(rec,
fdr,
log2FC,
rarefy) {


## Temporal solution to https://github.com/bryandmartin/corncob/issues/141
# ver <- utils::packageVersion("detectseparation")
# if (ver != "0.2") {
# rlang::abort(c(
# "!" = glue::glue(
# "Temporarily the version of the package ",
# "{crayon::bgMagenta('detectseparation')} must be ",
# "{crayon::blue('v0.2')}, but you have the version ",
# "{crayon::blue(ver)} installed."
# ),
# "*" = glue::glue(
# "Please first run {crayon::blue('remove.packages(\"detectseparation\")')}.",
# ),
# "*" = glue::glue(
# "Finally install the necessary version with ",
# "{crayon::blue('devtools::install_version(\"detectseparation\", version = 0.2)')}."
# )
# ),
# use_cli_format = TRUE)
# }

phy <- get_phy(rec)
vars <- get_var(rec)
Expand All @@ -258,23 +236,43 @@ run_corncob <- function(rec,
dplyr::filter(!!dplyr::sym(var) %in% comparison) %>%
dplyr::pull(sample_id) %>%
phyloseq::prune_samples(phy)

corncob_res <- corncob::differentialTest(
formula = glue::glue("~ { var }") %>% stats::formula(),
data = f_phy,
phi.formula = phi.formula,
formula_null = formula_null,
phi.formula_null = phi.formula_null,
link = link,
phi.link = phi.link,
test = test,
boot = boot,
B = B,
filter_discriminant = filter_discriminant,
fdr_cutoff = Inf,
fdr = fdr
)


corncob_res <-
tryCatch({
corncob::differentialTest(
formula = glue::glue("~ { var }") %>% stats::formula(),
data = f_phy,
phi.formula = phi.formula,
formula_null = formula_null,
phi.formula_null = phi.formula_null,
link = link,
phi.link = phi.link,
test = test,
boot = boot,
B = 10e4,
filter_discriminant = filter_discriminant,
fdr_cutoff = Inf,
fdr = fdr
)
}, error = function(e) { conditionMessage(e) })

## Skip error for no convergenc
if (!is(corncob_res, "differentialTest")) {
if (stringr::str_detect(corncob_res, "failed to converge")) {
rlang::abort(c(
glue::glue("{crayon::bgMagenta('corncob')}: All models failed to converge!"),
glue::glue("{crayon::bgMagenta('corncob')}: If you are seeing this, it is likely that your model is overspecified. This occurs when your sample size is not large enough to estimate all the parameters of your model. This is most commonly due to categorical variables that include many categories."),
glue::glue("Please remove or edit the {crayon::bgMagenta('step_corncob()')} and rerun.")
))
} else {
rlang::abort(c(
glue::glue("{crayon::bgMagenta('corncob')}: Internal error!"),
glue::glue("Please remove or edit the {crayon::bgMagenta('step_corncob()')} and rerun."),
"Please report this bug on GitHub: https://github.com/MicrobialGenomics-IrsicaixaOrg/dar/issues"
))
}
}

signif_taxa <- corncob::otu_to_taxonomy(
OTU = corncob_res$significant_taxa,
data = corncob_res$data,
Expand Down
Loading