1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2018, 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, typename THost>
53 class DPMatrix_<TValue, SparseDPMatrix, THost>
54 {
55 public:
56 
57     typedef typename Member<DPMatrix_, DPMatrixMember>::Type TMatrix;
58 
59     Holder<TMatrix>   data_host;  // The host containing the actual matrix.
60 
DPMatrix_()61     DPMatrix_() :
62         data_host()
63     {
64         create(data_host);
65     }
66 };
67 
68 // ============================================================================
69 // Metafunctions
70 // ============================================================================
71 
72 // ============================================================================
73 // Functions
74 // ============================================================================
75 
76 // ----------------------------------------------------------------------------
77 // Function resize()
78 // ----------------------------------------------------------------------------
79 
80 template <typename TValue, typename THost>
81 inline void
resize(DPMatrix_<TValue,SparseDPMatrix,THost> & dpMatrix)82 resize(DPMatrix_<TValue, SparseDPMatrix, THost> & dpMatrix)
83 {
84     typedef DPMatrix_<TValue, SparseDPMatrix, THost> TDPMatrix;
85     typedef typename Size<TDPMatrix>::Type TSize;
86 
87     TSize _dimVertical = length(dpMatrix, DPMatrixDimension_::VERTICAL);
88 
89     if (_dimVertical >= length(dpMatrix))
90         resize(host(dpMatrix), _dimVertical, Exact());
91 }
92 
93 template <typename TValue, typename THost>
94 inline void
resize(DPMatrix_<TValue,SparseDPMatrix,THost> & dpMatrix,TValue const & fillValue)95 resize(DPMatrix_<TValue, SparseDPMatrix, THost> & dpMatrix,
96        TValue const & fillValue)
97 {
98     typedef DPMatrix_<TValue, SparseDPMatrix, THost> TDPMatrix;
99     typedef typename Size<TDPMatrix>::Type TSize;
100 
101     TSize _dimVertical = length(dpMatrix, DPMatrixDimension_::VERTICAL);
102 
103     if (_dimVertical > length(dpMatrix))
104         resize(host(dpMatrix), _dimVertical, fillValue, Exact());
105 }
106 
107 // ----------------------------------------------------------------------------
108 // Function value()
109 // ----------------------------------------------------------------------------
110 
111 template <typename TValue, typename THost, typename TPositionV, typename TPositionH>
112 inline typename Reference<DPMatrix_<TValue, SparseDPMatrix, THost> >::Type
value(DPMatrix_<TValue,SparseDPMatrix,THost> & dpMatrix,TPositionV const & posV,TPositionH const &)113 value(DPMatrix_<TValue, SparseDPMatrix, THost> & dpMatrix,
114       TPositionV const & posV,
115       TPositionH const &)
116 {
117     return value(dpMatrix, posV);
118 }
119 
120 template <typename TValue, typename THost, typename TPositionV, typename TPositionH>
121 inline typename Reference<DPMatrix_<TValue, SparseDPMatrix, THost> const>::Type
value(DPMatrix_<TValue,SparseDPMatrix,THost> const & dpMatrix,TPositionV const & posV,TPositionH const &)122 value(DPMatrix_<TValue, SparseDPMatrix, THost> const & dpMatrix,
123       TPositionV const & posV,
124       TPositionH const &)
125 {
126     return value(dpMatrix, posV);
127 }
128 
129 // ----------------------------------------------------------------------------
130 // Function coordinate()
131 // ----------------------------------------------------------------------------
132 
133 
134 template <typename TValue, typename THost, typename TPosition>
135 inline typename Position<DPMatrix_<TValue, SparseDPMatrix, THost> >::Type
coordinate(DPMatrix_<TValue,SparseDPMatrix,THost> const &,TPosition hostPos,typename DPMatrixDimension_::TValue dimension)136 coordinate(DPMatrix_<TValue, SparseDPMatrix, THost> const & /*dpMatrix*/,
137            TPosition hostPos,
138            typename DPMatrixDimension_::TValue dimension)
139 {
140     SEQAN_ASSERT(_checkCorrectDimension(dimension));
141 
142     if (dimension == DPMatrixDimension_::VERTICAL)
143         return hostPos;
144 
145     return 0u;
146 }
147 
148 }  // namespace seqan
149 
150 #endif  // #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_DP_MATRIX_SPARSE_H_
151