Skip to content

Commit

Permalink
Add new argument to calculate_go_enrichment
Browse files Browse the repository at this point in the history
also allow for group to be a factor
  • Loading branch information
jpquast committed Sep 23, 2024
1 parent 645ce60 commit 9555161
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions R/calculate_go_enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ go_enrichment <- function(...) {
#' should be reversed in order. Default is `TRUE`.
#' @param label a logical argument indicating whether labels should be added to the plot.
#' Default is TRUE.
#' @param label_size a numeric argument that specifies the text size of the labels with the unit "pt".
#' The default is 5.
#' @param enrichment_type a character argument that is either "all", "enriched" or "deenriched". This
#' determines if the enrichment analysis should be performed in order to check for both enrichemnt and
#' deenrichemnt or only one of the two. This affects the statistics performed and therefore also the displayed
Expand Down Expand Up @@ -223,6 +225,7 @@ calculate_go_enrichment <- function(data,
heatmap_fill_colour = protti::mako_colours,
heatmap_fill_colour_rev = TRUE,
label = TRUE,
label_size = 5,
enrichment_type = "all",
replace_long_name = TRUE,
label_move_frac = 0.2,
Expand Down Expand Up @@ -408,12 +411,14 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
}

result_table <- cont_table %>%
dplyr::arrange({{ group }}) %>%
{ # group argument is missing
if (group_missing) {
dplyr::left_join(., fisher_test, by = "go_id")
} else {
# group argument is not missing
dplyr::left_join(., fisher_test, by = c("go_id", rlang::as_name(enquo(group)))) %>%
dplyr::mutate({{ group }} := forcats::fct_inorder({{ group }})) %>%
dplyr::group_by({{ group }})
}
} %>%
Expand Down Expand Up @@ -528,7 +533,8 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
"%)"
),
y = .data$neg_log_sig - 0.1,
hjust = .data$hjust
hjust = .data$hjust,
size = label_size/.pt
)
)
}
Expand Down Expand Up @@ -605,7 +611,11 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
if (group_missing) {
dplyr::mutate(., grouping = "")
} else {
dplyr::mutate(., grouping = forcats::fct_inorder({{ group }}))
if(!is(dplyr::pull(plot_input, {{ group }}), "factor")){ # if the column is already a factor do not reorder
dplyr::mutate(., grouping = forcats::fct_inorder({{ group }}))
} else {
dplyr::mutate(., grouping = {{ group }})
}
}
}

Expand Down Expand Up @@ -659,7 +669,8 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
NA
)
),
colour = plot_input_heatmap$text_col
colour = plot_input_heatmap$text_col,
size = label_size/.pt
)
}
} +
Expand Down
4 changes: 4 additions & 0 deletions man/calculate_go_enrichment.Rd

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

0 comments on commit 9555161

Please sign in to comment.