Peptide Annotation and Protein Inference

Introduction

This Vignette describes how the greedy_parsimony() function can be used to infer proteins from peptide identifications using the Occam’s razor principle. The method tries to find a minimal set of proteins which can explain all the peptides identified.

library(prozor)
library(dplyr)
library(ggplot2)

file <- system.file("extdata/IDResults.txt.gz", package = "prozor")
id_results <- utils::read.delim(file)
head(id_results) |> knitr::kable()
RefSpectraId numPeaks peptideSeq precursorCharge precursorMZ retentionTime copies peptideModSeq score lengthPepSeq fileName SpecIDinFile
9908 57 GPDVLTATVSGK 2 572.8143 73.61667 1 GPDVLTATVSGK 0.0000015 12 2 80138
36028 70 VPQVSTPTLVEVSR 3 504.6196 93.26667 1 VPQVSTPTLVEVSR 0.0000868 14 5 176230
74786 177 EVQLVETGGGLIQPGGSLR 3 637.3509 120.60000 1 EVQLVETGGGLIQPGGSLR 0.0062764 19 10 285759
53362 184 AQPVQVAEGSEPDGFWEALGGK 3 758.0356 129.11670 1 AQPVQVAEGSEPDGFWEALGGK 0.0000001 22 7 350198
48668 157 KYLYEIAR 2 528.2979 69.81667 1 KYLYEIAR 0.0742509 8 7 59857
90153 158 AQLVPLPPSTYVEFTVSGTDCVAK 3 860.4459 136.73330 1 AQLVPLPPSTYVEFTVSGTDC[+57.0]VAK 0.0000023 24 12 385011

Annotate peptide sequences with protein sequences from two FASTA files, one with reviewed entries only (sp) and the other with reviewed and TrEMBL entries (sp/tr).

fasta_all <- read_fasta(system.file("p1000_db1_example/Annotation_allSeq.fasta.gz", package = "prozor"))
fasta_canonical <- read_fasta(system.file("p1000_db1_example/Annotation_canSeq.fasta.gz", package = "prozor"))

db_sizes <- data.frame(database = c("All", "Canonical"), proteins = c(length(fasta_all), length(fasta_canonical)))
ggplot(db_sizes, aes(x = database, y = proteins)) +
  geom_col(fill = "#0072B2") +
  geom_text(aes(label = proteins), vjust = -0.3) +
  labs(x = NULL, y = "proteins")
Number of proteins in the All and Canonical database.

Number of proteins in the All and Canonical database.

peptides <- unique(id_results$peptideSeq)
length(peptides)
## [1] 1520
annotation_all <- annotate_peptides(peptides, fasta_all)
head(select(annotation_all, !protein_sequence)) |> knitr::kable()
peptide_seq protein_id offset matched peptide_length
AACAQLNDFLQEYGTQGCQV sp|P0C0L4-2|CO4A_HUMAN 1679 TRUE 20
AACAQLNDFLQEYGTQGCQV tr|A0A140TA49|A0A140TA49_HUMAN 1679 TRUE 20
AACAQLNDFLQEYGTQGCQV tr|A0A140TA29|A0A140TA29_HUMAN 1679 TRUE 20
AACAQLNDFLQEYGTQGCQV tr|F5GXS0|F5GXS0_HUMAN 1679 TRUE 20
AACAQLNDFLQEYGTQGCQV tr|A0A140TA44|A0A140TA44_HUMAN 1679 TRUE 20
AACAQLNDFLQEYGTQGCQV tr|A0A0G2JPR0|A0A0G2JPR0_HUMAN 1725 TRUE 20
annotation_canonical <- annotate_peptides(peptides, fasta_canonical)
matches <- data.frame(database = c("All", "Canonical"), matches = c(nrow(annotation_all), nrow(annotation_canonical)))
ggplot(matches, aes(x = database, y = matches)) +
  geom_col(fill = "#0072B2") +
  geom_text(aes(label = matches), vjust = -0.3) +
  labs(x = NULL, y = "peptide protein matches")
Number of peptide protein matches for the All and Canonical database.

Number of peptide protein matches for the All and Canonical database.

We can see that using the larger FASTA database reduces the proportion of proteotypic peptides. A proteotypic peptide is one which matches only a single protein.

proteotypic <- data.frame(
  database = c("All", "Canonical"),
  percent = c(
    mean(table(annotation_all$peptide_seq) == 1) * 100,
    mean(table(annotation_canonical$peptide_seq) == 1) * 100
  )
)
ggplot(proteotypic, aes(x = database, y = percent)) +
  geom_col(fill = "#0072B2") +
  geom_text(aes(label = sprintf("%.1f %%", percent)), vjust = -0.3) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(x = NULL, y = "% proteotypic peptides")
Proportion of proteotypic peptides.

Proportion of proteotypic peptides.

Protein Inference

We can now identify a minimal set of proteins explaining all the peptides observed for both databases. greedy_parsimony() takes a table with one row per peptide-protein match; a peptide observed as several precursors gives repeated rows, which count once.

precursors <- distinct(id_results, peptideModSeq, precursorCharge, peptideSeq)

