NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alignment_base.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <nvbio/basic/types.h>
31 
32 namespace nvbio {
33 
36 namespace aln {
38 
46 
51 
55 
57 
69 
73 struct PatternBlockingTag {};
74 
79 struct TextBlockingTag {};
80 
87 template <uint32 ALPHABET_SIZE_T> struct MyersTag { static const uint32 ALPHABET_SIZE = ALPHABET_SIZE_T; };
88 
89 template <typename T> struct transpose_tag {};
90 template <> struct transpose_tag<PatternBlockingTag> { typedef TextBlockingTag type; };
91 template <> struct transpose_tag<TextBlockingTag> { typedef PatternBlockingTag type; };
92 
93 template <typename T> struct transpose_aligner {};
94 
96 
104 
105 struct SmithWatermanTag {};
106 struct GotohTag {};
107 struct EditDistanceTag {};
109 
114 template <typename aligner_type>
115 struct aligner_tag {
116  typedef typename aligner_type::aligner_tag type;
117 };
118 
120 
123 template <typename ScoreType>
124 struct Alignment
125 {
128 
130  Alignment(const ScoreType _score, const uint2 _source, const uint2 _sink) : score( _score ), source( _source ), sink(_sink) {}
131 
132  ScoreType score;
133  uint2 source;
134  uint2 sink;
135 };
136 
141  INSERTION = 1u,
142  DELETION = 2u,
143  SINK = 3u,
146  // MASKS
147  HMASK = 3u,
148  EMASK = 4u,
149  FMASK = 8u,
150 };
151 
154 enum State
155 {
156  HSTATE = 0,
157  ESTATE = 1,
158  FSTATE = 2
159 };
160 
172 
179 template <AlignmentType T_TYPE, typename AlgorithmType = PatternBlockingTag>
181 {
182  static const AlignmentType TYPE = T_TYPE;
183 
185  typedef AlgorithmType algorithm_tag;
186 };
187 
188 template <AlignmentType T_TYPE, typename AlgorithmTag>
189 struct transpose_aligner< EditDistanceAligner<T_TYPE,AlgorithmTag> >
190 {
192 };
193 
194 template <AlignmentType TYPE>
197 {
198  return EditDistanceAligner<TYPE>();
199 }
200 
201 template <AlignmentType TYPE, typename algorithm_tag>
204 {
206 }
207 
208 template <AlignmentType TYPE>
210 {
212 }
213 template <AlignmentType TYPE, typename scoring_scheme_type>
215 {
217 }
218 
255 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmType = PatternBlockingTag>
257 {
258  static const AlignmentType TYPE = T_TYPE;
259 
261  typedef AlgorithmType algorithm_tag;
262 
264  GotohAligner(const scoring_scheme_type _scheme) : scheme(_scheme) {}
265 
266  scoring_scheme_type scheme;
267 };
268 
269 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmTag>
270 struct transpose_aligner< GotohAligner<T_TYPE, scoring_scheme_type, AlgorithmTag> >
271 {
273 };
274 
275 template <AlignmentType TYPE, typename scoring_scheme_type>
278 {
280 }
281 
282 template <AlignmentType TYPE, typename algorithm_tag, typename scoring_scheme_type>
285 {
287 }
288 
289 template <AlignmentType TYPE, typename scoring_scheme_type>
291 {
293 }
294 template <AlignmentType TYPE, typename scoring_scheme_type>
296 {
298 }
299 
326 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmType = PatternBlockingTag>
328 {
329  static const AlignmentType TYPE = T_TYPE;
330 
332  typedef AlgorithmType algorithm_tag;
333 
335  SmithWatermanAligner(const scoring_scheme_type _scheme) : scheme(_scheme) {}
336 
337  scoring_scheme_type scheme;
338 };
339 
340 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmTag>
341 struct transpose_aligner< SmithWatermanAligner<T_TYPE, scoring_scheme_type, AlgorithmTag> >
342 {
344 };
345 
346 template <AlignmentType TYPE, typename scoring_scheme_type>
349 {
351 }
352 
353 template <AlignmentType TYPE, typename scoring_scheme_type>
355 {
357 }
358 template <AlignmentType TYPE, typename scoring_scheme_type>
360 {
362 }
363 
369 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmType = PatternBlockingTag>
371 {
372  static const AlignmentType TYPE = T_TYPE;
373 
375  typedef AlgorithmType algorithm_tag;
376 
378  HammingDistanceAligner(const scoring_scheme_type _scheme) : scheme(_scheme) {}
379 
380  scoring_scheme_type scheme;
381 };
382 
383 template <AlignmentType T_TYPE, typename scoring_scheme_type, typename AlgorithmTag>
384 struct transpose_aligner< HammingDistanceAligner<T_TYPE,scoring_scheme_type,AlgorithmTag> >
385 {
387 };
388 
389 template <AlignmentType TYPE, typename scoring_scheme_type>
392 {
394 }
395 
396 template <AlignmentType TYPE, typename scoring_scheme_type, typename algorithm_tag>
399 {
401 }
402 
403 template <AlignmentType TYPE, typename scoring_scheme_type>
405 {
407 }
408 template <AlignmentType TYPE, typename scoring_scheme_type>
410 {
412 }
413 
415 
417 
418 } // namespace aln
419 } // namespace nvbio
420 
421 #include <nvbio/alignment/utils.h>