Get UniMod modification positions in a peptide sequence

get_mod_pos(sequence, mod_id, option = "only_pos")

Arguments

sequence

Character string. Peptide sequence with UniMod annotations, e.g. "(UniMod:1)ACD(UniMod:35)EFG".

mod_id

Character or numeric. Target UniMod ID to locate.

option

Character. Controls return format:

  • "only_pos" (default): integer vector of positions.

  • "with_aa": named list with $pos (positions) and $letter (amino acids).

Value

  • If option = "only_pos": integer vector of modification positions.

  • If option = "with_aa": list with elements $letter and $pos.

Position 0 indicates N-terminal; position 1 indicates the first amino acid.

Details

The function works in four steps:

  1. Replace the target UniMod tag with placeholder %

  2. Strip all remaining UniMod annotations

  3. Locate % positions in the cleaned string

  4. Subtract cumulative placeholder offsets

Example:

Input: (UniMod:8888)AAAPPL(UniMod:2114)SK(UniMod:2114)AEYLK

StepResult
Replace target(UniMod:8888)AAAPPL%SK%AEYLK
Strip remainingAAAPPL%SK%AEYLK
Locate %7, 10
Adjust offsets6, 9

Examples

# Only positions (default)
get_mod_pos("(UniMod:8888)AAAPPL(UniMod:2114)SK(UniMod:2114)AEYLK", "2114")
#> [1] 6 8
#> [1] 6 9

# With amino acid letters
get_mod_pos("(UniMod:8888)AAAPPL(UniMod:2114)SK(UniMod:2114)AEYLK", "2114",
            option = "with_aa")
#> $letter
#> [1] "L" "K"
#> 
#> $pos
#> [1] 6 8
#> 
#> $letter
#> [1] "L" "K"
#> $pos
#> [1] 6 9

# N-terminal modification (returns 0)
get_mod_pos("(UniMod:2114)AAAPPLK", "2114")
#> [1] 0
#> [1] 0

# Batch processing
df <- data.frame(
  sequence = c(
    "(UniMod:8888)AAAPPL(UniMod:2114)SKAEYLK(UniMod:2114)",
    "G(UniMod:2114)KAA"
  )
)
df$positions <- sapply(df$sequence, get_mod_pos, mod_id = "2114")