Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 23 additions & 36 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ get_differential_transcript_abundance_bulk <- function(.data,
distinct() %>%

# drop factors as it can affect design matrix
mutate_if(is.factor, as.character())
droplevels()
#%>%

# # Check if data rectangular
Expand Down Expand Up @@ -537,7 +537,7 @@ get_differential_transcript_abundance_bulk_voom <- function(.data,
distinct() %>%

# drop factors as it can affect design matrix
mutate_if(is.factor, as.character())
droplevels()
# %>%

# # Check if data rectangular
Expand Down Expand Up @@ -743,15 +743,7 @@ get_differential_transcript_abundance_deseq2 <- function(.data,
distinct() %>%

# drop factors as it can affect design matrix
mutate_if(is.factor, as.character()) %>%

# # Check if data rectangular
# ifelse2_pipe(
# (.) %>% check_if_data_rectangular(!!.sample,!!.transcript,!!.abundance) %>% not() & fill_missing_values,
# (.) %>% check_if_data_rectangular(!!.sample,!!.transcript,!!.abundance) %>% not() & !fill_missing_values,
# ~ .x %>% fill_NA_using_formula(.formula,!!.sample, !!.transcript, !!.abundance),
# ~ .x %>% eliminate_sparse_transcripts(!!.transcript)
# ) %>%
droplevels() %>%

# Needed for DESeq2
mutate(!!.abundance := as.integer(!!.abundance)) %>%
Expand All @@ -770,25 +762,27 @@ get_differential_transcript_abundance_deseq2 <- function(.data,
deseq2_object %>%

# If I have multiple .contrasts merge the results
ifelse_pipe(
my_contrasts %>% is.null | omit_contrast_in_colnames,

when(

# Simple comparison
~ .x %>%

(my_contrasts %>% is.null | omit_contrast_in_colnames) & (deseq2_object@colData[,parse_formula(.formula)[1]] %>% class %in% c("numeric", "integer", "double")) ~
(.) %>%
DESeq2::results() %>%
as_tibble(rownames = quo_name(.transcript))
# %>%

# # Mark DE genes
# mutate(significant = padj < significance_threshold) %>%

# # Arrange
# arrange(padj),

# Multiple comparisons
as_tibble(rownames = quo_name(.transcript)),

# Simple comparison
my_contrasts %>% is.null | omit_contrast_in_colnames ~
(.) %>%
DESeq2::results(contrast = c(
parse_formula(.formula)[1],
deseq2_object@colData[,parse_formula(.formula)[1]] %>% levels %>% .[2],
deseq2_object@colData[,parse_formula(.formula)[1]] %>% levels %>% .[1]
)) %>%
as_tibble(rownames = quo_name(.transcript)),

# Multiple comparisons NOT USED AT THE MOMENT
~ {
deseq2_obj = .x
deseq2_obj = (.)

1:ncol(my_contrasts) %>%
map_dfr(
Expand All @@ -800,21 +794,13 @@ get_differential_transcript_abundance_deseq2 <- function(.data,
# Convert to tibble
as_tibble(rownames = quo_name(.transcript)) %>%
mutate(constrast = colnames(my_contrasts)[.x])
# %>%
#
# # Mark DE genes
# mutate(significant = padj < significance_threshold)

) %>%
pivot_wider(values_from = -c(!!.transcript, constrast),
names_from = constrast, names_sep = "___")
}
) %>%

# # Add filtering info
# right_join(.data %>% distinct(!!.transcript)) %>%
# when(!"lowly_abundant" %in% colnames(.data) ~ (.) %>% mutate(lowly_abundant = if_else(is.na(log2FoldChange), T, F)) ,
# ~ (.)) %>%

# Attach prefix
setNames(c(
colnames(.)[1],
Expand All @@ -827,6 +813,7 @@ get_differential_transcript_abundance_deseq2 <- function(.data,

# Add raw object
attach_to_internals(deseq2_object, "DESeq2") %>%

# Communicate the attribute added
{
message(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-bulk_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ test_that("DESeq2 differential trancript abundance - no object",{
res_deseq2 =
test_deseq2_df %>%
DESeq2::DESeq() %>%
results()
DESeq2::results()

res_tidybulk =
test_deseq2_df %>%
Expand Down Expand Up @@ -552,7 +552,7 @@ test_that("DESeq2 differential trancript abundance - no object",{

expect_equal(
unique(res$log2FoldChange)[1:4],
c(-12.322037, -11.670005 , -9.048954 ,-12.603183),
c(3.449740, 2.459516, 2.433466, 1.951263),
tolerance=1e-6
)

Expand Down Expand Up @@ -580,7 +580,7 @@ test_that("DESeq2 differential trancript abundance - no object",{

expect_equal(
unique(res$log2FoldChange)[1:4],
c(-3.656244 ,-3.241215, -3.037658, 4.173217),
c(-1.1906895, -0.4422231, 0.9656122, -0.3328515),
tolerance=1e-6
)

Expand All @@ -605,7 +605,7 @@ test_that("DESeq2 differential trancript abundance - no object",{

expect_equal(
unique(res$log2FoldChange)[1:4],
c(-10.432623, -6.747017, -7.598174 , 6.598429),
c(1.1110210, 3.0077779, 0.9024256, 4.7259792),
tolerance=1e-6
)

Expand Down
2 changes: 1 addition & 1 deletion vignettes/manuscript_transcriptional_signatures.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vignette: >
%\usepackage[UTF-8]{inputenc}
---

This decument includes the code used for the manuscript, for the transcriptional signature identification.
This document includes the code used for the manuscript, for the transcriptional signature identification.


```{r, echo=FALSE, include=FALSE}
Expand Down