Skip to content

Commit

Permalink
Merge pull request #311 from stemangiola/fix-interactions-for-DE
Browse files Browse the repository at this point in the history
Fix interactions for de
  • Loading branch information
stemangiola committed Feb 7, 2024
2 parents c0f4e86 + 40d3c76 commit d926956
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidybulk
Title: Brings transcriptomics to the tidyverse
Version: 1.15.5
Version: 1.15.6
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
role = c("aut", "cre")),
person("Maria", "Doyle", email = "[email protected]",
Expand Down
6 changes: 6 additions & 0 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ get_differential_transcript_abundance_bulk <- function(.data,
data = df_for_edgeR %>% select(!!.sample, one_of(parse_formula(.formula))) %>% distinct %>% arrange(!!.sample)
)

# Replace `:` with ___ because it creates error with edgeR
if(design |> colnames() |> str_detect(":") |> any()) {
message("tidybulk says: the interaction term `:` has been replaced with `___` in the design matrix, in order to work with edgeR.")
colnames(design) = design |> colnames() |> str_replace(":", "___")
}

# Print the design column names in case I want contrasts
message(
sprintf(
Expand Down
6 changes: 6 additions & 0 deletions R/functions_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,12 @@ get_differential_transcript_abundance_bulk_SE <- function(.data,
data = sample_annotation
)

# Replace `:` with ___ because it creates error with edgeR
if(design |> colnames() |> str_detect(":") |> any()) {
message("tidybulk says: the interaction term `:` has been replaced with `___` in the design matrix, in order to work with edgeR.")
colnames(design) = design |> colnames() |> str_replace(":", "___")
}

# Print the design column names in case I want contrasts
message(
sprintf(
Expand Down
27 changes: 18 additions & 9 deletions tests/testthat/test-bulk_methods_SummarizedExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ test_that("tidybulk SummarizedExperiment normalisation",{

})


test_that("quantile normalisation",{

res = se_mini |> quantile_normalise_abundance()
Expand Down Expand Up @@ -109,7 +108,6 @@ test_that("quantile normalisation",{

})


test_that("tidybulk SummarizedExperiment normalisation subset",{

res = se |> identify_abundant() |> scale_abundance(
Expand All @@ -124,10 +122,6 @@ test_that("tidybulk SummarizedExperiment normalisation subset",{

})





test_that("tidybulk SummarizedExperiment clustering",{

res = cluster_elements(se, method="kmeans", centers = 2)
Expand Down Expand Up @@ -357,7 +351,6 @@ test_that("differential trancript abundance - SummarizedExperiment",{

})


test_that("differential trancript abundance - SummarizedExperiment - alternative .abundance",{

assays(se_mini) = list(counts = assay(se_mini), bla = assay(se_mini))
Expand Down Expand Up @@ -437,6 +430,24 @@ test_that("differential trancript abundance - SummarizedExperiment - alternative

})

test_that("DE interaction effects", {

# Att interaction factor
col_data = colData(breast_tcga_mini_SE)
set.seed(42)
col_data$interaction_term = sample(c(0,1), size = nrow(col_data), replace = TRUE)
colData(breast_tcga_mini_SE) = col_data

breast_tcga_mini_SE |>
identify_abundant(factor_of_interest = Call) |>
test_differential_abundance(
~ Call * interaction_term,
contrasts = "CallHer2___interaction_term",
method="edgeR_quasi_likelihood"
) |>
expect_no_error()

})

test_that("Voom with treat method",{

Expand Down Expand Up @@ -524,8 +535,6 @@ test_that("differential trancript abundance - random effects SE",{

})



test_that("filter abundant - SummarizedExperiment",{

res = keep_abundant( se )
Expand Down

0 comments on commit d926956

Please sign in to comment.