Skip to content

Commit

Permalink
Merge pull request #239 from stemangiola/deprecate_dot_contrasts
Browse files Browse the repository at this point in the history
deprecate .contrasts and update tests
  • Loading branch information
stemangiola authored Jun 26, 2022
2 parents b31ffe0 + 2b729ef commit 18f4cf0
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 71 deletions.
71 changes: 42 additions & 29 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol)
#' @param .sample The name of the sample column
#' @param .transcript The name of the transcript/gene column
#' @param .abundance The name of the transcript/gene abundance column
#' @param .contrasts This parameter takes the format of the contrast parameter of the method of choice. For edgeR and limma-voom is a character vector. For DESeq2 is a list including a character vector of length three. The first covariate is the one the model is tested against (e.g., ~ factor_of_interest)
#' @param contrasts This parameter takes the format of the contrast parameter of the method of choice. For edgeR and limma-voom is a character vector. For DESeq2 is a list including a character vector of length three. The first covariate is the one the model is tested against (e.g., ~ factor_of_interest)
#' @param method A string character. Either "edgeR_quasi_likelihood" (i.e., QLF), "edgeR_likelihood_ratio" (i.e., LRT), "edger_robust_likelihood_ratio", "DESeq2", "limma_voom", "limma_voom_sample_weights"
#' @param test_above_log2_fold_change A positive real value. This works for edgeR and limma_voom methods. It uses the `treat` function, which tests that the difference in abundance is bigger than this threshold rather than zero \url{https://pubmed.ncbi.nlm.nih.gov/19176553}.
#' @param scaling_method A character string. The scaling method passed to the back-end functions: edgeR and limma-voom (i.e., edgeR::calcNormFactors; "TMM","TMMwsp","RLE","upperquartile"). Setting the parameter to \"none\" will skip the compensation for sequencing-depth for the method edgeR or limma-voom.
Expand All @@ -2127,6 +2127,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol)
#' @param action A character string. Whether to join the new information to the input tbl (add), or just get the non-redundant tbl with the new information (get).
#' @param significance_threshold DEPRECATED - A real between 0 and 1 (usually 0.05).
#' @param fill_missing_values DEPRECATED - A boolean. Whether to fill missing sample/transcript values with the median of the transcript. This is rarely needed.
#' @param .contrasts DEPRECATED - This parameter takes the format of the contrast parameter of the method of choice. For edgeR and limma-voom is a character vector. For DESeq2 is a list including a character vector of length three. The first covariate is the one the model is tested against (e.g., ~ factor_of_interest)
#' @param ... Further arguments passed to some of the internal functions. Currently, it is needed just for internal debug.
#'
#'
Expand Down Expand Up @@ -2189,7 +2190,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol)
#' identify_abundant() |>
#' test_differential_abundance(
#' ~ 0 + condition,
#' .contrasts = c( "conditionTRUE - conditionFALSE")
#' contrasts = c( "conditionTRUE - conditionFALSE")
#' )
#'
#' # DESeq2 - equivalent for limma-voom
Expand All @@ -2207,7 +2208,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol)
#' identify_abundant() |>
#' test_differential_abundance(
#' ~ 0 + condition,
#' .contrasts = list(c("condition", "TRUE", "FALSE")),
#' contrasts = list(c("condition", "TRUE", "FALSE")),
#' method="deseq2"
#' )
#'
Expand All @@ -2220,7 +2221,7 @@ setGeneric("test_differential_abundance", function(.data,
.sample = NULL,
.transcript = NULL,
.abundance = NULL,
.contrasts = NULL,
contrasts = NULL,
method = "edgeR_quasi_likelihood",
test_above_log2_fold_change = NULL,
scaling_method = "TMM",
Expand All @@ -2231,7 +2232,8 @@ setGeneric("test_differential_abundance", function(.data,

# DEPRECATED
significance_threshold = NULL,
fill_missing_values = NULL
fill_missing_values = NULL,
.contrasts = NULL
)
standardGeneric("test_differential_abundance"))

Expand All @@ -2242,7 +2244,7 @@ setGeneric("test_differential_abundance", function(.data,
.sample = NULL,
.transcript = NULL,
.abundance = NULL,
.contrasts = NULL,
contrasts = NULL,
method = "edgeR_quasi_likelihood",
test_above_log2_fold_change = NULL,
scaling_method = "TMM",
Expand All @@ -2254,7 +2256,8 @@ setGeneric("test_differential_abundance", function(.data,

# DEPRECATED
significance_threshold = NULL,
fill_missing_values = NULL
fill_missing_values = NULL,
.contrasts = NULL
)
{
# Get column names
Expand Down Expand Up @@ -2282,6 +2285,15 @@ setGeneric("test_differential_abundance", function(.data,

}

# DEPRECATION OF .constrasts
if (is_present(.contrasts) & !is.null(.contrasts)) {

# Signal the deprecation to the user
deprecate_warn("1.7.4", "tidybulk::test_differential_abundance(.contrasts = )", details = "The argument .contrasts is now deprecated please use contrasts (without the dot).")

contrasts = .contrasts
}

# Clearly state what counts are used
rlang::inform("=====================================
tidybulk says: All testing methods use raw counts, irrespective of if scale_abundance
Expand Down Expand Up @@ -2322,7 +2334,7 @@ such as batch effects (if applicable) in the formula.
.sample = !!.sample,
.transcript = !!.transcript,
.abundance = !!.abundance,
.contrasts = .contrasts,
.contrasts = contrasts,
method = method,
test_above_log2_fold_change = test_above_log2_fold_change,
scaling_method = scaling_method,
Expand All @@ -2338,7 +2350,7 @@ such as batch effects (if applicable) in the formula.
.sample = !!.sample,
.transcript = !!.transcript,
.abundance = !!.abundance,
.contrasts = .contrasts,
.contrasts = contrasts,
method = method,
test_above_log2_fold_change = test_above_log2_fold_change,
scaling_method = scaling_method,
Expand All @@ -2354,7 +2366,7 @@ such as batch effects (if applicable) in the formula.
.sample = !!.sample,
.transcript = !!.transcript,
.abundance = !!.abundance,
.contrasts = .contrasts,
.contrasts = contrasts,
method = method,
scaling_method = scaling_method,
omit_contrast_in_colnames = omit_contrast_in_colnames,
Expand All @@ -2372,10 +2384,6 @@ such as batch effects (if applicable) in the formula.
.data %>%
dplyr::left_join(.data_processed, by = quo_name(.transcript)) %>%

# # Arrange
# ifelse_pipe(.contrasts %>% is.null,
# ~ .x %>% arrange(FDR)) %>%

# Attach attributes
reattach_internals(.data_processed)

Expand All @@ -2386,18 +2394,9 @@ such as batch effects (if applicable) in the formula.

# Selecting the right columns
pivot_transcript(!!.transcript) %>%
# select(
# !!.transcript,
# get_x_y_annotation_columns(.data, !!.sample,!!.transcript, !!.abundance, NULL)$vertical_cols
# ) %>%
# distinct() %>%

dplyr::left_join(.data_processed, by = quo_name(.transcript)) %>%

# # Arrange
# ifelse_pipe(.contrasts %>% is.null,
# ~ .x %>% arrange(FDR)) %>%

# Attach attributes
reattach_internals(.data_processed)

Expand Down Expand Up @@ -2837,13 +2836,14 @@ setMethod("keep_abundant", "tidybulk", .keep_abundant)
#' @param .sample The name of the sample column
#' @param .entrez The ENTREZ ID of the transcripts/genes
#' @param .abundance The name of the transcript/gene abundance column
#' @param .contrasts = NULL,
#' @param contrasts This parameter takes the format of the contrast parameter of the method of choice. For edgeR and limma-voom is a character vector. For DESeq2 is a list including a character vector of length three. The first covariate is the one the model is tested against (e.g., ~ factor_of_interest)
#' @param methods A character vector. One or 3 or more methods to use in the testing (currently EGSEA errors if 2 are used). Type EGSEA::egsea.base() to see the supported GSE methods.
#' @param gene_sets A character vector or a list. It can take one or more of the following built-in collections as a character vector: c("h", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "kegg_disease", "kegg_metabolism", "kegg_signaling"), to be used with EGSEA buildIdx. c1 is human specific. Alternatively, a list of user-supplied gene sets can be provided, to be used with EGSEA buildCustomIdx. In that case, each gene set is a character vector of Entrez IDs and the names of the list are the gene set names.
#' @param species A character. It can be human, mouse or rat.
#' @param cores An integer. The number of cores available
#'
#' @param method DEPRECATED. Please use methods.
#' @param .contrasts DEPRECATED - This parameter takes the format of the contrast parameter of the method of choice. For edgeR and limma-voom is a character vector. For DESeq2 is a list including a character vector of length three. The first covariate is the one the model is tested against (e.g., ~ factor_of_interest)
#'
#' @details This wrapper executes ensemble gene enrichment analyses of the dataset using EGSEA (DOI:0.12688/f1000research.12544.1)
#'
Expand Down Expand Up @@ -2917,13 +2917,15 @@ setGeneric("test_gene_enrichment", function(.data,
.sample = NULL,
.entrez,
.abundance = NULL,
.contrasts = NULL,
contrasts = NULL,
methods = c("camera" , "roast" , "safe", "gage" , "padog" , "globaltest", "ora" ),
gene_sets = c("h", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "kegg_disease", "kegg_metabolism", "kegg_signaling"),
species,
cores = 10,

method = NULL # DEPRECATED
# DEPRECATED
method = NULL,
.contrasts = NULL
)
standardGeneric("test_gene_enrichment"))

Expand All @@ -2934,13 +2936,15 @@ setGeneric("test_gene_enrichment", function(.data,
.sample = NULL,
.entrez,
.abundance = NULL,
.contrasts = NULL,
contrasts = NULL,
methods = c("camera" , "roast" , "safe", "gage" , "padog" , "globaltest", "ora" ),
gene_sets = c("h", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "kegg_disease", "kegg_metabolism", "kegg_signaling"),
species,
cores = 10,

method = NULL # DEPRECATED
# DEPRECATED
method = NULL,
.contrasts = NULL
) {

# DEPRECATION OF reference function
Expand All @@ -2951,6 +2955,15 @@ setGeneric("test_gene_enrichment", function(.data,
methods = method
}

# DEPRECATION OF .constrasts
if (is_present(.contrasts) & !is.null(.contrasts)) {

# Signal the deprecation to the user
deprecate_warn("1.7.4", "tidybulk::test_differential_abundance(.contrasts = )", details = "The argument .contrasts is now deprecated please use contrasts (without the dot).")

contrasts = .contrasts
}

# Make col names
.sample = enquo(.sample)
.abundance = enquo(.abundance)
Expand Down Expand Up @@ -2993,7 +3006,7 @@ setGeneric("test_gene_enrichment", function(.data,
.sample = !!.sample,
.entrez = !!.entrez,
.abundance = !!.abundance,
.contrasts = .contrasts,
.contrasts = contrasts,
methods = methods,
gene_sets = gene_sets,
species = species,
Expand Down
34 changes: 27 additions & 7 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ setMethod(
#' @importFrom rlang inform
.test_differential_abundance_se = function(.data,
.formula,
.contrasts = NULL,
contrasts = NULL,
method = "edgeR_quasi_likelihood",
test_above_log2_fold_change = NULL,
scaling_method = "TMM",
Expand All @@ -1040,6 +1040,15 @@ setMethod(
...)
{

# DEPRECATION OF .constrasts
if (is_present(.contrasts) & !is.null(.contrasts)) {

# Signal the deprecation to the user
deprecate_warn("1.7.4", "tidybulk::test_differential_abundance(.contrasts = )", details = "The argument .contrasts is now deprecated please use contrasts (without the dot).")

contrasts = .contrasts
}

# Clearly state what counts are used
# Clearly state what counts are used
rlang::inform("=====================================
Expand Down Expand Up @@ -1068,7 +1077,7 @@ such as batch effects (if applicable) in the formula.
get_differential_transcript_abundance_bulk_SE(
.,
.formula,
.contrasts = .contrasts,
.contrasts = contrasts,
colData(.data),
method = method,
test_above_log2_fold_change = test_above_log2_fold_change,
Expand All @@ -1082,7 +1091,7 @@ such as batch effects (if applicable) in the formula.
grepl("voom", method) ~ get_differential_transcript_abundance_bulk_voom_SE(
.,
.formula,
.contrasts = .contrasts,
.contrasts = contrasts,
colData(.data),
method = method,
test_above_log2_fold_change = test_above_log2_fold_change,
Expand All @@ -1095,7 +1104,7 @@ such as batch effects (if applicable) in the formula.
tolower(method)=="deseq2" ~ get_differential_transcript_abundance_deseq2_SE(
.,
.formula,
.contrasts = .contrasts,
.contrasts = contrasts,
method = method,
scaling_method = scaling_method,
omit_contrast_in_colnames = omit_contrast_in_colnames,
Expand Down Expand Up @@ -1401,13 +1410,15 @@ setMethod("keep_abundant",
.sample = NULL,
.entrez,
.abundance = NULL,
.contrasts = NULL,
contrasts = NULL,
methods = c("camera" , "roast" , "safe", "gage" , "padog" , "globaltest", "ora" ),
gene_sets = c("h", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "kegg_disease", "kegg_metabolism", "kegg_signaling"),
species,
cores = 10,

method = NULL # DEPRECATED
# DEPRECATED
method = NULL,
.contrasts = NULL
) {

# DEPRECATION OF reference function
Expand All @@ -1418,6 +1429,15 @@ setMethod("keep_abundant",
methods = method
}

# DEPRECATION OF .constrasts
if (is_present(.contrasts) & !is.null(.contrasts)) {

# Signal the deprecation to the user
deprecate_warn("1.7.4", "tidybulk::test_differential_abundance(.contrasts = )", details = "The argument .contrasts is now deprecated please use contrasts (without the dot).")

contrasts = .contrasts
}

.entrez = enquo(.entrez)

# Check that there are no entrez missing
Expand Down Expand Up @@ -1465,7 +1485,7 @@ setMethod("keep_abundant",
)

my_contrasts =
.contrasts %>%
contrasts %>%
when(
length(.) > 0 ~ limma::makeContrasts(contrasts = ., levels = design),
~ NULL
Expand Down
Loading

0 comments on commit 18f4cf0

Please sign in to comment.