Skip to main content

Target Decoy FDR from COMET search results

Author

Witold Wolski

Published

November 25, 2026

Here we describe how you can estimate the false discovery rate (FDR) when matching your spectra against a FASTA sequence database using spectra search engines such as Mascot or Comet. The sequence database contains forward sequences and the same number of reverse sequences.

The data

Comet’s E-value significantly outperforms SEQUEST’s probability score and Comet’s cross-correlation score.

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

data(bcd)
bcd |>
  mutate(hit = if_else(grepl("^REV_", protein), "decoy", "target")) |>
  ggplot(aes(x = -log10(e.value), y = sp_score, colour = hit)) +
  geom_point(alpha = 0.3, size = 0.8) +
  scale_colour_manual(values = c(target = "#0072B2", decoy = "#D55E00")) +
  labs(x = "-log10(E-value)", y = "Sp score", colour = NULL)

bcd |>
  select(scan, plain_peptide, protein, e.value, sp_score) |>
  head() |>
  knitr::kable()
scan plain_peptide protein e.value sp_score
1085 IWKHGECAQTIR tr|E5RIM3|E5RIM3_HUMAN,sp|Q9Y263|PLAP_HUMAN 11.50 187.3
1117 DQEASRGSVPSGSKMDR tr|A0A0C4DG22|A0A0C4DG22_HUMAN,sp|Q9GZR2|REXO4_HUMAN 21.40 460.4
1128 QYDFSFTVNGVSEDSK REV_tr|C9J114|C9J114_HUMAN,REV_sp|P17181|INAR1_HUMAN 5.99 207.7
1134 CQAEFTALEDFVQHK tr|H3BUJ7|H3BUJ7_HUMAN,tr|H3BSL4|H3BSL4_HUMAN,tr|H3BN24|H3BN24_HUMAN,sp|Q66K89|E4F1_HUMAN 30.60 394.7
1159 RMMRGLMGR REV_sp|A6NH11|GLTD2_HUMAN 8.65 114.7
1168 HSGCRACVLGK tr|I3L0P5|I3L0P5_HUMAN,sp|O95838|GLP2R_HUMAN 5.91 412.2

Define helper function

summarize_level <- function(
  data,
  level = "psm",
  score = "e.value",
  protein = "protein",
  q_value = 0.01,
  decoy = "^REV_"
) {
  fdr <- TargetDecoyFDR$new(data[[score]], decoy_hit = grepl(decoy, data[[protein]]), larger_better = FALSE)
  cutoff <- fdr$score_at(q_value = q_value, method = "fdr_simple")

  filtered <- filter(data, .data[[score]] <= .env$cutoff)
  n_decoy <- sum(grepl(decoy, filtered[[protein]]))
  n_confident <- nrow(filtered) - n_decoy

  res <- data.frame(
    n = nrow(data),
    n_confident = n_confident,
    n_decoy = n_decoy,
    fdr = n_decoy / n_confident,
    assignment_rate = nrow(filtered) / nrow(data) * 100
  )
  colnames(res) <- paste(colnames(res), level, sep = "_")
  res
}

PSM level

summarize_level(bcd)
  n_psm n_confident_psm n_decoy_psm    fdr_psm assignment_rate_psm
1  4557            3367          33 0.00980101            74.61049

Peptide FDR

Use minimum of e.value of all PSMs matching a peptide as new score for the peptide.

peptide_level <- bcd |>
  summarise(n = n(), min_e.value = min(e.value), .by = c(plain_peptide, protein))
table(peptide_level$n)

   1    2    3    4    6 
4180  157   15    3    1 
summarize_level(peptide_level, score = "min_e.value", level = "peptides")
  n_peptides n_confident_peptides n_decoy_peptides fdr_peptides
1       4356                 3178               30  0.009439899
  assignment_rate_peptides
1                 73.64555

Protein FDR

Use minimum of e.value of all PSMs matching a protein as new score for the protein.

