SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
trim_quality.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 
15 #include <ranges>
16 
20 
21 namespace seqan3::detail
22 {
23 
29 struct trim_fn
30 {
32  template <typename threshold_t>
33  constexpr auto operator()(threshold_t const threshold) const
34  {
35  static_assert(quality_alphabet<threshold_t> || std::integral<threshold_t>,
36  "The threshold must either be a quality alphabet or an integral type "
37  "in which case it is compared with the underlying Phred score type.");
38 
39  return adaptor_from_functor{*this, threshold};
40  }
41 
47  template <std::ranges::input_range irng_t, typename threshold_t>
48  constexpr auto operator()(irng_t && irange, threshold_t const threshold) const
49  {
50  static_assert(quality_alphabet<std::remove_reference_t<std::ranges::range_reference_t<irng_t>>>,
51  "views::trim_quality can only operate on ranges over seqan3::quality_alphabet.");
52  static_assert(
53  std::same_as<std::remove_cvref_t<threshold_t>, std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>
54  || std::integral<std::remove_cvref_t<threshold_t>>,
55  "The threshold must either be a letter of the underlying alphabet or an integral type "
56  "in which case it is compared with the underlying Phred score type.");
57 
58  return detail::take_until(
59  std::forward<irng_t>(irange),
60  [threshold](auto const value)
61  {
62  if constexpr (std::same_as<std::remove_cvref_t<threshold_t>,
63  std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>)
64  {
65  return to_phred(value) < to_phred(threshold);
66  }
67  else
68  {
69  using c_t = std::common_type_t<decltype(to_phred(value)), threshold_t>;
70  return static_cast<c_t>(to_phred(value)) < static_cast<c_t>(threshold);
71  }
72  });
73  }
74 };
75 
76 } // namespace seqan3::detail
77 
78 namespace seqan3::views
79 {
129 inline constexpr auto trim_quality = deep{seqan3::detail::trim_fn{}};
130 
131 } // namespace seqan3::views
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:104
Provides seqan3::views::deep.
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition: alphabet/quality/concept.hpp:100
constexpr auto trim_quality
A view that does quality-threshold trimming on a range of seqan3::quality_alphabet.
Definition: trim_quality.hpp:129
A concept that indicates whether an alphabet represents quality scores.
The SeqAn namespace for views.
Definition: char_strictly_to.hpp:22
Provides quality alphabet composites.
The <ranges> header from C++20's standard library.
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.