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")## [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 |
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")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")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
plot_matches <- function(annotation) {
pairs <- distinct(annotation, peptide = factor(peptideSeq), protein = factor(protein_id))
peptide_rank <- rank(-tabulate(pairs$peptide, nlevels(pairs$peptide)), ties.method = "first")
protein_rank <- rank(-tabulate(pairs$protein, nlevels(pairs$protein)), ties.method = "first")
ggplot(data.frame(peptide = peptide_rank[pairs$peptide], protein = protein_rank[pairs$protein])) +
geom_point(aes(x = protein, y = peptide), shape = 15, size = 0.5) +
scale_y_reverse() +
labs(x = "proteins, most peptides first", y = "peptides, most proteins first")
}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
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
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")## R version 4.6.2 (2026-10-29)
## Platform: aarch64-apple-darwin23
## Running under: macOS Golden Gate 27.2.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] C/en_US.UTF-8/C/C/C/C
##
## time zone: Europe/Zurich
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggplot2_4.0.4 dplyr_1.2.1 prozor_0.5.0
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_2.0.0 compiler_4.6.2
## [4] tidyselect_1.2.1 Rcpp_1.1.2 jquerylib_0.1.4
## [7] scales_1.4.0 yaml_2.3.12 fastmap_1.2.0
## [10] R6_2.6.1 labeling_0.4.3 generics_0.1.4
## [13] knitr_1.52 tibble_3.3.1 AhoCorasickTrie_0.1.3
## [16] bslib_0.12.0 pillar_1.11.1 RColorBrewer_1.1-3
## [19] rlang_1.3.0 cachem_1.1.0 xfun_0.62
## [22] sass_0.5.0 S7_1.0.0 otel_0.3.0
## [25] cli_3.6.6 withr_3.0.3 magrittr_2.0.5
## [28] digest_0.6.39 grid_4.6.2 lifecycle_1.0.5
## [31] vctrs_0.7.3 evaluate_1.0.5 glue_1.8.1
## [34] farver_2.1.2 rmarkdown_2.32 tools_4.6.2
## [37] pkgconfig_2.0.3 htmltools_0.5.9