Skip to main content

Target-decoy false discovery rate

Description

An R6 class that estimates the false discovery rate (FDR) of target-decoy search results. When the object is created, the hits are sorted from best to worst score and two FDR estimates are computed at each score:

  • fdr_concatenated: the FDR of a concatenated target-decoy search, estimated as 2 * decoys / all hits (Elias and Gygi 2007).

  • fdr_simple: the FDR estimated as decoys / targets (Käll et al. 2008).

Both estimates are fractions in [0, 1]: values above 1, e.g. where the best hits are decoys, are set to 1.

The q-value of a hit is the lowest FDR at which it is accepted: the smallest estimate at its own or any worse score. The estimate at a score counts all hits with that score or a better one, so tied hits share their estimates and q-values, whatever the input order; within a tie, decoys are listed before targets.

The decoys are given as logical flags. For protein IDs whose decoys start with REV_, pass decoy_hit = grepl(“^REV_”, id), and id = id to keep the IDs in table.

The object cannot be changed: its fields are read-only and its methods only read them. clone() copies an object. See vignette(“TargetDecoyFDR_Example”, package = “prozor”).

Value

TargetDecoyFDR$new() returns a TargetDecoyFDR R6 object; see Methods.

Active bindings

larger_better
TRUE if a larger score is better (read-only).
n
Number of hits (read-only).
table

The hits from best to worst score, as a data frame (read-only) with the columns:

  • order: the position of the hit in the input.

  • id: the ID of the hit; only when id was given.

  • score, decoy_hit: the sorted input.

  • fdr_concatenated, fdr_simple: the FDR estimates at the score, as fractions in [0, 1].

  • q_value_fdr_concatenated, q_value_fdr_simple: the q-values of both estimates, as fractions in [0, 1].

Methods

Public methods


TargetDecoyFDR$new()

Sort the hits from best to worst score and compute both FDR estimates and their q-values.

Usage
TargetDecoyFDR\$new(score, decoy_hit, larger_better = TRUE, id = NULL)
Arguments
score
Search engine scores, at least one, without NA.
decoy_hit
Logical, TRUE for decoy hits, one per score, without NA.
larger_better
TRUE if a larger score is better, FALSE if a smaller score is better.
id
IDs of the hits, e.g. protein IDs, one per score; NULL (default) for none.
Returns

A new TargetDecoyFDR object.


TargetDecoyFDR$print()

Print the numbers of hits and decoys, larger_better, and the scores at fdr_simple q-values of 0.01 and 0.05 (none if no score reaches them).

Usage
TargetDecoyFDR\$print(...)
Arguments
…
Not used.
Returns

The object, invisibly.


TargetDecoyFDR$score_at()

Find the score cut-off for a given FDR.

Usage
TargetDecoyFDR\$score_at(
  q_value = 0.01,
  method = c("fdr_simple", "fdr_concatenated")
)
Arguments
q_value
The FDR as a fraction, like the q-values in table: 0.01 for 1 %.
method
The FDR estimate to use: “fdr_simple” (default) or “fdr_concatenated”.
Returns

The least strict score whose q-value is at most q_value. An error if no score reaches it.


TargetDecoyFDR$plot()

Plot the score distributions and q-values: two panels on a shared score axis, the histogram of target and decoy scores, and the q-values of both FDR estimates in percent. When smaller scores are better and all scores are positive, the score axis is logarithmic. Every hit is drawn: one million hits take about 2 s to render as PDF and 20 s as PNG.

Usage
TargetDecoyFDR\$plot(bins = 100)
Arguments
bins
Number of histogram bins.
Returns

A ggplot object.


TargetDecoyFDR$clone()

The objects of this class are cloneable with this method.

Usage
TargetDecoyFDR\$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.

References

Elias JE, Gygi SP (2007). Target-decoy search strategy for increased confidence in large-scale protein identifications by mass spectrometry. Nature Methods, 4(3), 207-214. doi:10.1038/nmeth1019

Käll L, Storey JD, MacCoss MJ, Noble WS (2008). Assigning significance to peptides identified by tandem mass spectrometry using decoy databases. Journal of Proteome Research, 7(1), 29-34. doi:10.1021/pr700600n

See Also

Other FDR: bcd, fdr_sample

Examples

library("prozor")

data(fdr_sample)
# smaller scores are better; decoy IDs start with REV_
fdr <- TargetDecoyFDR$new(
  fdr_sample$score,
  decoy_hit = grepl("^REV_", fdr_sample$protein_id),
  larger_better = FALSE,
  id = fdr_sample$protein_id
)
fdr
<TargetDecoyFDR> hits: 40,000, decoys: 858, larger_better: FALSE
score at fdr_simple q-value 0.01: 0.03395, at 0.05: 0.09992
head(fdr$table)
  order                   id        score decoy_hit fdr_concatenated fdr_simple
1   287 sp|P04264|K2C1_HUMAN 8.611747e-21     FALSE                0          0
2  3581 sp|P04264|K2C1_HUMAN 6.305185e-19     FALSE                0          0
3 29584 sp|P35527|K1C9_HUMAN 1.750698e-17     FALSE                0          0
4 26559 sp|P04264|K2C1_HUMAN 3.081044e-16     FALSE                0          0
5 15524 sp|P02768|ALBU_HUMAN 3.835269e-16     FALSE                0          0
6 30840 sp|P04264|K2C1_HUMAN 3.845918e-16     FALSE                0          0
  q_value_fdr_concatenated q_value_fdr_simple
1                        0                  0
2                        0                  0
3                        0                  0
4                        0                  0
5                        0                  0
6                        0                  0
fdr$score_at(q_value = 0.01)
[1] 0.03394749
fdr$score_at(q_value = 0.01, method = "fdr_concatenated")
[1] 0.008509834
fdr$plot()

# larger scores are better
fdr2 <- TargetDecoyFDR$new(
  fdr_sample$neg_log10_score,
  decoy_hit = grepl("^REV_", fdr_sample$protein_id)
)
fdr2$score_at(q_value = 0.01)
[1] 1.469192
fdr2$plot()