SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
trim_quality.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <ranges>
13
17
18namespace seqan3::detail
19{
20
26struct trim_fn
27{
29 template <typename threshold_t>
30 constexpr auto operator()(threshold_t const threshold) const
31 {
32 static_assert(quality_alphabet<threshold_t> || std::integral<threshold_t>,
33 "The threshold must either be a quality alphabet or an integral type "
34 "in which case it is compared with the underlying Phred score type.");
35
36 return adaptor_from_functor{*this, threshold};
37 }
38
44 template <std::ranges::input_range irng_t, typename threshold_t>
45 constexpr auto operator()(irng_t && irange, threshold_t const threshold) const
46 {
48 "views::trim_quality can only operate on ranges over seqan3::quality_alphabet.");
49 static_assert(
50 std::same_as<std::remove_cvref_t<threshold_t>, std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>
51 || std::integral<std::remove_cvref_t<threshold_t>>,
52 "The threshold must either be a letter of the underlying alphabet or an integral type "
53 "in which case it is compared with the underlying Phred score type.");
54
55 return detail::take_until(
56 std::forward<irng_t>(irange),
57 [threshold](auto const value)
58 {
59 if constexpr (std::same_as<std::remove_cvref_t<threshold_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
75namespace seqan3::views
76{
126inline constexpr auto trim_quality = deep{seqan3::detail::trim_fn{}};
127
128} // namespace seqan3::views
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition deep.hpp:101
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:97
constexpr auto trim_quality
A view that does quality-threshold trimming on a range of seqan3::quality_alphabet.
Definition trim_quality.hpp:126
A concept that indicates whether an alphabet represents quality scores.
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
Provides quality alphabet composites.
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Hide me