yat  0.14.5pre
algorithm.h
1 #ifndef theplu_yat_omic_algorithm
2 #define theplu_yat_omic_algorithm
3 
4 // $Id: algorithm.h 3625 2017-03-06 03:09:59Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 2016, 2017 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 this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
26 
27 #ifdef YAT_HAVE_LIBBAM
28 #include "BamPairIterator.h"
29 #endif
30 #include "DnaComplementer.h"
31 
32 #include <boost/iterator/iterator_concepts.hpp>
33 #include <boost/iterator/iterator_traits.hpp>
34 #include <boost/iterator/reverse_iterator.hpp>
35 #include <boost/concept_check.hpp>
36 
37 #include <algorithm>
38 #include <vector>
39 
40 namespace theplu {
41 namespace yat {
42 namespace omic {
43 
64 #ifdef YAT_HAVE_LIBBAM
65  template<class Iterator, class Visitor>
66  void bam_pair_analyse(Iterator first, Iterator last, Visitor& visitor);
67 #endif
68 
84  template<typename InputIterator, typename OutputIterator>
85  void dna_complement(InputIterator begin, InputIterator end,
86  OutputIterator out);
87 
104  template<typename BidirectionalIterator>
105  void dna_reverse_complement(BidirectionalIterator begin,
106  BidirectionalIterator end);
107 
134  template<typename BidirectionalIterator, typename OutputIterator>
135  void dna_reverse_complement_copy(BidirectionalIterator begin,
136  BidirectionalIterator end,
137  OutputIterator out);
138 
139 
140  // template implementations
141 
142 #ifdef YAT_HAVE_LIBBAM
143  template<class Iterator, class Visitor>
144  void bam_pair_analyse(Iterator first, Iterator last, Visitor& visitor)
145  {
146  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
147  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
148  BamPairIterator<Iterator> iter(first, last);
149  BamPairIterator<Iterator> end(last, last);
150  for (; iter!=end; ++iter)
151  visitor((*iter).first(), (*iter).second());
152  }
153 #endif
154 
155 
156  template<typename InputIterator, typename OutputIterator>
157  void dna_complement(InputIterator begin, InputIterator end,
158  OutputIterator out)
159  {
160  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>));
161  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator>));
162 
163  typedef typename boost::iterator_value<InputIterator>::type value_type;
164  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, char>));
165 
166  using namespace boost_concepts;
167  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, char>));
168  BOOST_CONCEPT_ASSERT((IncrementableIterator<OutputIterator>));
169  std::transform(begin, end, out, DnaComplementer());
170  }
171 
172 
173  template<typename BidirectionalIterator>
174  void dna_reverse_complement(BidirectionalIterator begin,
175  BidirectionalIterator end)
176  {
177  BOOST_CONCEPT_ASSERT((
178  boost::Mutable_BidirectionalIterator<BidirectionalIterator>
179  ));
180  dna_complement(begin, end, begin);
181  std::reverse(begin, end);
182  }
183 
184 
185  template<typename BidirectionalIterator, typename OutputIterator>
186  void dna_reverse_complement_copy(BidirectionalIterator begin,
187  BidirectionalIterator end,
188  OutputIterator out)
189  {
190  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<BidirectionalIterator>));
191 
192  dna_complement(boost::make_reverse_iterator(end),
193  boost::make_reverse_iterator(begin), out);
194  }
195 
196 }}}
197 #endif
void dna_complement(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:157
Functor that calculates genomic complement.
Definition: DnaComplementer.h:30
void dna_reverse_complement(BidirectionalIterator begin, BidirectionalIterator end)
Definition: algorithm.h:174
void dna_reverse_complement_copy(BidirectionalIterator begin, BidirectionalIterator end, OutputIterator out)
Definition: algorithm.h:186

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5