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

fixes #293

Merged
merged 1 commit into from
Sep 8, 2023
Merged

fixes #293

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
53 changes: 30 additions & 23 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ get_differential_transcript_abundance_glmmSeq <- function(.data,
.abundance = enquo(.abundance)
.sample_total_read_count = enquo(.sample_total_read_count)
.dispersion = enquo(.dispersion)

# Check if omit_contrast_in_colnames is correctly setup
if(omit_contrast_in_colnames & length(.contrasts) > 1){
warning("tidybulk says: you can omit contrasts in column names only when maximum one contrast is present")
Expand Down Expand Up @@ -757,27 +757,27 @@ get_differential_transcript_abundance_glmmSeq <- function(.data,

# Reorder counts
counts = counts[,rownames(metadata),drop=FALSE]

if(quo_is_symbolic(.dispersion))
dispersion = .data |> pivot_transcript(!!.transcript) |> select(!!.transcript, !!.dispersion) |> deframe()
else
dispersion = setNames(edgeR::estimateDisp(counts)$tagwise.dispersion, rownames(counts))

# # Check dispersion
# if(!names(dispersion) |> sort() |> identical(
# rownames(counts) |>
# sort()
# )) stop("tidybulk says: The features in the dispersion vector do not overlap with the feature in the assay")

# Make sure the order matches the counts
dispersion = dispersion[rownames(counts)]
glmmSeq_object =

glmmSeq_object =
glmmSeq( .formula,
countdata = counts ,
metadata = metadata,
dispersion = dispersion,
progress = TRUE,
progress = TRUE,
method = method |> str_remove("(?i)^glmmSeq_"),
...
)
Expand Down Expand Up @@ -3974,6 +3974,10 @@ fill_NA_using_value = function(.data,
# filter(how_many_bimod == 0)


#' @details
#' This function plots the GSEA for gene overrepresentation
#'
#'
#' @keywords internal
#' @noRd
#'
Expand Down Expand Up @@ -4031,6 +4035,8 @@ entrez_over_to_gsea = function(my_entrez_rank, species, gene_collections = NULL
}


#' @details
#' This function plots the GSEA for gene overrepresentation
#'
#' @keywords internal
#' @noRd
Expand Down Expand Up @@ -4066,20 +4072,21 @@ entrez_rank_to_gsea = function(my_entrez_rank, species, gene_collections = NULL
}

# Get gene sets signatures
my_gene_collection =
gene_collections %>%
when(
is.null(gene_collections ) ~ msigdbr::msigdbr(species = species) ,
is(., "character") ~ msigdbr::msigdbr(species = species) %>% filter( gs_cat %in% gene_collections ),
is(., "list") ~
tibble(gs_name=names(.), entrez_gene = . ) %>% unnest(entrez_gene) %>% mutate(gs_cat = "user_defined"),
~ stop("tidybulk says: the gene sets should be either a character vector or a named list")
)
my_gene_collection %>%
if(is.null(gene_collections ) )
my_gene_collection = msigdbr::msigdbr(species = species)
else if(gene_collections |> is("character"))
my_gene_collection = msigdbr::msigdbr(species = species) %>% filter( tolower(gs_cat) %in% tolower(gene_collections) )
else if(gene_collections |> is("list"))
my_gene_collection = tibble(gs_name=names(.), entrez_gene = . ) %>% unnest(entrez_gene) %>% mutate(gs_cat = "user_defined")
else
stop("tidybulk says: the gene sets should be either a character vector or a named list")


my_gene_collection |>


# Execute calculation
nest(data = -gs_cat) %>%
nest(data = -gs_cat) |>
mutate(fit =
map(
data,
Expand All @@ -4089,18 +4096,18 @@ entrez_rank_to_gsea = function(my_entrez_rank, species, gene_collections = NULL
pvalueCutoff = 1
)

)) %>%
)) |>
mutate(test =
map(
fit,
~ .x %>%
ggplot2::fortify(showCategory=Inf) %>%
as_tibble() %>%
~ .x |>
# ggplot2::fortify(showCategory=Inf) %>%
as_tibble() |>
rowid_to_column(var = "idx_for_plotting")
#%>%
# mutate(plot = future_imap(ID, ~ enrichplot::gseaplot2(fit, geneSetID = .y, title = .x)))

)) %>%
)) |>
select(-data)


Expand Down
12 changes: 6 additions & 6 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -3928,10 +3928,10 @@ setGeneric("test_gene_rank", function(.data,
}

# Get column names
.sample = enquo(.sample)
.sample = get_sample(.data, .sample)$.sample
.arrange_desc = enquo(.arrange_desc)
.entrez = enquo(.entrez)
.sample = enquo(.sample)
.sample = get_sample(.data, .sample)$.sample
.arrange_desc = enquo(.arrange_desc)
.entrez = enquo(.entrez)

# Check if ranking is set
if(quo_is_missing(.arrange_desc))
Expand All @@ -3953,13 +3953,13 @@ setGeneric("test_gene_rank", function(.data,
stop(sprintf("tidybulk says: wrong species name. MSigDB uses the latin species names (e.g., %s)", paste(msigdbr::msigdbr_species()$species_name, collapse=", ")))

# Check if missing entrez
if(.data |> filter(!!.entrez |> is.na()) |> nrow() |> gt(0) ){
if(.data |> filter(is.na(!!.entrez)) |> nrow() > 0 ){
warning("tidybulk says: there are .entrez that are NA. Those will be removed")
.data = .data |> filter(!!.entrez |> is.na() |> not())
}

# Check if missing .arrange_desc
if(.data |> filter(!!.arrange_desc |> is.na()) |> nrow() |> gt(0) ){
if(.data |> filter(is.na(!!.arrange_desc)) |> nrow() > 0 ){
warning("tidybulk says: there are .arrange_desc that are NA. Those will be removed")
.data = .data |> filter(!!.arrange_desc |> is.na() |> not())
}
Expand Down
Loading