Skip to main content

Creating Target Decoy Databases

Author

Witek Wolski

Published

November 25, 2026

Using the package prozor for creating standardized FASTA. The package can be used to:

Contaminants

This package provides several sets of typical contaminant proteins and peptides, which can be loaded with load_contaminants(); no_human = TRUE leaves out the contaminants of human origin. At the FGCZ we always are adding contaminants to the database. To databases already containing human proteins, we add the contaminants without the human ones. The contaminants are easy to distinguish from other entries thanks to the zz|FGCZCont prefix.

library(prozor)
head(names(load_contaminants("fgcz2021")))
[1] "zz|fgczContaminants2021|" "zz|Y-FGCZCont00001|"     
[3] "zz|Y-FGCZCont00002|"      "zz|Y-FGCZCont00003|"     
[5] "zz|Y-FGCZCont00004|"      "zz|Y-FGCZCont00005|"     
length(load_contaminants("fgcz2021"))
[1] 499
length(load_contaminants("fgcz2021", no_human = TRUE))
[1] 343

Creating a FASTA protein amino acid sequence database for searching.

To merge several FASTA databases into a single file place them into a single folder and give the folder the name of the database. At the FGCZ the database name is the project number, e.g. p1000, a consecutive number, e.g. db1, and a descriptive name, e.g. example: p1000_db1_example.

Add to the folder also an annotation.txt file. The annotation file should contain a single line formatted like a FASTA entry header with the following content: aa|p<project_number>_<database_name>|<YYYYMMDD> <detailed_description>.

Example : AA|p1000_db1_example|20180119_Example https://github.com/prolfqua/prozor

The package provides an example of such a folder with the FASTA files. create_fgcz_fasta_db() reads the FASTA files in it (*.fasta, *.fa or *.faa, optionally gzipped) and the first line of annotation.txt; here we do the same step by step.

database_dir <- system.file("p1000_db1_example", package = "prozor")
files <- list.files(database_dir, pattern = "\\.(fasta|fa|faa)(\\.gz)?$", full.names = TRUE)
basename(files)
[1] "Annotation_allSeq.fasta.gz" "Annotation_canSeq.fasta.gz"
annotation <- readLines(file.path(database_dir, "annotation.txt"))[1]
annotation
[1] "AA|p1000_db1_example|20180118 Example: Homo sapiens UniProt entries (Swiss-Prot and TrEMBL, with isoforms) matched by the peptides of extdata/IDResults.txt.gz"

Create non decoy database

create_decoy_db() puts a dummy entry, whose header is the annotation, first, followed by the sequences of the FASTA files and the contaminants. Of entries with the same name, only the first is kept.

db <- create_decoy_db(files, contaminants = load_contaminants("fgcz2021"), rev_lab = NULL, header = annotation)
length(db)
[1] 1572

Based on the directory name we build the name of the FASTA file adding the current date.

db_file <- file.path(tempdir(), paste0(basename(database_dir), "_", format(Sys.time(), "%Y%m%d"), ".fasta"))
basename(db_file)
[1] "p1000_db1_example_20261125.fasta"
write_fasta(db, file = db_file)

Create decoy database

To add decoys, reversed sequences, specify the rev_lab parameter of create_decoy_db(). Apart from the dummy entry, the resulting database is twice as long as the non-decoy database. The names stay unique.

db_decoy <- create_decoy_db(files, contaminants = load_contaminants("fgcz2021"), rev_lab = "REV_", header = annotation)
db_decoy[[length(db_decoy)]]
[1] "ADAFGLESLKQHAEAYDAFFADEDAAYKDVLPRFVPDSLLAKDSPLQLLGEKEGSLLETFYSNDFILPNSTWPGEFGSREKHAAGITHGGSLAVIDQDTLGMAKGFVDRLHDSGKTADPLRGEPPPEPKDERGPHFPVEPGGTVEVAVVGALQYFDAYSLIPFEAKLPELLRVAIDLGNNASHALEAPHKITGFPGGTKTGKDFTGASHWALRLMLPACRKEAIFGRLKKKAKEVAKQYDASVTPYSKGM"
attr(,"name")
[1] "REV_zz|Y-FGCZCont00498|"
attr(,"Annot")
[1] ">REV_zz|Y-FGCZCont00498|  tr|Q43758|Q43758_SOYBN L-ascorbate peroxidase OS=Glycine max OX=3847 GN=apx1 PE=1 SV=1"
attr(,"class")
[1] "SeqFastaAA"
length(db_decoy)
[1] 3143
anyDuplicated(names(db_decoy))
[1] 0

The name of a database with decoys ends in _d.

db_decoy_file <- file.path(
  tempdir(),
  paste0(basename(database_dir), "_d_", format(Sys.time(), "%Y%m%d"), ".fasta")
)
basename(db_decoy_file)
[1] "p1000_db1_example_d_20261125.fasta"
write_fasta(db_decoy, file = db_decoy_file)

All steps in one call

create_fgcz_fasta_db() runs these steps, writes the file to output_dir and returns a summary.

res <- create_fgcz_fasta_db(
  database_dir,
  contaminants = load_contaminants("fgcz2021"),
  output_dir = tempdir(),
  make_summary = FALSE
)
cat(res$summary)
Database created with prozor 0.5.0
   database_dir : /home/runner/work/_temp/Library/prozor/p1000_db1_example
   contaminants : 499 sequences
        rev_lab : REV_
     output_dir : /tmp/RtmpIzhgIX
     FASTA name : p1000_db1_example_d
FASTA file name : p1000_db1_example_d_20261125.fasta
     annotation : AA|p1000_db1_example|20180118 Example: Homo sapiens UniProt entries (Swiss-Prot and TrEMBL, with isoforms) matched by the peptides of extdata/IDResults.txt.gz
    n_sequences : 3143
unlink(c(db_file, db_decoy_file, res$file_path))

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=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] prozor_0.5.0

loaded via a namespace (and not attached):
 [1] compiler_4.6.2  R6_2.6.1        fastmap_1.2.0   cli_3.6.6      
 [5] tools_4.6.2     htmltools_0.5.9 otel_0.3.0      yaml_2.3.12    
 [9] rmarkdown_2.32  knitr_1.52      jsonlite_2.0.0  xfun_0.62      
[13] digest_0.6.39   rlang_1.3.0     evaluate_1.0.5