Skip to content

Commit

Permalink
Merge branch 'improve_assign_peptide_type_243' of https://github.com/…
Browse files Browse the repository at this point in the history
…jpquast/protti into improve_assign_peptide_type_243
  • Loading branch information
elena-krismer committed Sep 24, 2024
2 parents b1c94c9 + cd31c1e commit 008c498
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions R/assign_peptide_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ peptide_type <- function(...) {
#'
#' @examples
#' data <- data.frame(
#' aa_before = c("K", "S", "K", "S", "T", "M"),
#' last_aa = c("R", "K","R", "K", "Y", "K"),
#' aa_after = c("T", "R", "T", "R", "T", "R"),
#' protein_id = c("P1", "P1", "P3", "P3","P2", "P2"),
#' start_pos = c(2, 2, 1, 2, 1, 2),
#' aa_before = c("K", "S", "K", "S", "T", "M"),
#' last_aa = c("R", "K", "R", "K", "Y", "K"),
#' aa_after = c("T", "R", "T", "R", "T", "R"),
#' protein_id = c("P1", "P1", "P3", "P3", "P2", "P2"),
#' start_pos = c(2, 2, 1, 2, 1, 2),
#' )
#'
#' assign_peptide_type(data, aa_before, last_aa, aa_after, protein_id, start_pos)
Expand All @@ -72,35 +72,30 @@ assign_peptide_type <- function(data,
peptide_data <- data %>%
dplyr::distinct({{ aa_before }}, {{ last_aa }}, {{ aa_after }}, {{ protein_id }}, {{ start_pos }}, .keep_all = TRUE) %>%
dplyr::left_join(start_summary, by = rlang::as_name(rlang::enquo(protein_id))) %>%

# Determine N-terminal trypticity
dplyr::mutate(N_term_tryp = dplyr::if_else(
{{ aa_before }} == "" | {{ aa_before }} == "K" | {{ aa_before }} == "R",
TRUE,
FALSE
)) %>%

# Determine C-terminal trypticity
dplyr::mutate(C_term_tryp = dplyr::if_else(
{{ last_aa }} == "K" | {{ last_aa }} == "R" | {{ aa_after }} == "",
TRUE,
FALSE
)) %>%

# Assign peptide type based on N-term and C-term trypticity
dplyr::mutate(pep_type = dplyr::case_when(
N_term_tryp & C_term_tryp ~ "fully-tryptic",
N_term_tryp | C_term_tryp ~ "semi-tryptic",
TRUE ~ "non-tryptic"
)) %>%

# Reassign semi-tryptic peptides at position 2 to fully-tryptic if no start_pos == 1
dplyr::mutate(pep_type = dplyr::if_else(
pep_type == "semi-tryptic" & {{ start_pos }} == 2 & !.data$has_start_pos_1 & C_term_tryp,
"fully-tryptic",
.data$pep_type
)) %>%

# Drop unnecessary columns
dplyr::select(-N_term_tryp, -C_term_tryp, -has_start_pos_1)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-auxiliary_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (Sys.getenv("TEST_PROTTI") == "true") {
expect_is(assigned_types, "data.frame")
expect_equal(nrow(assigned_types), 6)
expect_equal(ncol(assigned_types), 9)
expect_equal(assigned_types$pep_type, c("fully-tryptic", "semi-tryptic", "non-tryptic", "non-tryptic", "fully-tryptic","fully-tryptic"))
expect_equal(assigned_types$pep_type, c("fully-tryptic", "semi-tryptic", "non-tryptic", "non-tryptic", "fully-tryptic", "fully-tryptic"))
})

assigned_types <- data %>%
Expand Down

0 comments on commit 008c498

Please sign in to comment.