SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
trim_quality.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
18 #include <seqan3/std/ranges>
19 
20 namespace seqan3::detail
21 {
22 
28 struct trim_fn
29 {
31  template <typename threshold_t>
32  constexpr auto operator()(threshold_t const threshold) const
33  {
34  static_assert(quality_alphabet<threshold_t> || std::integral<threshold_t>,
35  "The threshold must either be a quality alphabet or an integral type "
36  "in which case it is compared with the underlying phred type.");
37 
38  return adaptor_from_functor{*this, threshold};
39  }
40 
46  template <std::ranges::input_range irng_t, typename threshold_t>
47  constexpr auto operator()(irng_t && irange, threshold_t const threshold) const
48  {
49  static_assert(quality_alphabet<std::remove_reference_t<std::ranges::range_reference_t<irng_t>>>,
50  "views::trim_quality can only operate on ranges over seqan3::quality_alphabet.");
51  static_assert(std::same_as<std::remove_cvref_t<threshold_t>,
52  std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>> ||
53  std::integral<std::remove_cvref_t<threshold_t>>,
54  "The threshold must either be a letter of the underlying alphabet or an integral type "
55  "in which case it is compared with the underlying phred type.");
56 
57  return views::take_until(std::forward<irng_t>(irange), [threshold] (auto const value)
58  {
59  if constexpr (std::same_as<std::remove_cvref_t<threshold_t>,
60  std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>)
61  {
62  return to_phred(value) < to_phred(threshold);
63  }
64  else
65  {
66  using c_t = std::common_type_t<decltype(to_phred(value)), threshold_t>;
67  return static_cast<c_t>(to_phred(value)) < static_cast<c_t>(threshold);
68  }
69  });
70  }
71 };
72 
73 } // namespace seqan3::detail
74 
75 namespace seqan3::views
76 {
77 
129 inline constexpr auto trim_quality = deep{seqan3::detail::trim_fn{}};
130 
132 
133 } // namespace seqan3::views
qualified.hpp
Provides quality alphabet composites.
seqan3::views
The SeqAn namespace for views.
Definition: view_iota_simd.hpp:218
take_until.hpp
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
quality_alphabet
A concept that indicates whether an alphabet represents quality scores.
std::common_type_t
seqan3::views::deep
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:102
seqan3::views::take_until
constexpr auto take_until
A view adaptor that returns elements from the underlying range until the functor evaluates to true (o...
Definition: take_until.hpp:610
seqan3::to_phred
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:89
ranges
Adaptations of concepts from the Ranges TS.
deep.hpp
Provides seqan3::views::deep.
std::remove_reference_t
std::remove_cvref_t
seqan3::views::trim_quality
constexpr auto trim_quality
A view that does quality-threshold trimming on a range of seqan3::quality_alphabet.
Definition: trim_quality.hpp:129