--- title: "Creating Target Decoy Databases" author: "Witek Wolski" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Creating Target Decoy Databases} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- Using the package prozor for creating standardized FASTA. The package can be used to: * merge several FASTA files into a single FASTA file * add reverse sequences to the FASTA file. * add contaminants to the FASTA file # 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](https://fgcz.ch/) 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. ```{r} library(prozor) head(names(load_contaminants("fgcz2021"))) length(load_contaminants("fgcz2021")) length(load_contaminants("fgcz2021", no_human = TRUE)) ``` # 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](https://fgcz.ch/) 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_| `. 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. ```{r} database_dir <- system.file("p1000_db1_example", package = "prozor") files <- list.files(database_dir, pattern = "\\.(fasta|fa|faa)(\\.gz)?$", full.names = TRUE) basename(files) annotation <- readLines(file.path(database_dir, "annotation.txt"))[1] annotation ``` ## 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. ```{r message = FALSE} db <- create_decoy_db(files, contaminants = load_contaminants("fgcz2021"), rev_lab = NULL, header = annotation) length(db) ``` Based on the directory name we build the name of the FASTA file adding the current date. ```{r} db_file <- file.path(tempdir(), paste0(basename(database_dir), "_", format(Sys.time(), "%Y%m%d"), ".fasta")) basename(db_file) 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. ```{r message = FALSE} db_decoy <- create_decoy_db(files, contaminants = load_contaminants("fgcz2021"), rev_lab = "REV_", header = annotation) db_decoy[[length(db_decoy)]] length(db_decoy) anyDuplicated(names(db_decoy)) ``` The name of a database with decoys ends in `_d`. ```{r} db_decoy_file <- file.path( tempdir(), paste0(basename(database_dir), "_d_", format(Sys.time(), "%Y%m%d"), ".fasta") ) basename(db_decoy_file) 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. ```{r message = FALSE} res <- create_fgcz_fasta_db( database_dir, contaminants = load_contaminants("fgcz2021"), output_dir = tempdir(), make_summary = FALSE ) cat(res$summary) unlink(c(db_file, db_decoy_file, res$file_path)) ``` # Session Info ```{r} sessionInfo() ```