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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* `calculate_peptide_abundance()` new function to calculate peptide abundances from precursor abundances.
* `fit_drc_4p()` received the `show_progress` argument that is by default `TRUE` and allows the user to show or hide progress bars. This closes issue #278.
* `assign_missingness()` gained the `completeness_MNAR_reference` argument, allowing users to control how complete a condition must be to be considered sufficiently observed when assigning MNAR missingness. This closes issue #200.
* `calculate_aa_scores()` gained a `methods` argument, allowing user to choose between additive or the new multiplicative score calculation mode. The function now also returns min-max normalised scores in addition to raw values.

## Bug fixes

Expand Down
37 changes: 33 additions & 4 deletions R/calculate_aa_scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#' data frame. Default is not retaining additional columns \code{retain_columns = NULL}. Specific
#' columns can be retained by providing their names (not in quotations marks, just like other
#' column names, but in a vector).
#' @param method a character argument selecting the method used for score calculation.
#' Supported are "multiplicative" = `-log10(adj_pval) * abs(diff)` (default) or "additive" = `-log10(adj_pval) + abs(diff)`.
#'
#' @return A data frame that contains the aggregated scores per amino acid position, enabling to
#' draw fingerprints for each individual protein.
Expand Down Expand Up @@ -51,30 +53,57 @@ calculate_aa_scores <- function(data,
adj_pval = adj_pval,
start_position,
end_position,
retain_columns = NULL) {
retain_columns = NULL,
method = "multiplicative") {
# validate method input
method <- match.arg(method, c("multiplicative", "additive"))

output <- data %>%
Comment thread
lukasvonziegler marked this conversation as resolved.
dplyr::ungroup() %>%
dplyr::distinct({{ protein }}, {{ diff }}, {{ adj_pval }}, {{ start_position }}, {{ end_position }}) %>%
tidyr::drop_na({{ diff }}, {{ adj_pval }}) %>%
dplyr::mutate(score = -log10({{ adj_pval }}) * abs({{ diff }})) %>%
dplyr::mutate(
score = if (method == "multiplicative") {
-log10({{ adj_pval }}) * abs({{ diff }})
} else if (method == "additive") {
-log10({{ adj_pval }}) + abs({{ diff }})
}
) %>%
Comment thread
lukasvonziegler marked this conversation as resolved.
dplyr::rowwise() %>%
dplyr::mutate(residue = list(seq({{ start_position }}, {{ end_position }}))) %>%
tidyr::unnest("residue") %>%
dplyr::group_by({{ protein }}, .data$residue) %>%
dplyr::mutate(amino_acid_score = mean(.data$score)) %>%
dplyr::distinct({{ protein }}, .data$residue, .data$amino_acid_score)

# normalization (per protein)
output <- output %>%
dplyr::group_by({{ protein }}) %>%
dplyr::mutate(
amino_acid_score_normalized = {
min_val <- min(.data$amino_acid_score, na.rm = TRUE)
max_val <- max(.data$amino_acid_score, na.rm = TRUE)
if (max_val == min_val) {
1 # avoid division by zero; constant protein gets 1
} else {
(.data$amino_acid_score - min_val) / (max_val - min_val)
}
}
) %>%
dplyr::ungroup()

if (!missing(retain_columns)) {
output <- data %>%
dplyr::select(!!enquo(retain_columns), colnames(output)[!colnames(output) %in% c(
"residue",
"amino_acid_score"
"amino_acid_score",
"amino_acid_score_normalized"
)]) %>%
dplyr::distinct() %>%
dplyr::right_join(output, by = colnames(output)[!colnames(output) %in% c(
"residue",
"amino_acid_score"
"amino_acid_score",
"amino_acid_score_normalized"
)])
}

Expand Down
2 changes: 1 addition & 1 deletion R/calculate_go_enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ if you used the right organism ID.", prefix = "\n", initial = ""))
groups_to_skip <- cont_table %>%
dplyr::group_by({{ group }}) %>%
dplyr::summarise(n_levels = dplyr::n_distinct({{ is_significant }}), .groups = "drop") %>%
dplyr::filter(n_levels < 2) %>%
dplyr::filter(.data$n_levels < 2) %>%
dplyr::pull({{ group }})

cont_table <- cont_table %>%
Expand Down
4 changes: 2 additions & 2 deletions R/qc_sample_correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ qc_sample_correlation <- function(data,
heatmap_interactive <-
heatmaply::heatmaply(
correlation,
main = "Correlation based hirachical clustering of samples",
main = "Correlation based hierarchical clustering of samples",
col_side_colors = annotation,
col_side_palette = c(
annotation_colours[[1]],
Expand Down Expand Up @@ -190,7 +190,7 @@ qc_sample_correlation <- function(data,
cluster_cols = stats::as.hclust(dendrogram_column),
annotation = annotation,
annotation_colors = annotation_colours,
main = "Correlation based hierachical clustering of samples",
main = "Correlation based hierarchical clustering of samples",
color = viridis_colours,
silent = TRUE
)
Expand Down
6 changes: 5 additions & 1 deletion man/calculate_aa_scores.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ test_that("calculate_aa_scores works", {

expect_is(aa_fingerprint, "data.frame")
expect_equal(nrow(aa_fingerprint), 45)
expect_equal(ncol(aa_fingerprint), 3)
expect_equal(ncol(aa_fingerprint), 4)
})

# Test for random forest imputation
Expand Down