Debian Codegraph @

alphabet.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright 2011, Ben Langmead <[email protected]>
3 *
4 * This file is part of Bowtie 2.
5 *
6 * Bowtie 2 is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Bowtie 2 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Bowtie 2. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef ALPHABETS_H_
21 #define ALPHABETS_H_cxx . . $ `alphabet.h:21:9`!
22
23 #include <stdexcept>
24 #include <string>
25 #include <sstream>
26 #include <stdint.h>
27 #include "assert_helpers.h"cxx . . $ `<file>/assert_helpers.h`/
28
29 using namespace std;
30
31 /// Convert an ascii char to a DNA category. Categories are:
32 /// 0 -> invalid
33 /// 1 -> unambiguous a, c, g or t
34 /// 2 -> ambiguous
35 /// 3 -> unmatchable
36 extern uint8_tcxx . . $ uint8_t# asc2dnacatcxx . . $ asc2dnacat.[];
37 /// Convert masks to ambiguous nucleotides
38 extern char mask2dnacxx . . $ mask2dna.[];
39 /// Convert ambiguous ASCII nuceleotide to mask
40 extern uint8_tcxx . . $ uint8_t# asc2dnamaskcxx . . $ asc2dnamask.[];
41 /// Convert mask to # of alternative in the mask
42 extern int mask2popcntcxx . . $ mask2popcnt.[];
43 /// Convert an ascii char to a 2-bit base: 0=A, 1=C, 2=G, 3=T, 4=N
44 extern uint8_tcxx . . $ uint8_t# asc2dnacxx . . $ asc2dna.[];
45 /// Convert an ascii char representing a base or a color to a 2-bit
46 /// code: 0=A,0; 1=C,1; 2=G,2; 3=T,3; 4=N,.
47 extern uint8_tcxx . . $ uint8_t# asc2dnaOrColcxx . . $ asc2dnaOrCol.[];
48 /// Convert a pair of DNA masks to a color mask
49 extern uint8_tcxx . . $ uint8_t# dnamasks2colormaskcxx . . $ dnamasks2colormask.[16][16];
50
51 /// Convert an ascii char to a color category. Categories are:
52 /// 0 -> invalid
53 /// 1 -> unambiguous 0, 1, 2 or 3
54 /// 2 -> ambiguous (not applicable for colors)
55 /// 3 -> unmatchable
56 extern uint8_tcxx . . $ uint8_t# asc2colcatcxx . . $ asc2colcat.[];
57 /// Convert an ascii char to a 2-bit base: 0=A, 1=C, 2=G, 3=T, 4=N
58 extern uint8_tcxx . . $ uint8_t# asc2colcxx . . $ asc2col.[];
59 /// Convert an ascii char to its DNA complement, including IUPACs
60 extern char asc2dnacompcxx . . $ asc2dnacomp.[];
61
62 /// Convert a pair of 2-bit (and 4=N) encoded DNA bases to a color
63 extern uint8_tcxx . . $ uint8_t# dinuc2colorcxx . . $ dinuc2color.[5][5];
64 /// Convert a 2-bit nucleotide (and 4=N) and a color to the
65 /// corresponding 2-bit nucleotide
66 extern uint8_tcxx . . $ uint8_t# nuccol2nuccxx . . $ nuccol2nuc.[5][5];
67 /// Convert a 4-bit mask into an IUPAC code
•68 extern signed char mask2iupaccxx . . $ mask2iupac.[16];
69
70 /// Convert an ascii color to an ascii dna char
71 extern char col2dnacxx . . $ col2dna.[];
72 /// Convert an ascii dna to a color char
73 extern char dna2colcxx . . $ dna2col.[];
74 /// Convert an ascii dna to a color char
75 extern const char* dna2colstrcxx . . $ dna2colstr.[];
76
77 /// Convert bit encoded DNA char to its complement
78 extern int dnacompcxx . . $ dnacomp.[5];
79
80 /// String of all DNA and IUPAC characters
81 extern const char *iupacscxx . . $ iupacs.;
82
83 /// Map from masks to their reverse-complement masks
84 extern int maskcompcxx . . $ maskcomp.[16];
85
86 /**
87 * Return true iff c is a Dna character.
88 */
89 static inline bool isDnacxx . . $ isDna(b5fd09639b7a0261).(char c) {
90 return asc2dnacatcxx . . $ asc2dnacat.[(int)c] > 0;
91 }
92
93 /**
94 * Return true iff c is a color character.
95 */
96 static inline bool isColorcxx . . $ isColor(b5fd09639b7a0261).(char c) {
97 return asc2colcatcxx . . $ asc2colcat.[(int)c] > 0;
98 }
99
100 /**
101 * Return true iff c is an ambiguous Dna character.
102 */
103 static inline bool isAmbigNuccxx . . $ isAmbigNuc(b5fd09639b7a0261).(char c) {
104 return asc2dnacatcxx . . $ asc2dnacat.[(int)c] == 2;
105 }
106
107 /**
108 * Return true iff c is an ambiguous color character.
109 */
110 static inline bool isAmbigColorcxx . . $ isAmbigColor(b5fd09639b7a0261).(char c) {
111 return asc2colcatcxx . . $ asc2colcat.[(int)c] == 2;
112 }
113
114 /**
115 * Return true iff c is an ambiguous character.
116 */
117 static inline bool isAmbigcxx . . $ isAmbig(4485263e4e7b0db4).(char c, bool color) {
118 return (color ? asc2colcatcxx . . $ asc2colcat.[(int)c] : asc2dnacatcxx . . $ asc2dnacat.[(int)c]) == 2;
119 }
120
121 /**
122 * Return true iff c is an unambiguous DNA character.
123 */
124 static inline bool isUnambigNuccxx . . $ isUnambigNuc(b5fd09639b7a0261).(char c) {
125 return asc2dnacatcxx . . $ asc2dnacat.[(int)c] == 1;
126 }
127
128 /**
129 * Return the DNA complement of the given ASCII char.
130 */
131 static inline char compcxx . . $ comp(e6e5e845b55315fc).(char c) {
132 switch(c) {
133 case 'a': return 't';
134 case 'A': return 'T';
135 case 'c': return 'g';
136 case 'C': return 'G';
137 case 'g': return 'c';
138 case 'G': return 'C';
139 case 't': return 'a';
140 case 'T': return 'A';
141 default: return c;
142 }
143 }
144
145 /**
146 * Return the reverse complement of a bit-encoded nucleotide.
147 */
148 static inline int compDnacxx . . $ compDna(7864480464b09eea).(int c) {
149 assert_leqcxx . . $ `assert_helpers.h:239:9`!(c, 4);
150 return dnacompcxx . . $ dnacomp.[c];
151 }
152
153 /**
154 * Return true iff c is an unambiguous Dna character.
155 */
156 static inline bool isUnambigDnacxx . . $ isUnambigDna(b5fd09639b7a0261).(char c) {
157 return asc2dnacatcxx . . $ asc2dnacat.[(int)c] == 1;
158 }
159
160 /**
161 * Return true iff c is an unambiguous color character (0,1,2,3).
162 */
163 static inline bool isUnambigColorcxx . . $ isUnambigColor(b5fd09639b7a0261).(char c) {
164 return asc2colcatcxx . . $ asc2colcat.[(int)c] == 1;
165 }
166
167 /// Convert a pair of 2-bit (and 4=N) encoded DNA bases to a color
168 extern uint8_tcxx . . $ uint8_t# dinuc2colorcxx . . $ dinuc2color.[5][5];
169
170 /**
171 * Decode a not-necessarily-ambiguous nucleotide.
172 */
173 static inline void decodeNuccxx . . $ decodeNuc(fb8d58820d05c11e).(char c , int& num, int *alts) {
174 switch(c) {
175 case 'A': alts[0] = 0; num = 1; break;
176 case 'C': alts[0] = 1; num = 1; break;
177 case 'G': alts[0] = 2; num = 1; break;
178 case 'T': alts[0] = 3; num = 1; break;
179 case 'M': alts[0] = 0; alts[1] = 1; num = 2; break;
180 case 'R': alts[0] = 0; alts[1] = 2; num = 2; break;
181 case 'W': alts[0] = 0; alts[1] = 3; num = 2; break;
182 case 'S': alts[0] = 1; alts[1] = 2; num = 2; break;
183 case 'Y': alts[0] = 1; alts[1] = 3; num = 2; break;
184 case 'K': alts[0] = 2; alts[1] = 3; num = 2; break;
185 case 'V': alts[0] = 0; alts[1] = 1; alts[2] = 2; num = 3; break;
186 case 'H': alts[0] = 0; alts[1] = 1; alts[2] = 3; num = 3; break;
187 case 'D': alts[0] = 0; alts[1] = 2; alts[2] = 3; num = 3; break;
188 case 'B': alts[0] = 1; alts[1] = 2; alts[2] = 3; num = 3; break;
189 case 'N': alts[0] = 0; alts[1] = 1; alts[2] = 2; alts[3] = 3; num = 4; break;
190 default: {
191 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Bad IUPAC code: " <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). c <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", (int: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). (int)c <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
192 throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("");
193 }
194 }
195 }
196
197 extern void setIupacsCatcxx . . $ setIupacsCat(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# cat);
198
199 #endif /*ALPHABETS_H_*/