-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmbiguous.hpp
276 lines (246 loc) · 10.6 KB
/
Ambiguous.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/**
* \file Ambiguous.hpp
* \author D'Oleris Paul Thatcher Edlefsen [email protected]
* \par Library:
* galosh::prolific
* \brief
* Metafunctions for describing how one residue type (eg seqan::Dna5 or
* seqan::Iupac) is ambiguous over another (eg seqan::Dna).
* \par Oveview:
* This file is part of prolific, a library of useful C++ classes for
* working with genomic sequence data and Profile HMMs. Please see the
* document CITING, which should have been included with this file. You may
* use at will, subject to the license (Apache v2.0), but *please cite the
* relevant papers* in your documentation and publications associated with
* uses of this library. Thank you!
*
* \copyright © 2015 by Paul T. Edlefsen, Fred Hutchinson Cancer
* Research Center.
* \par License:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef __GALOSH_AMBIGUOUS_HPP__
#define __GALOSH_AMBIGUOUS_HPP__
// TODO: REMOVE
#include <iostream>
#include <seqan/basic.h>
#include <seqan/sequence.h> // for ordValue
#include <seqan/stream.h> // now required to avoid "use of undeclared identifier 'directionIterator'" error
#include "Prolific.hpp"
#include "AminoAcid20.hpp"
namespace galosh {
/* ///////////////////////////////////////////////////////////////////////////// */
//IsAmbiguous
/* ////////////////////////////////////////////////////////////////////////////// */
/**
.Metafunction.IsAmbiguous:
..summary:Tests whether one type (the "larger type") is ambiguous over another (the "smaller type") -- that is, whether there exists a multivalued mapping from the elements of the larger (enumerated) type to elements of the smaller (enumerated) type.
..signature:IsAmbiguous<LargerType, SmallerType>::Type
..param.LargerType:The enumerated type being tested for ambiguity over the other type.
..param.SmallerType:The other enumerated type.
..returns.param.Type:@Tag.Logical Values.True@, if $LargerType$ is ambiguous over $SmallerType$, @Tag.Logical Values.False@ otherwise.
...default:@Tag.Logical Values.False@
..remarks:Both types should have a @Metafunction.ValueSize@, and the @Metafunction.ValueSize@ of the former should be greater than or equal to that of the latter. The @Metafunction.AmbiguousValueSize@ of at least one value in 0..ValueSize<LargerType>::VALUE should be greater than 1, and none should be less than 1.
..see:Metafunction.AmbiguousValueSize
..see:Metafunction.ValueSize
*/
template <typename LargerType, typename SmallerType>
struct _IsAmbiguous {
typedef seqan::False Type;
};
template <typename LargerType, typename SmallerType>
struct IsAmbiguous:
public _IsAmbiguous<LargerType, SmallerType> {};
template <typename LargerType, typename SmallerType>
struct IsAmbiguous<LargerType const, SmallerType const>:
public IsAmbiguous<LargerType, SmallerType> {};
//////////////////////////////////////////////////////////////////////////////
// Dna5 is ambiguous over Dna
template <>
struct IsAmbiguous<seqan::Dna5, seqan::Dna>
{
typedef seqan::True Type;
};
//____________________________________________________________________________
template <typename T = void>
struct _Translate_Table_Ambiguous_Dna5_2_Dna
{
static char const VALUE[ 5 ][ 4 ];
};
template <typename T>
char const _Translate_Table_Ambiguous_Dna5_2_Dna<T>::VALUE[ 5 ][ 4 ] =
{
{ 0, 0, 0, 0 },
{ 1, 1, 1, 1 },
{ 2, 2, 2, 2 },
{ 3, 3, 3, 3 },
{ 0, 1, 2, 3 }
};
template <typename T = void>
struct _Size_Table_Ambiguous_Dna5_2_Dna
{
static char const VALUE[ 5 ];
};
template <typename T>
char const _Size_Table_Ambiguous_Dna5_2_Dna<T>::VALUE[ 5 ] =
{
1, 1, 1, 1, 4
};
//////////////////////////////////////////////////////////////////////////////
static
inline void ambiguousAssign ( seqan::Dna & c_target, seqan::Dna5 const & source, unsigned int const & which )
{
SEQAN_CHECKPOINT
c_target.value =
galosh::_Translate_Table_Ambiguous_Dna5_2_Dna<>::VALUE[ source.value ][ which ];
}
static
inline size_t ambiguousCount ( seqan::Dna5 const & source, seqan::Dna const & )
{
return
galosh::_Size_Table_Ambiguous_Dna5_2_Dna<>::VALUE[ source.value ];
}
/*/////////////////////////////////////////////////////////////////////////////
// Iupac is ambiguous over Dna */
template <>
struct IsAmbiguous<seqan::Iupac, seqan::Dna>
{
typedef seqan::True Type;
};
//____________________________________________________________________________
template <typename T = void>
struct _Translate_Table_Ambiguous_Iupac_2_Dna
{
static char const VALUE[ 16 ][ 4 ];
};
template <typename T>
char const _Translate_Table_Ambiguous_Iupac_2_Dna<T>::VALUE[ 16 ][ 4 ] =
{
// //TGCA=[hex] // IUPAC
{ 3, 3, 3, 3 }, //0000=0 = or U // U
{ 0, 0, 0, 0 }, //0001=1 // A
{ 1, 1, 1, 1 }, //0010=2 // C
{ 0, 1, 0, 0 }, //0011=3 AC // M: A or C
{ 2, 2, 2, 2 }, //0100=4 // G
{ 0, 2, 0, 0 }, //0101=5 AG (purine) // R: Purine (A or G)
{ 1, 2, 0, 0 }, //0110=6 CG // S: C or G
{ 0, 1, 2, 0 }, //0111=7 non-T // V: A or C or G
{ 3, 3, 3, 3 }, //1000=8 // T
{ 0, 3, 0, 0 }, //1001=9 TA // W: A or T/U
{ 1, 3, 0, 0 }, //1010=A TC (pyrimidine)// Y: Pyrimidine (C or T/U)
{ 0, 1, 3, 0 }, //1011=B not-G // H: A or C or T/U
{ 2, 3, 0, 0 }, //1100=C TG // K: G or T/U
{ 0, 2, 3, 0 }, //1101=D not-C // D: A or G or T/U
{ 1, 2, 3, 1 }, //1110=E non-A // B: C or G or T/U
{ 0, 1, 2, 3 } //1111=F any // N: A or C or G or T/U
};
template <typename T = void>
struct _Size_Table_Ambiguous_Iupac_2_Dna
{
static char const VALUE[ 16 ];
};
template <typename T>
char const _Size_Table_Ambiguous_Iupac_2_Dna<T>::VALUE[ 16 ] =
{
// U, A, C, M, G, R, S, V, T, W, Y, H, K, D, B, N.
1, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
};
//////////////////////////////////////////////////////////////////////////////
static
inline void ambiguousAssign ( seqan::Dna & c_target, seqan::Iupac const & source, unsigned int const & which )
{
SEQAN_CHECKPOINT
c_target.value =
galosh::_Translate_Table_Ambiguous_Iupac_2_Dna<>::VALUE[ source.value ][ which ];
}
static
inline size_t ambiguousCount ( seqan::Iupac const & source, seqan::Dna const & )
{
return
galosh::_Size_Table_Ambiguous_Iupac_2_Dna<>::VALUE[ source.value ];
}
// mark
//////////////////////////////////////////////////////////////////////////////
// AminoAcid is ambiguous over AminoAcid20
template <>
struct IsAmbiguous<seqan::AminoAcid, seqan::AminoAcid20>
{
typedef seqan::True Type;
};
//____________________________________________________________________________
template <typename T = void>
struct _Translate_Table_Ambiguous_AminoAcid_2_AminoAcid20
{
static char const VALUE[ 27 ][ 20 ];
};
template <typename T>
char const _Translate_Table_Ambiguous_AminoAcid_2_AminoAcid20<T>::VALUE[ 27 ][ 20 ] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // A
{ 2, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // (it's B = D or N)
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // C
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, // D
{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, // E
{ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, // F
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, // G
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, // H
{ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, // I
{ 7, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // (it's J = L or I)
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }, // K
{ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }, // L
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, // M
{ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11 }, // N
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, // (it's O, but we'll map it to all)
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 }, // P
{ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 }, // Q
{ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 }, // R
{ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, // S
{ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }, // T
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, // (it's U, but we'll map it to all)
{ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 }, // V
{ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }, // W
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, // (it's X, but we'll map it to all)
{ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 }, // Y
{ 3, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // (it's Z = E or Q)
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 } // (it's *, but we'll map it to all)
};
template <typename T = void>
struct _Size_Table_Ambiguous_AminoAcid_2_AminoAcid20
{
static char const VALUE[ 27 ];
};
template <typename T>
char const _Size_Table_Ambiguous_AminoAcid_2_AminoAcid20<T>::VALUE[ 27 ] =
{
1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 20, 1, 1, 1, 1, 1, 20, 1, 1, 20, 1, 2, 20
};
//////////////////////////////////////////////////////////////////////////////
static
inline void ambiguousAssign ( seqan::AminoAcid20 & c_target, seqan::AminoAcid const & source, unsigned int const & which )
{
SEQAN_CHECKPOINT
c_target.value =
galosh::_Translate_Table_Ambiguous_AminoAcid_2_AminoAcid20<>::VALUE[ source.value ][ which ];
}
static
inline size_t ambiguousCount ( seqan::AminoAcid const & source, seqan::AminoAcid20 const & )
{
return
galosh::_Size_Table_Ambiguous_AminoAcid_2_AminoAcid20<>::VALUE[ source.value ];
}
// endmark
} // End namespace galosh
#endif // __GALOSH_AMBIGUOUS_HPP__