BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
trim_quality.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <ranges>
17
20
21namespace bio::ranges::detail
22{
23
29struct trim_fn
30{
32 template <typename threshold_t>
33 constexpr auto operator()(threshold_t const threshold) const
34 {
35 static_assert(alphabet::quality<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 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(alphabet::quality<std::ranges::range_reference_t<irng_t>>,
51 "views::trim_quality can only operate on ranges over bio::alphabet::quality.");
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 type.");
57
58 return std::views::take_while(
59 std::forward<irng_t>(irange),
60 [threshold](auto const value)
61 {
62 if constexpr (std::same_as<std::remove_cvref_t<threshold_t>,
64 {
65 return alphabet::to_phred(value) >= alphabet::to_phred(threshold);
66 }
67 else
68 {
69 using c_t = std::common_type_t<decltype(alphabet::to_phred(value)), threshold_t>;
70 return static_cast<c_t>(alphabet::to_phred(value)) >= static_cast<c_t>(threshold);
71 }
72 });
73 }
74};
75
76} // namespace bio::ranges::detail
77
78namespace bio::ranges::views
79{
80
132inline constexpr auto trim_quality = deep{detail::trim_fn{}};
133
135
136} // namespace bio::ranges::views
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:104
Provides bio::views::deep.
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:65
constexpr auto trim_quality
A view that does quality-threshold trimming on a range of bio::alphabet::quality.
Definition: trim_quality.hpp:132
The BioC++ namespace for views.
Provides quality alphabet composites.