|
| 1 | +\name{translate_codons} |
| 2 | + |
| 3 | +\alias{translate_codons} |
| 4 | +\alias{extract_codons} |
| 5 | + |
| 6 | +\title{Extract and translate codons from a set of DNA sequences} |
| 7 | + |
| 8 | +\description{ |
| 9 | + The \code{translate_codons()} function extracts and translates codons |
| 10 | + from a set of DNA sequences. |
| 11 | +} |
| 12 | + |
| 13 | +\usage{ |
| 14 | +translate_codons(dna, offset=0, with.init.codon=FALSE) |
| 15 | + |
| 16 | +## Used internally by translate_codons(): |
| 17 | +extract_codons(dna, offset=0) |
| 18 | +} |
| 19 | + |
| 20 | +\arguments{ |
| 21 | + \item{dna}{ |
| 22 | + A \link[Biostrings]{DNAStringSet} (or \link[Biostrings]{DNAString}) |
| 23 | + object containing the codons to translate. |
| 24 | + } |
| 25 | + \item{offset}{ |
| 26 | + The number of nucleotides that precede the first codon to translate. |
| 27 | + This must be supplied as a numeric vector with one value per |
| 28 | + sequence in \code{dna}, or as a single value. If the latter, |
| 29 | + then the same offset is used for all sequences. |
| 30 | + } |
| 31 | + \item{with.init.codon}{ |
| 32 | + Is the first codon to translate in each DNA sequence the initiation |
| 33 | + codon? By default, \code{with.init.codon} is set to \code{FALSE}, in |
| 34 | + which case \code{translate_codons()} assumes that the first codon |
| 35 | + to translate in each DNA sequence is \emph{not} the initiation codon. |
| 36 | + |
| 37 | + See the \code{no.init.codon} argument in |
| 38 | + \code{?\link[Biostrings]{translate}} in the \pkg{Biostrings} package |
| 39 | + for more information. |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +\value{ |
| 44 | + \code{translate_codons()} returns an \link[Biostrings]{AAStringSet} |
| 45 | + object with one amino acid sequence per input sequence. |
| 46 | + |
| 47 | + \code{extract_codons()} returns a \link[Biostrings]{DNAStringSet} |
| 48 | + object with one sequence per input sequence. The output sequences |
| 49 | + are obtained by trimming the original sequences as follow: |
| 50 | + \itemize{ |
| 51 | + \item On their 5' end, sequences are trimmed by the amount of |
| 52 | + nucleotides specified in \code{offset}. |
| 53 | + \item On their 3' end, sequences are trimmed by the smallest |
| 54 | + amount of nucleotides that makes the length of the trimmed |
| 55 | + sequence a multiple of 3. Note that this will always be 0, 1, |
| 56 | + or 2 nucleotides. |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +\seealso{ |
| 61 | + \itemize{ |
| 62 | + \item \link[Biostrings]{DNAStringSet} and \link[Biostrings]{AAStringSet} |
| 63 | + objects in the \pkg{Biostrings} package. |
| 64 | + |
| 65 | + \item The \code{\link[Biostrings]{translate}} function in the |
| 66 | + \pkg{Biostrings} package on which \code{translate_codons()} |
| 67 | + is based. |
| 68 | + |
| 69 | + \item \code{\link{list_germline_dbs}} to list all the \emph{cached |
| 70 | + germline dbs}, that is, all the germline databases currently |
| 71 | + installed in \pkg{igblastr}'s persistent cache. |
| 72 | + } |
| 73 | +} |
| 74 | +
|
| 75 | +\examples{ |
| 76 | +## --------------------------------------------------------------------- |
| 77 | +## translate_codons() |
| 78 | +## --------------------------------------------------------------------- |
| 79 | +
|
| 80 | +## Load germline V gene allele sequences for human: |
| 81 | +list_germline_dbs() |
| 82 | +db_name <- "_AIRR.human.IGH+IGK+IGL.202410" |
| 83 | +V_alleles <- load_germline_db(db_name, region_types="V") |
| 84 | +V_alleles # DNAStringSet object |
| 85 | +
|
| 86 | +## Translate them: |
| 87 | +V_aa <- translate_codons(V_alleles) |
| 88 | +V_aa # AAStringSet object |
| 89 | +
|
| 90 | +## Some human germline V gene allele sequences have a stop codon: |
| 91 | +has_stop_codon <- grepl("*", as.character(V_aa), fixed=TRUE) |
| 92 | +V_aa[has_stop_codon] |
| 93 | +
|
| 94 | +## Handling of initiation codons (see '?translate' in the Biostrings |
| 95 | +## package for how initiation codons are handled): |
| 96 | +dna2 <- DNAStringSet(c("TTGTCCTTTATA", "GAATCATTTATC", "CTGTCGTTTATT")) |
| 97 | +translate_codons(dna2) |
| 98 | +translate_codons(dna2, with.init.codon=TRUE) |
| 99 | +
|
| 100 | +## --------------------------------------------------------------------- |
| 101 | +## extract_codons() |
| 102 | +## --------------------------------------------------------------------- |
| 103 | +dna <- DNAStringSet(c("CCCAAAGGGTTT", |
| 104 | + "CCAAAGGGTTT", |
| 105 | + "CAAAGGGTTT", |
| 106 | + "AAAGGGTTT")) |
| 107 | +extract_codons(dna) |
| 108 | +extract_codons(dna, offset=1) |
| 109 | +extract_codons(dna, offset=2) |
| 110 | +extract_codons(dna, offset=3) |
| 111 | +extract_codons(dna, offset=4) |
| 112 | +
|
| 113 | +extract_codons(dna, offset=3:0) |
| 114 | +extract_codons(dna, offset=4:1) |
| 115 | +extract_codons(dna, offset=5:2) |
| 116 | +extract_codons(dna, offset=6:3) |
| 117 | +} |
| 118 | +
|
| 119 | +\keyword{utilities} |
0 commit comments