1 // ==========================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2015, Knut Reinert, FU Berlin
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
16 // its contributors may be used to endorse or promote products derived
17 // from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32 // Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
33 // ==========================================================================
34
35 #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_LOCAL_ALIGNMENT_ENUMERATION_BANDED_H_
36 #define SEQAN_INCLUDE_SEQAN_ALIGN_LOCAL_ALIGNMENT_ENUMERATION_BANDED_H_
37
38 namespace seqan {
39
40 // ============================================================================
41 // Forwards
42 // ============================================================================
43
44 // ============================================================================
45 // Tags, Classes, Enums
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // Specialization Banded LocalAlignmentEnumerator
50 // ----------------------------------------------------------------------------
51
52 struct Banded_;
53 typedef Tag<Banded_> Banded;
54
55 template <typename TScore>
56 class LocalAlignmentEnumerator<TScore, Banded>
57 {
58 public:
59 typedef typename Value<TScore>::Type TScoreValue_;
60
61 TScore _score;
62 int _lowerDiag;
63 int _upperDiag;
64 TScoreValue_ _cutoff;
65 LocalAlignmentFinder<TScoreValue_> _finder;
66
LocalAlignmentEnumerator(TScore const & score,int lowerDiag,int upperDiag)67 LocalAlignmentEnumerator(TScore const & score, int lowerDiag, int upperDiag) :
68 _score(score), _lowerDiag(lowerDiag), _upperDiag(upperDiag), _cutoff(0)
69 {}
70
LocalAlignmentEnumerator(TScore const & score,int lowerDiag,int upperDiag,int cutoff)71 LocalAlignmentEnumerator(TScore const & score, int lowerDiag, int upperDiag, int cutoff) :
72 _score(score), _lowerDiag(lowerDiag), _upperDiag(upperDiag), _cutoff(cutoff)
73 {}
74 };
75
76 // ============================================================================
77 // Metafunctions
78 // ============================================================================
79
80 // ============================================================================
81 // Functions
82 // ============================================================================
83
84 // ----------------------------------------------------------------------------
85 // Function getScore()
86 // ----------------------------------------------------------------------------
87
88 template <typename TScoreValue, typename TScoreSpec>
89 inline TScoreValue
getScore(LocalAlignmentEnumerator<Score<TScoreValue,TScoreSpec>,Banded> const & enumerator)90 getScore(LocalAlignmentEnumerator<Score<TScoreValue, TScoreSpec>, Banded> const & enumerator)
91 {
92 return getScore(enumerator._finder);
93 }
94
95 // ----------------------------------------------------------------------------
96 // Function nextLocalAlignment()
97 // ----------------------------------------------------------------------------
98
99 template <typename TScoreValue, typename TScoreSpec, typename TSequenceH, typename TGapsSpecH, typename TSequenceV, typename TGapsSpecV>
100 inline bool
nextLocalAlignment(Gaps<TSequenceH,TGapsSpecH> & gapsH,Gaps<TSequenceV,TGapsSpecV> & gapsV,LocalAlignmentEnumerator<Score<TScoreValue,TScoreSpec>,Banded> & enumerator)101 nextLocalAlignment(Gaps<TSequenceH, TGapsSpecH> & gapsH,
102 Gaps<TSequenceV, TGapsSpecV> & gapsV,
103 LocalAlignmentEnumerator<Score<TScoreValue, TScoreSpec>, Banded> & enumerator)
104 {
105 if (enumerator._finder.needReinit)
106 return _localAlignment(enumerator._finder, gapsH, gapsV, enumerator._score, enumerator._cutoff,
107 enumerator._lowerDiag, enumerator._upperDiag, BandedWatermanEggert());
108 else
109 return _localAlignmentNext(enumerator._finder, gapsH, gapsV, enumerator._score,
110 enumerator._cutoff, enumerator._lowerDiag, enumerator._upperDiag,
111 BandedWatermanEggert());
112 }
113
114 template <typename TScoreValue, typename TScoreSpec, typename TSequence, typename TAlignSpec>
115 inline bool
nextLocalAlignment(Align<TSequence,TAlignSpec> & align,LocalAlignmentEnumerator<Score<TScoreValue,TScoreSpec>,Banded> & enumerator)116 nextLocalAlignment(Align<TSequence, TAlignSpec> & align,
117 LocalAlignmentEnumerator<Score<TScoreValue, TScoreSpec>, Banded> & enumerator)
118 {
119 SEQAN_ASSERT_EQ(length(rows(align)), 2u);
120
121 return nextLocalAlignment(row(align, 0), row(align, 1), enumerator);
122 }
123
124 } // namespace seqan
125
126 #endif // #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_LOCAL_ALIGNMENT_ENUMERATION_BANDED_H_
127