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

Calculate go enrichment improvement #276

Merged
merged 10 commits into from
Oct 31, 2024
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# protti 0.9.1.9000

## New features

* `calculate_go_enrichment()` received the argument `label_size` that allows the user to specifiy the size of the labels in the plot.

## Bug fixes

* Fixed issue #193. This makes sure that information in retained columns can be propagated to newly created combinations, which were not present in the original data.
* `calculate_go_enrichment()` can now correctly handle groups that are of type factor.

## Additional Changes

Expand Down
24 changes: 20 additions & 4 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 7.
#' @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 = 7,
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 @@ -529,12 +534,16 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
),
y = .data$neg_log_sig - 0.1,
hjust = .data$hjust
)
),
size = label_size / .pt
)
}
} +
ggplot2::scale_fill_manual(values = c(Deenriched = barplot_fill_colour[1], Enriched = barplot_fill_colour[2])) +
ggplot2::scale_y_continuous(labels = scales::number_format(accuracy = 1)) +
ggplot2::scale_y_continuous(
labels = scales::number_format(accuracy = 1),
expand = expansion(mult = c(0, 0.05))
) +
ggplot2::coord_flip() +
{
if (!missing(group)) {
Expand Down Expand Up @@ -605,7 +614,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,10 +672,13 @@ 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
)
}
} +
ggplot2::scale_x_discrete(expand = expansion(mult = c(0, 0))) +
ggplot2::scale_y_discrete(expand = expansion(mult = c(0, 0))) +
ggplot2::scale_fill_gradientn(colours = colours) +
ggplot2::labs(
title = plot_title,
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.

Loading