Get UniMod modification positions in a peptide sequence
get_mod_pos(sequence, mod_id, option = "only_pos")Character string. Peptide sequence with UniMod annotations,
e.g. "(UniMod:1)ACD(UniMod:35)EFG".
Character or numeric. Target UniMod ID to locate.
Character. Controls return format:
"only_pos" (default): integer vector of positions.
"with_aa": named list with $pos (positions) and $letter (amino acids).
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.
The function works in four steps:
Replace the target UniMod tag with placeholder %
Strip all remaining UniMod annotations
Locate % positions in the cleaned string
Subtract cumulative placeholder offsets
Example:
Input: (UniMod:8888)AAAPPL(UniMod:2114)SK(UniMod:2114)AEYLK
| Step | Result |
| Replace target | (UniMod:8888)AAAPPL%SK%AEYLK |
| Strip remaining | AAAPPL%SK%AEYLK |
Locate % | 7, 10 |
| Adjust offsets | 6, 9 |
# 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")