protein_level <- bcd |>
  summarise(n = n(), min_e.value = min(e.value), .by = protein)
table(protein_level$n)

   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
1909  355  145   88   25   29   18   14    7    8    9    2    1    3    4    4 
  17   18   19   20   21   36 
   1    2    1    2    1    1 
summarize_level(protein_level, score = "min_e.value", level = "proteins")
  n_proteins n_confident_proteins n_decoy_proteins fdr_proteins
1       2629                 1562               15  0.009603073
  assignment_rate_proteins
1                 59.98479

Filter on PSM level only

Filter on PSM level and then estimate the FDR on peptide and protein level. score_cutoff() returns the score at the requested q-value; the code below prints it and keeps the PSMs that pass it.

score_cutoff <- function(
  data,
  score = "e.value",
  larger_better = FALSE,
  protein = "protein",
  q_value = 0.01,
  decoy = "^REV_"
) {
  fdr <- TargetDecoyFDR$new(data[[score]], decoy_hit = grepl(decoy, data[[protein]]), larger_better = larger_better)
  fdr$score_at(q_value = q_value, method = "fdr_simple")
}

summarize_fdrs <- function(
  data,
  filtered,
  psm_fdr_cutoff,
  peptide = "plain_peptide",
  protein = "protein",
  decoy = "^REV_"
) {
  res <- list()
  res$n_psm <- nrow(data)
  res$psm_fdr_cutoff <- psm_fdr_cutoff
  res$n_decoy_psm <- sum(grepl(decoy, filtered[[protein]]))
  res$n_confident_psm <- nrow(filtered) - res$n_decoy_psm
  res$fdr_psm <- res$n_decoy_psm / res$n_confident_psm

  # peptide level FDR
  filtered_peptides <- filtered |> select(all_of(c(peptide, protein))) |> distinct()
  res$n_decoy_peptide <- sum(grepl(decoy, filtered_peptides[[protein]]))
  res$n_confident_peptide <- nrow(filtered_peptides) - res$n_decoy_peptide
  res$fdr_peptide <- res$n_decoy_peptide / res$n_confident_peptide

  # protein level FDR
  filtered_proteins <- filtered |> select(all_of(protein)) |> distinct()
  res$n_decoy_protein <- sum(grepl(decoy, filtered_proteins[[protein]]))
  res$n_confident_protein <- nrow(filtered_proteins) - res$n_decoy_protein
  res$fdr_protein <- res$n_decoy_protein / res$n_confident_protein
  data.frame(res)
}

Use e-value

# psm level FDR
psm_fdr_cutoff <- 0.01

cutoff <- score_cutoff(bcd, score = "e.value", larger_better = FALSE, q_value = psm_fdr_cutoff)
cutoff
[1] 0.491
filtered <- filter(bcd, e.value <= cutoff)
knitr::kable(summarize_fdrs(bcd, filtered, psm_fdr_cutoff))
n_psm psm_fdr_cutoff n_decoy_psm n_confident_psm fdr_psm n_decoy_peptide n_confident_peptide fdr_peptide n_decoy_protein n_confident_protein fdr_protein
4557 0.01 33 3367 0.009801 33 3197 0.0103222 33 1642 0.0200974

Use sp_score

# psm level FDR
psm_fdr_cutoff <- 0.01

cutoff <- score_cutoff(bcd, score = "sp_score", larger_better = TRUE, q_value = psm_fdr_cutoff)
cutoff
[1] 466.8
filtered <- filter(bcd, sp_score >= cutoff)
knitr::kable(summarize_fdrs(bcd, filtered, psm_fdr_cutoff))
n_psm psm_fdr_cutoff n_decoy_psm n_confident_psm fdr_psm n_decoy_peptide n_confident_peptide fdr_peptide n_decoy_protein n_confident_protein fdr_protein
4557 0.01 30 3046 0.009849 30 2882 0.0104094 30 1551 0.0193424