Skip to content

Commit

Permalink
force detectseparation v0.2 (corncob bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
xec-cm committed Sep 1, 2022
1 parent 84491e8 commit aa339ad
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
23 changes: 22 additions & 1 deletion R/corncob.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
#'
#' ## Define step with default parameters and prep
#' rec <-
#' step_corncob(rec) # %>% prep(parallel = TRUE)
#' step_corncob(rec) %>%
#' prep(parallel = TRUE)
#'
#' rec
#'
Expand Down Expand Up @@ -206,6 +207,26 @@ run_corncob <- function(rec,
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(pkg)} must be {crayon::blue(paste0('v', v))}, 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)
tax_level <- get_tax(rec)
Expand Down
22 changes: 11 additions & 11 deletions R/filter_taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ run_filter_taxa <- function(rec, .f) {

val <-
zero_otu(rec) %>%
dplyr::filter(pct == 0) %>%
dplyr::filter(.data$pct == 0) %>%
nrow()

if (val > 0 & rm_zeros == 0 & is_metagenomeseq) {
Expand Down Expand Up @@ -132,16 +132,16 @@ methods::setMethod(
otu_table(obj) %>%
tidyr::pivot_longer(-1, names_to = "sample_id") %>%
dplyr::left_join(sample_data(obj), by = "sample_id") %>%
dplyr::mutate(no_zero = ifelse(value == 0, 0, 1)) %>%
dplyr::mutate(no_zero = ifelse(.data$value == 0, 0, 1)) %>%
dplyr::group_by(taxa_id, !!dplyr::sym(var)) %>%
dplyr::summarise(
no_zero = sum(no_zero),
no_zero = sum(.data$no_zero),
total = dplyr::n(),
pct = no_zero / total,
pct = .data$no_zero / .data$total,
.groups = "drop"
) %>%
dplyr::arrange(pct) %>%
dplyr::filter(pct >= pct_cutoff)
dplyr::arrange(.data$pct) %>%
dplyr::filter(.data$pct >= pct_cutoff)
}
)

Expand All @@ -160,15 +160,15 @@ methods::setMethod(
dplyr::select(1, !!var),
by = "sample_id"
) %>%
dplyr::mutate(no_zero = ifelse(value == 0, 0, 1)) %>%
dplyr::mutate(no_zero = ifelse(.data$value == 0, 0, 1)) %>%
dplyr::group_by(taxa_id, !!dplyr::sym(var)) %>%
dplyr::summarise(
no_zero = sum(no_zero),
no_zero = sum(.data$no_zero),
total = dplyr::n(),
pct = no_zero / total,
pct = .data$no_zero / .data$total,
.groups = "drop"
) %>%
dplyr::arrange(pct) %>%
dplyr::filter(pct >= pct_cutoff)
dplyr::arrange(.data$pct) %>%
dplyr::filter(.data$pct >= pct_cutoff)
}
)
4 changes: 2 additions & 2 deletions R/metagenomeseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ run_metagenomeseq <- function(rec,

vct_var <- phyloseq::sample_data(phy2)[[var]]
norm_factor <- metagenomeSeq::normFactors(mr_obj)
norm_factor <- log2(norm_factor / median(norm_factor) + 1)
norm_factor <- log2(norm_factor / stats::median(norm_factor) + 1)

model <- stats::model.matrix( ~ 1 + vct_var + norm_factor)

Expand All @@ -221,7 +221,7 @@ run_metagenomeseq <- function(rec,
metagenomeSeq::MRfulltable(number = Inf, by = 2) %>%
tibble::as_tibble(rownames = "taxa_id") %>%
dplyr::left_join(tax_table(rec), by = "taxa_id") %>%
dplyr::rename(pvalue = pvalues, padj = adjPvalues) %>%
dplyr::rename(pvalue = .data$pvalues, padj = .data$adjPvalues) %>%
dplyr::mutate(
comparison = stringr::str_c(comparison, collapse = "_"),
var = var
Expand Down
13 changes: 13 additions & 0 deletions R/pkg_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ methods::setMethod(
invisible()
}
)

check_version <- function(pkg, v) {

check <- utils::packageVersion(pkg) == v
if (!check) {
rlang::warn(c(
"i" = glue::glue(
"Temporarily the version of the package ",
"{crayon::blue(pkg)} must be {crayon::blue(paste0('v', v))}, but you ")
), use_cli_format = TRUE)
}
}

3 changes: 2 additions & 1 deletion man/step_corncob.Rd

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

0 comments on commit aa339ad

Please sign in to comment.