SeqAn3
trim.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <range/v3/view/take_while.hpp>
43 
47 #include <seqan3/std/ranges>
48 
49 namespace seqan3::detail
50 {
51 
57 struct trim_fn
58 {
64  template <typename irng_t>
65  auto operator()(irng_t && irange,
66  underlying_phred_t<value_type_t<std::decay_t<irng_t>>> const threshold) const
68  requires std::ranges::InputRange<irng_t> && quality_concept<value_type_t<std::decay_t<irng_t>>>
70  {
71  return ranges::view::take_while(std::forward<irng_t>(irange), [threshold] (auto && value)
72  {
73  return to_phred(std::forward<decltype(value)>(value)) >= threshold;
74  });
75  }
76 
82  template <typename irng_t>
83  auto operator()(irng_t && irange,
84  std::decay_t<value_type_t<std::decay_t<irng_t>>> const threshold) const
86  requires std::ranges::InputRange<irng_t> && quality_concept<value_type_t<std::decay_t<irng_t>>>
88  {
89  return (*this)(std::forward<irng_t>(irange), to_phred(threshold));
90  }
91 
108  template <typename threshold_t>
109  struct delegate
110  {
112  threshold_t const threshold;
114  trim_fn const & parent;
115 
117  template <typename irng_t>
118  auto operator()(irng_t && irange) const
119  {
120  return parent(std::forward<irng_t>(irange), threshold);
121  }
122  };
123 
132  template <typename threshold_t>
133  delegate<threshold_t> operator()(threshold_t const threshold) const
135  requires std::is_integral_v<std::decay_t<threshold_t>> || quality_concept<std::decay_t<threshold_t>>
137  {
138  return delegate<threshold_t>{threshold, *this};
139  // this doesn't work here, see seqan3::detail::trim_fn::delegate.
140  //return std::bind(trim_fn(), std::placeholders::_1, threshold);
141  }
142 
149  template <typename irng_t,
150  typename threshold_t>
152  requires std::ranges::InputRange<irng_t> && quality_concept<value_type_t<std::decay_t<irng_t>>> &&
153  (std::is_same_v<std::decay_t<threshold_t>,
154  std::decay_t<value_type_t<std::decay_t<irng_t>>>> ||
155  std::is_convertible_v<std::decay_t<threshold_t>,
156  underlying_phred_t<std::decay_t<value_type_t<std::decay_t<irng_t>>>>>)
158  friend auto operator|(irng_t && irange,
159  seqan3::detail::trim_fn::delegate<threshold_t> const & bound_view)
160  {
161  return bound_view(std::forward<irng_t>(irange));
162  }
163 };
164 
165 } // namespace seqan3::detail
166 
167 namespace seqan3::view
168 {
169 
219 inline constexpr auto trim = deep{seqan3::detail::trim_fn{}};
220 
222 
223 } // namespace seqan3::view
Contains quality alphabet compositions.
Specifies requirements of a Range type for which begin returns a type that models std::InputIterator...
constexpr underlying_phred_t< alphabet_type > to_phred(alphabet_type const &chr)
The public getter function for the phred representation of a score.
Definition: concept.hpp:127
Provides various metafunctions.
typename underlying_phred< alphabet_type >::type underlying_phred_t
The internal phred type.
Definition: concept.hpp:88
Provides seqan3::view::deep.
Adaptations of concepts from the Ranges TS.
The SeqAn3 namespace for views.
constexpr auto trim
A view that does quality-threshold trimming on a range of seqan3::quality_concept.
Definition: trim.hpp:219
Definition: aligned_sequence_concept.hpp:288
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view...
Definition: deep.hpp:129
typename value_type< t >::type value_type_t
Type metafunction shortcut for seqan3::value_type.
Definition: pre.hpp:72