yat  0.21pre
SmithWaterman.h
1 #ifndef _theplu_yat_utility_smith_waterman
2 #define _theplu_yat_utility_smith_waterman
3 
4 // $Id: SmithWaterman.h 4207 2022-08-26 04:36:28Z peter $
5 
6 /*
7  Copyright (C) 2014, 2015, 2016, 2022 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "Aligner.h"
26 #include "Matrix.h"
27 
28 #include <boost/concept_check.hpp>
29 
30 #include <cstddef> // size_t
31 
32 namespace theplu {
33 namespace yat {
34 namespace utility {
35 
40  {
41  public:
47  explicit SmithWaterman(double gap=0, double open_gap=0);
48 
65  SmithWaterman(double vertical_gap, double open_vertical_gap,
66  double horizon_gap, double open_horizon_gap);
67 
76  const Aligner::Cigar& cigar(void) const;
77 
82  size_t position(void) const;
83 
87  const Matrix& score(void) const;
88 
97  double operator()(const MatrixBase& dot);
98 
110  template<typename RandomAccessIterator1, typename RandomAccessIterator2>
111  double operator()(RandomAccessIterator1 reference_begin,
112  RandomAccessIterator1 reference_end,
113  RandomAccessIterator2 query_begin,
114  RandomAccessIterator2 query_end,
115  double mismatch=0);
116 
117  private:
118  Aligner aligner_;
119  Aligner::Cigar cigar_;
120  size_t position_;
121  Matrix score_;
122  };
123 
124  // template implementaion
125 
126  template<typename RandomAccessIterator1, typename RandomAccessIterator2>
127  double SmithWaterman::operator()(RandomAccessIterator1 reference_begin,
128  RandomAccessIterator1 reference_end,
129  RandomAccessIterator2 query_begin,
130  RandomAccessIterator2 query_end,
131  double mismatch)
132  {
133  using boost_concepts::ReadableIterator;
134  using boost_concepts::RandomAccessTraversal;
135  BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIterator1>));
136  BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIterator1>));
137  BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIterator2>));
138  BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIterator2>));
139  Matrix dot(reference_end-reference_begin, query_end-query_begin, -mismatch);
140  for (size_t i=0; i<dot.rows(); ++i)
141  for (size_t j=0; j<dot.columns(); ++j)
142  if (reference_begin[i] == query_begin[j])
143  dot(i, j) = 1;
144  return this->operator()(dot);
145  }
146 
147 }}} // of namespace utility, yat, and theplu
148 
149 #endif
Definition: MatrixBase.h:54
const Matrix & score(void) const
The Department of Theoretical Physics namespace as we define it.
double operator()(const MatrixBase &dot)
const Aligner::Cigar & cigar(void) const
SmithWaterman(double gap=0, double open_gap=0)
Constructor.
Aligning two sequences.
Definition: Aligner.h:58
Definition: SmithWaterman.h:39
Interface to GSL matrix.
Definition: Matrix.h:104
Compact Idiosyncratic Gapped Alignment Report.
Definition: Aligner.h:184

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14