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: Rene Rahn <rene.rahn@fu-berlin.de>
33 // ==========================================================================
34
35 #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_DP_MATRIX_SPARSE_H_
36 #define SEQAN_INCLUDE_SEQAN_ALIGN_DP_MATRIX_SPARSE_H_
37
38 namespace seqan {
39
40 // ============================================================================
41 // Forwards
42 // ============================================================================
43
44 // ============================================================================
45 // Tags, Classes, Enums
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // Class DPMatrix [SparseDPMatrix]
50 // ----------------------------------------------------------------------------
51
52 template <typename TValue>
53 class DPMatrix_<TValue, SparseDPMatrix>
54 {
55 public:
56
57 typedef Matrix<TValue, 2> THost;
58
59 Holder<THost> _dataHost; // The host containing the actual matrix.
60
DPMatrix_()61 DPMatrix_() :
62 _dataHost()
63 {
64 create(_dataHost);
65 }
66
DPMatrix_(DPMatrix_ const & other)67 DPMatrix_(DPMatrix_ const & other) :
68 _dataHost(other._dataHost) {}
69
~DPMatrix_()70 ~DPMatrix_() {}
71
72 DPMatrix_ & operator=(DPMatrix_ const & other)
73 {
74 if (this != &other)
75 {
76 _dataHost = other._dataHost;
77 }
78 return *this;
79 }
80
81 };
82
83 // ============================================================================
84 // Metafunctions
85 // ============================================================================
86
87 // ============================================================================
88 // Functions
89 // ============================================================================
90
91 // ----------------------------------------------------------------------------
92 // Function resize()
93 // ----------------------------------------------------------------------------
94
95 template <typename TValue>
96 inline void
resize(DPMatrix_<TValue,SparseDPMatrix> & dpMatrix)97 resize(DPMatrix_<TValue, SparseDPMatrix> & dpMatrix)
98 {
99 typedef DPMatrix_<TValue, SparseDPMatrix> TDPMatrix;
100 typedef typename Size<TDPMatrix>::Type TSize;
101
102 TSize _dimVertical = length(dpMatrix, DPMatrixDimension_::VERTICAL);
103
104 if (_dimVertical >= length(dpMatrix))
105 resize(host(dpMatrix), _dimVertical, Exact());
106 }
107
108 template <typename TValue>
109 inline void
resize(DPMatrix_<TValue,SparseDPMatrix> & dpMatrix,TValue const & fillValue)110 resize(DPMatrix_<TValue, SparseDPMatrix> & dpMatrix,
111 TValue const & fillValue)
112 {
113 typedef DPMatrix_<TValue, SparseDPMatrix> TDPMatrix;
114 typedef typename Size<TDPMatrix>::Type TSize;
115
116 TSize _dimVertical = length(dpMatrix, DPMatrixDimension_::VERTICAL);
117
118 if (_dimVertical > length(dpMatrix))
119 resize(host(dpMatrix), _dimVertical, fillValue, Exact());
120 }
121
122 // ----------------------------------------------------------------------------
123 // Function value()
124 // ----------------------------------------------------------------------------
125
126 template <typename TValue, typename TPositionV, typename TPositionH>
127 inline typename Reference<DPMatrix_<TValue, SparseDPMatrix> >::Type
value(DPMatrix_<TValue,SparseDPMatrix> & dpMatrix,TPositionV const & posV,TPositionH const &)128 value(DPMatrix_<TValue, SparseDPMatrix> & dpMatrix,
129 TPositionV const & posV,
130 TPositionH const &)
131 {
132 return value(dpMatrix, posV);
133 }
134
135 template <typename TValue, typename TPositionV, typename TPositionH>
136 inline typename Reference<DPMatrix_<TValue, SparseDPMatrix> const>::Type
value(DPMatrix_<TValue,SparseDPMatrix> const & dpMatrix,TPositionV const & posV,TPositionH const &)137 value(DPMatrix_<TValue, SparseDPMatrix> const & dpMatrix,
138 TPositionV const & posV,
139 TPositionH const &)
140 {
141 return value(dpMatrix, posV);
142 }
143
144 // ----------------------------------------------------------------------------
145 // Function coordinate()
146 // ----------------------------------------------------------------------------
147
148
149 template <typename TValue, typename TPosition>
150 inline typename Position<DPMatrix_<TValue, SparseDPMatrix> >::Type
coordinate(DPMatrix_<TValue,SparseDPMatrix> const &,TPosition hostPos,typename DPMatrixDimension_::TValue dimension)151 coordinate(DPMatrix_<TValue, SparseDPMatrix> const & /*dpMatrix*/,
152 TPosition hostPos,
153 typename DPMatrixDimension_::TValue dimension)
154 {
155 SEQAN_ASSERT(_checkCorrectDimension(dimension));
156
157 if (dimension == DPMatrixDimension_::VERTICAL)
158 return hostPos;
159
160 return 0u;
161 }
162
163 } // namespace seqan
164
165 #endif // #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_DP_MATRIX_SPARSE_H_
166