# peptide protein matches as points; rows and columns sorted by their number of matches,
# proteotypic peptides (one protein) in red
plot_matches <- function(annotation) {
  pairs <- distinct(annotation, peptide = factor(peptideSeq), protein = factor(protein_id))
  peptide_matches <- tabulate(pairs$peptide, nlevels(pairs$peptide))
  peptide_rank <- rank(-peptide_matches, ties.method = "first")
  protein_rank <- rank(-tabulate(pairs$protein, nlevels(pairs$protein)), ties.method = "first")
  matches <- data.frame(
    peptide = peptide_rank[pairs$peptide],
    protein = protein_rank[pairs$protein],
    proteotypic = peptide_matches[pairs$peptide] == 1
  )
  ggplot(matches) +
    geom_point(aes(x = protein, y = peptide, colour = proteotypic), shape = 15, size = 0.5) +
    scale_colour_manual(
      name = NULL,
      values = c(`FALSE` = "black", `TRUE` = "red"),
      labels = c(`FALSE` = "shared", `TRUE` = "proteotypic")
    ) +
    scale_y_reverse() +
    labs(x = "proteins, most peptides first", y = "peptides, most proteins first")
}

Protein Inference for database with TrEMBL identifiers

annotated_precursors <- inner_join(
  precursors,
  select(annotation_all, peptide_seq, protein_id),
  by = join_by(peptideSeq == peptide_seq),
  relationship = "many-to-many"
)

head(annotated_precursors) |> knitr::kable()
peptideModSeq precursorCharge peptideSeq protein_id
GPDVLTATVSGK 2 GPDVLTATVSGK sp|Q14624|ITIH4_HUMAN
GPDVLTATVSGK 2 GPDVLTATVSGK tr|H7C0L5|H7C0L5_HUMAN
GPDVLTATVSGK 2 GPDVLTATVSGK sp|Q14624-3|ITIH4_HUMAN
GPDVLTATVSGK 2 GPDVLTATVSGK sp|Q14624-4|ITIH4_HUMAN
GPDVLTATVSGK 2 GPDVLTATVSGK sp|Q14624-2|ITIH4_HUMAN
GPDVLTATVSGK 2 GPDVLTATVSGK tr|B7ZKJ8|B7ZKJ8_HUMAN
c(
  peptides = n_distinct(annotated_precursors$peptideSeq),
  proteins = n_distinct(annotated_precursors$protein_id)
)
## peptides proteins 
##     1433     1072
plot_matches(annotated_precursors)
Peptide protein matches for the All database. Rows - peptides, columns - proteins, point - peptide protein match, red - proteotypic peptide.

Peptide protein matches for the All database. Rows - peptides, columns - proteins, point - peptide protein match, red - proteotypic peptide.

groups_all <- greedy_parsimony(annotated_precursors, peptide = "peptideSeq")

Protein Inference for Reviewed/Canonical database

annotated_precursors <- inner_join(
  precursors,
  select(annotation_canonical, peptide_seq, protein_id),
  by = join_by(peptideSeq == peptide_seq),
  relationship = "many-to-many"
)

c(
  peptides = n_distinct(annotated_precursors$peptideSeq),
  proteins = n_distinct(annotated_precursors$protein_id)
)
## peptides proteins 
##     1430      382
plot_matches(annotated_precursors)
Peptide protein matches for the Canonical database. Rows - peptides, columns - proteins, point - peptide protein match, red - proteotypic peptide.

Peptide protein matches for the Canonical database. Rows - peptides, columns - proteins, point - peptide protein match, red - proteotypic peptide.

groups_canonical <- greedy_parsimony(annotated_precursors, peptide = "peptideSeq")

Conclusion

We see that the number of proteins needed to explain all the peptides is practically identical for both databases. Also in practice using a database with more entries does not lead to more identified proteins. On the contrary, it might even reduce the number of proteins identified.

inference <- data.frame(
  database = rep(c("All", "Canonical"), each = 2),
  stage = factor(rep(c("before", "after"), 2), levels = c("before", "after")),
  proteins = c(
    length(unique(annotation_all$protein_id)), length(unique(groups_all)),
    length(unique(annotation_canonical$protein_id)), length(unique(groups_canonical))
  )
)
ggplot(inference, aes(x = stage, y = proteins)) +
  geom_col(fill = "#0072B2") +
  geom_text(aes(label = proteins), vjust = -0.3) +
  facet_wrap(~database) +
  labs(x = "protein inference", y = "proteins")
Number of proteins before and after protein inference.

Number of proteins before and after protein inference.

Session Info

sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] dplyr_1.2.1    ggplot2_4.0.4  prozor_0.5.0   rmarkdown_2.32
## 
## loaded via a namespace (and not attached):
##  [1] vctrs_0.7.3           cli_3.6.6             knitr_1.52           
##  [4] rlang_1.3.0           xfun_0.62             otel_0.3.0           
##  [7] generics_0.1.4        S7_1.0.0              jsonlite_2.0.0       
## [10] AhoCorasickTrie_0.1.4 labeling_0.4.3        glue_1.8.1           
## [13] buildtools_1.0.0      htmltools_0.5.9       maketools_1.3.2      
## [16] sys_3.4.3             sass_0.5.0            scales_1.4.0         
## [19] grid_4.6.2            tibble_3.3.1          evaluate_1.0.5       
## [22] jquerylib_0.1.4       fastmap_1.2.0         yaml_2.3.12          
## [25] lifecycle_1.0.5       compiler_4.6.2        RColorBrewer_1.1-3   
## [28] Rcpp_1.1.2            pkgconfig_2.0.3       farver_2.1.2         
## [31] digest_0.6.39         R6_2.6.1              tidyselect_1.2.1     
## [34] pillar_1.11.1         magrittr_2.0.5        bslib_0.12.0         
## [37] withr_3.0.3           tools_4.6.2           gtable_0.3.6         
## [40] cachem_1.1.0