| 1 |
The \eslmod{alphabet} module contains routines for digitizing |
| 2 |
alphabetic biosequences. |
| 3 |
|
| 4 |
It is convenient to represent nucleotides and amino acids as array |
| 5 |
indices 0..3 or 0..19, respectively, for efficiency and other |
| 6 |
reasons. It is also convenient to index the residues in a biosequence |
| 7 |
in 1..L coordinates instead of the C language's 0..L-1 array |
| 8 |
representation, partly for human readability, and also because some |
| 9 |
codes (dynamic programming alignment algorithms, for example) have |
| 10 |
boundary conditions where initializing a boundary at coordinate 0 is |
| 11 |
convenient. |
| 12 |
|
| 13 |
Real biosequences do not consist of just four or twenty different |
| 14 |
canonical symbols, though. The \eslmod{alphabet} module provides |
| 15 |
mechanisms for dealing with several other biosequence coding issues: |
| 16 |
|
| 17 |
\begin{itemize} |
| 18 |
\item Degenerate residue symbols representing uncertainties, |
| 19 |
including both IUPAC/IUBMB standard one-letter nomenclature |
| 20 |
and nonstandard extensions such as the use of \ccode{J} to |
| 21 |
mean isoleucine or leucine (\ccode{I|L}) in protein sequences |
| 22 |
determined by mass spec; |
| 23 |
|
| 24 |
\item Symbols for ``any residue'' (N in DNA/RNA; X in amino acid |
| 25 |
sequences) and ``not a residue'' (a ``translated'' stop codon '*' |
| 26 |
in protein sequence; |
| 27 |
|
| 28 |
\item Standard and nonstandard symbols for unusual residues, such as |
| 29 |
selenocysteine (\ccode{U}) and pyrrolysine (\ccode{O}) in |
| 30 |
proteins; |
| 31 |
|
| 32 |
\item \emph{Ad hoc} symbols representing modified residues, such as |
| 33 |
the slew of one-letter codes used to annotate |
| 34 |
posttranscriptionally modified nucleotides in the Sprinzl tRNA |
| 35 |
database \citep{Sprinzl98}; |
| 36 |
|
| 37 |
\item Case-insensitivity of input sequences, for instance allowing |
| 38 |
both \ccode{a} and \ccode{A} to mean alanine in amino acid |
| 39 |
sequences; |
| 40 |
|
| 41 |
\item Tolerating common malpractices in the field, like the use of |
| 42 |
\ccode{X} instead of \ccode{N} as a degeneracy code in nucleic |
| 43 |
acid sequence; |
| 44 |
|
| 45 |
\item The semantic difference between a gap symbol and a missing |
| 46 |
data symbol in sequence alignments. |
| 47 |
\end{itemize} |
| 48 |
|
| 49 |
The \eslmod{alphabet} module provides standard defaults for protein, |
| 50 |
RNA, and DNA alphabets which follow both community standards and |
| 51 |
IUPAC/IUBMB nomenclature for representing sequence residues in |
| 52 |
one-letter ASCII characters. Additionally, the design of the |
| 53 |
\eslmod{alphabet} module is flexible enough to allow an application to |
| 54 |
customize its own alphabet, to deal with these issues almost any way |
| 55 |
it chooses. |
| 56 |
|
| 57 |
Table~\ref{tbl:alphabet_api} lists the functions in the |
| 58 |
\eslmod{alphabet} API. Easel maintains alphabet information in an |
| 59 |
\ccode{ESL\_ALPHABET} structure. An application usually creates its |
| 60 |
alphabet once, possibly even as a global variable. A digitized |
| 61 |
sequence \ccode{dsq} is an \ccode{unsigned char *} array of length |
| 62 |
\ccode{L+2}, where \ccode{dsq[1..L]} are digitized residues, and |
| 63 |
\ccode{dsq[0]} and \ccode{dsq[L+1]} are sentinel bytes (of value |
| 64 |
\ccode{eslSENTINEL}, 127). |
| 65 |
|
| 66 |
\begin{table}[hbp] |
| 67 |
\begin{center} |
| 68 |
\begin{tabular}{ll}\hline |
| 69 |
\multicolumn{2}{c}{\textbf{The \ccode{ESL\_ALPHABET} object}}\\ |
| 70 |
\ccode{esl\_alphabet\_Create()} & Create alphabet of standard type. \\ |
| 71 |
\ccode{esl\_alphabet\_CreateCustom()} & Create a custom alphabet. \\ |
| 72 |
\ccode{esl\_alphabet\_SetEquiv()} & Define an equivalent symbol. \\ |
| 73 |
\ccode{esl\_alphabet\_SetCaseInsensitive()} & Make an alphabet's input map case insensitive. \\ |
| 74 |
\ccode{esl\_alphabet\_SetDegeneracy()} & Define degenerate symbol in custom alphabet. \\ |
| 75 |
\ccode{esl\_alphabet\_Destroy()} & Frees an alphabet object. \\ |
| 76 |
\multicolumn{2}{c}{\textbf{Digitized sequences}}\\ |
| 77 |
\ccode{esl\_abc\_CreateDsq()} & Digitize a sequence into new \ccode{dsq} space. \\ |
| 78 |
\ccode{esl\_abc\_Digitize()} & Digitize a sequence into existing \ccode{dsq} space. \\ |
| 79 |
\multicolumn{2}{c}{\textbf{Other functions}}\\ |
| 80 |
\ccode{esl\_abc\_\{I,F,D\}AvgScore()} & Calculate avg score of degenerate residue.\\ |
| 81 |
\ccode{esl\_abc\_\{I,F,D\}ExpectScore()} & Calculate expected score of degenerate residue.\\ |
| 82 |
\ccode{esl\_abc\_Type()} & Convert internal alphabet type code to output string.\\ |
| 83 |
\ccode{esl\_abc\_\{F,D\}Count()} & Count a digital symbol towards a countvector.\\ |
| 84 |
\ccode{esl\_abc\_DigitizeSymbol()} & Returns digital code for one ASCII character.\\ |
| 85 |
\ccode{esl\_abc\_XIsDegenerate()} & Returns TRUE given code for a degeneracy.\\ |
| 86 |
\ccode{esl\_abc\_XIsBasic()} & Returns TRUE given code for a fundamental residue.\\ |
| 87 |
\ccode{esl\_abc\_XIsGap()} & Returns TRUE given code for a gap.\\ |
| 88 |
\ccode{esl\_abc\_CIsDegenerate()} & Returns TRUE given a degenerate character.\\ |
| 89 |
\ccode{esl\_abc\_CIsBasic()} & Returns TRUE given a fundamental residue.\\ |
| 90 |
\ccode{esl\_abc\_CIsGap()} & Returns TRUE given a gap character.\\ |
| 91 |
|
| 92 |
\hline |
| 93 |
\end{tabular} |
| 94 |
\end{center} |
| 95 |
\caption{The \eslmod{alphabet} API.} |
| 96 |
\label{tbl:alphabet_api} |
| 97 |
\end{table} |
| 98 |
|
| 99 |
\subsection{An example of using the alphabet API} |
| 100 |
|
| 101 |
Figure~\ref{fig:alphabet_example} shows an example of creating a DNA |
| 102 |
alphabet and digitizing a short DNA sequence. |
| 103 |
|
| 104 |
\begin{figure} |
| 105 |
\input{cexcerpts/alphabet_example} |
| 106 |
\caption{An example of using the \eslmod{alphabet} module.} |
| 107 |
\label{fig:alphabet_example} |
| 108 |
\end{figure} |
| 109 |
|
| 110 |
\begin{itemize} |
| 111 |
\item A standard biosequence alphabet is created using |
| 112 |
\ccode{esl\_alphabet\_Create(type)}, where \ccode{type} can be |
| 113 |
\ccode{eslDNA}, \ccode{eslRNA}, or \ccode{eslAMINO}. |
| 114 |
|
| 115 |
\item An input sequence \ccode{seq} of length \ccode{L} is digitized |
| 116 |
according to alphabet \ccode{a}, creating a newly allocated digital |
| 117 |
sequence \ccode{dsq}, by calling \ccode{esl\_dsq\_Create(a, seq, L, |
| 118 |
\&dsq)}. The caller must free \ccode{dsq} using \ccode{free(dsq)}. |
| 119 |
Alternatively, if the caller has already allocated \ccode{L+2} (or |
| 120 |
more) bytes in \ccode{dsq}, it can call \ccode{esl\_dsq\_Set(a, seq, |
| 121 |
L, dsq)}, which is the non-allocating version of |
| 122 |
\ccode{esl\_dsq\_Create()}. |
| 123 |
|
| 124 |
\item For an input sequence of length \ccode{L}, the digitized |
| 125 |
sequence \ccode{dsq} is a \ccode{char *} array of \ccode{L+2} |
| 126 |
bytes. \ccode{dsq[0]} and \ccode{dsq[L+1]} contain a sentinel byte of |
| 127 |
value \ccode{eslSENTINEL} (127). Positions \ccode{1..L} hold the |
| 128 |
residues, where values \ccode{0..3} encode \ccode{ACGT} in DNA |
| 129 |
sequences, \ccode{0..3} encode \ccode{ACGU} in RNA sequences, and |
| 130 |
\ccode{0..19} encode \ccode{AC..WY} in amino acid sequences. |
| 131 |
|
| 132 |
\item Both sequence-digitizing functions return \ccode{eslEINVAL} if |
| 133 |
the input sequence contains characters that are not in the |
| 134 |
alphabet. Because input sequences are often provided by a user (not |
| 135 |
the program), this is a common error that the application must check |
| 136 |
for. |
| 137 |
\end{itemize} |
| 138 |
|
| 139 |
\subsection{Concepts and terminology} |
| 140 |
|
| 141 |
A \esldef{symbol} is a 7-bit ASCII input character, representing a |
| 142 |
residue, gap, nonresidue, or degeneracy. A \esldef{code} is the |
| 143 |
digital internal representation of the symbol as an \ccode{unsigned |
| 144 |
char} in the range $0..127$, suitable for use as an array index. The |
| 145 |
\eslmod{alphabet} module translates input symbols into internal |
| 146 |
digital codes. |
| 147 |
|
| 148 |
We distinguish between an input alphabet, an internal alphabet, and a |
| 149 |
canonical alphabet. The \esldef{input alphabet} consists of all the |
| 150 |
symbols that Easel allows in an input biosequence character |
| 151 |
string. The \esldef{internal alphabet} is the standardized one-letter |
| 152 |
alphabet that Easel deals with. The \esldef{canonical alphabet} is the |
| 153 |
fundamental set of 4 nucleotides or 20 amino acids. |
| 154 |
|
| 155 |
Easel deals with all of the complications of sequence encoding using |
| 156 |
two concepts, equivalency and degeneracy. \esldef{Equivalency} |
| 157 |
defines how the input alphabet maps to the internal |
| 158 |
alphabet. \esldef{Degeneracy} defines how the internal alphabet maps |
| 159 |
to the canonical alphabet. |
| 160 |
|
| 161 |
Equivalent residues are symbols that are accepted in an input sequence |
| 162 |
character string and silently translated into an appropriate internal |
| 163 |
code. Characters in the input alphabet are mapped many-to-one to the |
| 164 |
internal alphabet using an \esldef{input map}. One use of equivalency |
| 165 |
is to map both lower and upper case input to the same internal |
| 166 |
symbol. Another use is to allow several different input characters to |
| 167 |
mean a gap, 'any' symbol, or 'nonresidue' symbol. Another use is to |
| 168 |
silently accept and ``fix'' nonstandard but common input ``errors'', |
| 169 |
such as tolerating the use of X to mean N in nucleic acid sequences. |
| 170 |
|
| 171 |
Degenerate residues are codes in the internal alphabet that are mapped |
| 172 |
one-to-many onto canonical residue codes, using a \esldef{degeneracy |
| 173 |
map}. In addition to mapping the degeneracy codes onto the canonical |
| 174 |
alphabet, the degeneracy mechanism is also used to deal with unusual |
| 175 |
and modified residues. Selenocysteine, for instance, is represented by |
| 176 |
default as a \ccode{U}, but treated as a degenerate code for \ccode{C} |
| 177 |
(cysteine). The rationale for this will be described in more detail |
| 178 |
below. |
| 179 |
|
| 180 |
\subsubsection{The internal alphabet} |
| 181 |
|
| 182 |
Easel's internal alphabet is a string (\ccode{a->sym}) of length |
| 183 |
\ccode{Kp}, which contains: |
| 184 |
|
| 185 |
\begin{itemize} |
| 186 |
\item the \ccode{K} symbols of the canonical alphabet; |
| 187 |
\item a standard gap symbol; |
| 188 |
\item (optionally) any other degenerate, unusual, or modified residue codes; |
| 189 |
\item a mandatory ``any'' symbol (a completely degenerate residue); |
| 190 |
\item a mandatory ``not-a-residue'' symbol; |
| 191 |
\item a mandatory ``missing data'' symbol. |
| 192 |
\end{itemize} |
| 193 |
|
| 194 |
Residues \ccode{0..K-1} must be the canonical alphabet. Residue |
| 195 |
\ccode{K} must be the gap symbol. Residues \ccode{K+1..Kp-4} must be |
| 196 |
the degenerate and modified residue symbols (there can be zero of |
| 197 |
these). Residue \ccode{Kp-3} must be the completely degenerate symbol |
| 198 |
(such as \ccode{X} for protein sequence or \ccode{N} for nucleic acid |
| 199 |
sequence); all alphabets must have such a symbol. Residue \ccode{Kp-2} |
| 200 |
must be the not-a-residue symbol. Residue \ccode{Kp-1} must be the |
| 201 |
missing data symbol. Because the 'any' symbol, 'not-a-residue' |
| 202 |
symbol, and the two kinds of gap symbols are mandatory in any |
| 203 |
alphabet, \ccode{Kp} $\geq$ \ccode {K+4}. Aside from these |
| 204 |
constraints, symbols may occur in any order. |
| 205 |
|
| 206 |
The digital code used for each residue is then the index of a residue |
| 207 |
in this string, \ccode{0..Kp-1}. The only other value that can appear |
| 208 |
in a digitized sequence is \ccode{eslSENTINEL} (127), the sentinel |
| 209 |
byte in positions \ccode{0} and \ccode{L+1} of a digitized sequence of |
| 210 |
length \ccode{L}. |
| 211 |
|
| 212 |
The rationale for the ordering is the following. Most applications |
| 213 |
will define residue scores in vectors and matrices that are smaller |
| 214 |
than the full range of the internal alphabet; for instance, it's |
| 215 |
common to only have \ccode{K} scores for the canonical residues. As |
| 216 |
much as possible, we want array indices to be the same whether we're |
| 217 |
accessing the full internal alphabet or a smaller score vector or |
| 218 |
matrix. So: we expect many applications to have score vectors or |
| 219 |
matrices that only contain the \ccode{K} canonical residues, so the |
| 220 |
canonical residues go first. We expect some applications to treat |
| 221 |
gaps as an extra symbol, and provide \ccode{K+1} position-specific |
| 222 |
scores or a \ccode{K+1} $\times$ \ccode{K+1} score matrix, so the gap |
| 223 |
character is next. We expect a few applications to optimize degeneracy |
| 224 |
scoring by precalculating them in \ccode{Kp-2} vectors or $Kp-2 \times |
| 225 |
Kp-2$ matrices, so the degeneracies go next (the gap character at $K$ |
| 226 |
might then go unused in the score vectors and matrices, but that's a |
| 227 |
minor inefficiency). The 'any' symbol should be at a predictable |
| 228 |
position in the degeneracy list, so it's arbitrarily placed at the |
| 229 |
end, in position \ccode{Kp-3}. The most robust applications will also |
| 230 |
handle the not-a-residue symbol (they may see translated stop codons), |
| 231 |
so it's next. Finally, the missing data symbol is expected to always |
| 232 |
require special handling when it occurs, rather than appearing in a |
| 233 |
score vector or matrix, so it's put last. |
| 234 |
|
| 235 |
\subsection{The standard alphabets: DNA, RNA, protein} |
| 236 |
|
| 237 |
The three standard internal alphabets are: |
| 238 |
|
| 239 |
\begin{table}[h] |
| 240 |
\begin{tabular}{llccrr} |
| 241 |
\textbf{Type} & \ccode{sym} & \textbf{equivs} & \textbf{gaps} & \ccode{K} & \ccode{Kp} \\ |
| 242 |
\ccode{eslRNA} & \ccode{ACGU-RYMKSWHBVDN*\~} & T=U; X=N & \ccode{-\_.} & 4 & 18 \\ |
| 243 |
\ccode{eslDNA} & \ccode{ACGT-RYMKSWHBVDN*\~} & U=T; X=N & \ccode{-\_.} & 4 & 18 \\ |
| 244 |
\ccode{eslAMINO} & \ccode{ACDEFGHIKLMNPQRSTVWY-BJZOUX*\~} & & \ccode{-\_.} & 20 & 29 \\ |
| 245 |
\end{tabular} |
| 246 |
\end{table} |
| 247 |
|
| 248 |
The \ccode{sym} string contains all the symbols that can be handled |
| 249 |
internally, and all the residues that can be represented when a |
| 250 |
digitized sequence is converted back to text. An application might |
| 251 |
still convert some characters for its own purposes before displaying |
| 252 |
an alphabetic string; for instance, to use different gap symbols for |
| 253 |
insertions versus deletions, or to use upper/lower case conventions to |
| 254 |
represent match/insert positions in a profile HMM alignment. |
| 255 |
|
| 256 |
The standard DNA and RNA alphabets follow published IUBMB |
| 257 |
recommendations (``Nomenclature for incompletely specified bases in |
| 258 |
nucleic acid'' \citep{IUBMB85}), with an addition of X as an |
| 259 |
equivalence for N (acquiescing to the \emph{de facto} BLAST filter |
| 260 |
standard of using X's to mask residues), and equivalencing T to U in |
| 261 |
RNA sequences (and vice versa in DNA). |
| 262 |
|
| 263 |
The one-letter code for amino acids follows section 3AA-21 of the |
| 264 |
IUPAC recommendations \citep{IUPAC84}. The code is augmented by U for |
| 265 |
selenocysteine, as recommended in 1999 by the JCBN/NC-IUBMB Newsletter |
| 266 |
(\url{http://www.chem.qmul.ac.uk/iubmb/newsletter/1999/item3.html}). |
| 267 |
It is also augmented by O for pyrrolysine and J for a |
| 268 |
leucine/isoleucine ambiguity (from a mass spectrometry experiment), |
| 269 |
following usage in the RESID database |
| 270 |
(\url{http://www.ebi.ac.uk/RESID/}). |
| 271 |
|
| 272 |
|
| 273 |
\subsection{Degenerate residues} |
| 274 |
|
| 275 |
The symbols from \ccode{K+1..Kp-4} in the internal alphabet are all |
| 276 |
treated as degenerate residues. |
| 277 |
|
| 278 |
When creating a custom alphabet, each degenerate symbol is initialized |
| 279 |
by calling \ccode{esl\_alphabet\_SetDegeneracy(alphabet, c, syms)} to |
| 280 |
assign degenerate alphabetic symbol \ccode{c} to the alphabetic |
| 281 |
symbols in the string \ccode{syms}. For example, |
| 282 |
\ccode{esl\_alphabet\_SetDegeneracy(a, 'R', \"AG\")} assigns R |
| 283 |
(purine) to mean A or G. For the standard biosequence alphabets, this |
| 284 |
is done automatically to define the proper degeneracy codes. |
| 285 |
|
| 286 |
For amino acid alphabets, the default code is: |
| 287 |
|
| 288 |
\begin{cchunk} |
| 289 |
esl_alphabet_SetDegeneracy(a, 'B', "ND"); |
| 290 |
esl_alphabet_SetDegeneracy(a, 'J', "IL"); |
| 291 |
esl_alphabet_SetDegeneracy(a, 'Z', "QE"); |
| 292 |
\end{cchunk} |
| 293 |
|
| 294 |
For RNA alphabets, the default code is: |
| 295 |
|
| 296 |
\begin{cchunk} |
| 297 |
esl_alphabet_SetDegeneracy(a, 'R', "AG"); |
| 298 |
esl_alphabet_SetDegeneracy(a, 'Y', "CU"); |
| 299 |
esl_alphabet_SetDegeneracy(a, 'M', "AC"); |
| 300 |
esl_alphabet_SetDegeneracy(a, 'K', "GU"); |
| 301 |
esl_alphabet_SetDegeneracy(a, 'S', "CG"); |
| 302 |
esl_alphabet_SetDegeneracy(a, 'W', "AU"); |
| 303 |
esl_alphabet_SetDegeneracy(a, 'H', "ACU"); |
| 304 |
esl_alphabet_SetDegeneracy(a, 'B', "CGU"); |
| 305 |
esl_alphabet_SetDegeneracy(a, 'V', "ACG"); |
| 306 |
esl_alphabet_SetDegeneracy(a, 'D', "AGU"); |
| 307 |
\end{cchunk} |
| 308 |
|
| 309 |
For DNA alphabets, the calls are is the same as for RNA code, but with |
| 310 |
\ccode{T} in place of \ccode{U}. |
| 311 |
|
| 312 |
|
| 313 |
\subsubsection{Implementation: the degeneracy map} |
| 314 |
|
| 315 |
The alphabet's degeneracy map is implemented in an array |
| 316 |
\ccode{a->degen[0..Kp-1][0..K-1]} of 1/0 (TRUE/FALSE) flags. |
| 317 |
\ccode{a->degen[x][y] == TRUE} indicates that the residue set $D(x)$ |
| 318 |
for degeneracy code \ccode{x} contains base residue \ccode{y}. |
| 319 |
\ccode{a->ndegen[x]} contains the cardinality $|D(x)|$, how many base |
| 320 |
residues are represented by degeneracy code \ccode{x}. |
| 321 |
|
| 322 |
For the two kinds of gap symbols, the degeneracy map is empty; all |
| 323 |
flags are FALSE and the cardinality is 0. |
| 324 |
|
| 325 |
Because character \ccode{Kp-3} in the internal alphabet is |
| 326 |
automatically assumed to be an ``any'' character (such as 'N' for DNA |
| 327 |
or RNA, 'X' for protein), \ccode{a->degen[Kp-3][i] = 1} for all |
| 328 |
$i=0..K-1$, and \ccode{a->ndegen[Kp-3] = K}. |
| 329 |
|
| 330 |
The storage of the degeneracy map is a little wasteful. We really only |
| 331 |
need rows \ccode{a->degen[K+1..Kp-3]}, but optimizing this would |
| 332 |
create some index translation hassles, and it doesn't seem worth it. |
| 333 |
|
| 334 |
|
| 335 |
\subsection{Equivalent residues} |
| 336 |
|
| 337 |
The concept of equivalent residues allows an input symbol to be mapped |
| 338 |
to a different internal symbol. One use of equivalence is to map both |
| 339 |
lower and upper case input to the same internal representation. |
| 340 |
Another use is to allow several different input characters to mean a |
| 341 |
gap. Another use is to silently accept and ``fix'' nonstandard but |
| 342 |
common input ``errors'', such as the use of T instead of U in RNA |
| 343 |
sequences (or vice versa in DNA), or the use of X instead of N as an |
| 344 |
ambiguity code in nucleic acid sequences. |
| 345 |
|
| 346 |
The call \ccode{esl\_alphabet\_SetEquiv(a, 'U', 'T')}, for example, |
| 347 |
makes an alphabet interpret \ccode{U} as a \ccode{T} (encoding both as |
| 348 |
\ccode{3}, in the case of the standard DNA and RNA alphabets). |
| 349 |
|
| 350 |
All three standard alphabets accept \ccode{\_} or \ccode{.} symbols |
| 351 |
as equivalences for the standard gap symbol \ccode{-}. An application |
| 352 |
can define additional gap characters, such as \ccode{,}, by calling |
| 353 |
\ccode{esl\_alphabet\_SetSynonym(a, ',', '-')} on one of the standard |
| 354 |
alphabets to define additional equivalences (that is, you don't have |
| 355 |
to create a custom alphabet to add new equivalences). |
| 356 |
|
| 357 |
\ccode{esl\_alphabet\_SetCaseInsensitive()} maps both upper case and |
| 358 |
lower case input alphabetic characters map to their equivalent in the |
| 359 |
internal alphabet in a case-insensitive manner. This function works |
| 360 |
only on residues that have already been declared to be part of the |
| 361 |
alphabet, so when defining a custom alphabet, it must be called after |
| 362 |
all individual equivalences have been defined. The standard alphabets |
| 363 |
are always set to be case insensitive. |
| 364 |
|
| 365 |
\subsubsection{Implementation of equivalent residues: the input map} |
| 366 |
|
| 367 |
Internally, an \textbf{input map}, \ccode{a->inmap[0..127]}, specifies |
| 368 |
how an input ASCII 7-bit text symbol is converted to digital |
| 369 |
code. \ccode{a->inmap['T'] = 3} in the standard DNA alphabet, for |
| 370 |
example, and the call \ccode{esl\_alphabet\_SetSynonym(a, 'U', 'T')} |
| 371 |
sets \ccode{a->inmap['U'] = a->inmap['T']}. |
| 372 |
|
| 373 |
The elements in input maps are of type \ccode{unsigned char}. Legal |
| 374 |
values are 0..127 (values that can be cast to the \ccode{unsigned |
| 375 |
char} codes in a digitized sequence) and two additional flags with |
| 376 |
negative values, \ccode{eslILLEGAL\_CHAR} (255) and |
| 377 |
\ccode{eslIGNORED\_CHAR} (254). |
| 378 |
|
| 379 |
\subsection{Unusual or modified residues} |
| 380 |
|
| 381 |
In addition to the canonical 4 or 20 residues and their ambiguity |
| 382 |
codes, there are many unusual and/or modified residues. For instance, |
| 383 |
there are many posttranscriptional or posttranslational modifications |
| 384 |
on residues in RNAs and proteins. Some databases try to capture this |
| 385 |
information in a single-letter alphabetic code, such as the Sprinzl |
| 386 |
transfer RNA database \cite{Sprinzl98}. |
| 387 |
|
| 388 |
Additionally, and perhaps more importantly, proteins are known to |
| 389 |
contain at least two additional genetically encoded amino acids, |
| 390 |
selenocysteine and pyrrolysine. Selenocysteine is represented by a |
| 391 |
\ccode{U} according to the IUPAC standard, and pyrrolysine is |
| 392 |
represented by a \ccode{O} in the RESID database at EBI. |
| 393 |
|
| 394 |
Unusual one-letter residue codes pose a tradeoff issue for sequence |
| 395 |
analysis applications. On the one hand, an application should |
| 396 |
recognize symbols for unusual or modified residues, and be able to |
| 397 |
represent them both internally and in any sequence output. For |
| 398 |
example, no application should read an input selenocysteine residue |
| 399 |
(\ccode{U}) and output it as a cysteine (\ccode{C}) -- this changes |
| 400 |
the original sequence and causes data corruption.\footnote{However, at |
| 401 |
least one the main public protein databases (UniProt) has already |
| 402 |
chosen to replace all selenocysteines with \ccode{C} and all |
| 403 |
pyrrolysines with \ccode{K}, for fear of breaking legacy sequence |
| 404 |
analysis software. So, this data corruption is already a fact of |
| 405 |
life.} On the other hand, most sequence analysis applications would |
| 406 |
not want to take the trouble to define a canonical alphabet larger |
| 407 |
than the usual 4 or 20 residues, and then have to parameterize that |
| 408 |
alphabet, just to be able to handle a few rare residues. (Pyrrolysine, |
| 409 |
for example, has only been found in a handful of proteins in a few |
| 410 |
Archaea.) It is useful to be able to deal with probability parameters |
| 411 |
and scores only for the canonical alphabet. However (on yet another |
| 412 |
hand!) in some cases one \emph{would} want to write a specialized |
| 413 |
application that parameterizes unusual residues as part of its |
| 414 |
canonical alphabet -- for instance, an application for analyzing |
| 415 |
posttranscriptional tRNA modifications, for example. |
| 416 |
|
| 417 |
Therefore, Easel must not force an input selenocysteine or pyrrolysine |
| 418 |
(or any other unusual residue) to be recoded as an arbitrary symbol |
| 419 |
(such as cysteine or lysine). That is, unusual symbols cannot be |
| 420 |
treated as equivalences, but must be allowed to be part of the |
| 421 |
internal alphabet. However, Easel \emph{can} allow unusual symbols to |
| 422 |
be treated as noncanonical, and \emph{score} them as some other |
| 423 |
arbitrary residue, as a reasonable approximation. Thus for most |
| 424 |
purposes, unusual symbols are best handled as a special kind of |
| 425 |
degeneracy, with a one-to-one degeneracy map from the unusual symbol |
| 426 |
to the ``closest'' canonical residue. |
| 427 |
|
| 428 |
Therefore, the default amino acid alphabet accepts selenocysteine |
| 429 |
(\ccode{U}) and pyrrolysine symbols (\ccode{O}) and represents them in |
| 430 |
the internal alphabet, and maps them as ``degeneracies'' onto cysteine |
| 431 |
(\ccode{C}) and lysine (\ccode{K}), respectively. |
| 432 |
|
| 433 |
When that behavior is not suitable, an application can also define any |
| 434 |
custom alphabet it chooses, as described below. |
| 435 |
|
| 436 |
|
| 437 |
\subsection{Creating a custom alphabet} |
| 438 |
|
| 439 |
Figure~\ref{fig:alphabet_example2} shows an example of creating a |
| 440 |
customized 22-letter amino acid alphabet that includes the \ccode{U} |
| 441 |
selenocysteine code and the \ccode{O} pyrrolysine code. |
| 442 |
|
| 443 |
\begin{figure} |
| 444 |
\input{cexcerpts/alphabet_example2} |
| 445 |
\caption{An example of creating a custom alphabet.} |
| 446 |
\label{fig:alphabet_example2} |
| 447 |
\end{figure} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
\subsection{Scoring degenerate residues} |
| 452 |
|
| 453 |
To score a degenerate residue code $x$, Easel provides two strategies. |
| 454 |
One set of functions assigns an average score: |
| 455 |
|
| 456 |
\[ |
| 457 |
S(x) = \frac{\sum_{y \in D(x)} S(y) } { |D(x)| }, |
| 458 |
\] |
| 459 |
|
| 460 |
where $D(x)$ is the set of residues $y$ represented by degeneracy code |
| 461 |
$x$ (for example, $D(\mbox{R}) = \{ \mbox{A,G} \}$), $| D(x) |$ is the |
| 462 |
number of residues that the degeneracy code includes, and $S(y)$ is |
| 463 |
the score of a base residue $y$. Because scores $S(y)$ are commonly |
| 464 |
kept as integers, floats, or doubles, depending on the application, |
| 465 |
three functions are provided that differ only in the storage type of |
| 466 |
the scores: \ccode{esl\_abc\_IAvgScore(a,x,sc)}, |
| 467 |
\ccode{esl\_abc\_FAvgScore(a,x,sc)}, and |
| 468 |
\ccode{esl\_abc\_DAvgScore(a,x,sc)} calculate and return the average |
| 469 |
score of residue \ccode{x} in alphabet \ccode{a} given a base score |
| 470 |
vector \ccode{sc[0]..sc[K-1]} for integers, floats, and doubles, |
| 471 |
respectively. |
| 472 |
|
| 473 |
A second set of functions assigns an expected score, weighted by an |
| 474 |
expected occurrence probability $p_y$ of the residues $y$ (often the |
| 475 |
random background frequencies): |
| 476 |
|
| 477 |
\[ |
| 478 |
S(x) = \frac{\sum_{y \in D(x)} p_y S(y) } { \sum_{y \in D(x)} p_y }, |
| 479 |
\] |
| 480 |
|
| 481 |
These three functions are \ccode{esl\_abc\_IExpectScore(a,x,sc,p)}, |
| 482 |
\ccode{esl\_abc\_FExpectScore(a,x,sc,p)}, and |
| 483 |
\ccode{esl\_abc\_DExpectScore(a,x,sc,p)}. For the integer and float |
| 484 |
versions, the probability vector is in floats; for the double version, |
| 485 |
the probability vector is in doubles. |
| 486 |
|
| 487 |
For efficiency reasons, an application might choose to preculate |
| 488 |
scores for all possible degenerate codes it might see. HMMER, for |
| 489 |
example, turns probability vectors of length \ccode{K} into score |
| 490 |
residues of length \ccode{Kp}. |
| 491 |
|
| 492 |
An application might also choose to score residues on-the-fly, using |
| 493 |
score vectors of length \ccode{K}. Each input residue \ccode{x} would |
| 494 |
then have to be tested to see if it is degenerate, before scoring it |
| 495 |
appropriately. \ccode{esl\_abc\_IsBasic(a, x)} returns \ccode{TRUE} |
| 496 |
if \ccode{x} is in the basic set of \ccode{K} residues in alphabet |
| 497 |
\ccode{a}, and \ccode{FALSE} otherwise. Similarly, |
| 498 |
\ccode{esl\_abc\_IsGap(a,x)} tests whether $x$ is a gap, and |
| 499 |
\ccode{esl\_abc\_IsDegenerate(a,x)} tests whether $x$ is a degenerate |
| 500 |
residue. |
| 501 |
|