Loading...
Searching...
No Matches
trim_quality.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <ranges>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/io/views/detail/take_until_view.hpp>
#include <seqan3/utility/views/deep.hpp>
namespace seqan3::detail
{
struct trim_fn
{
template <typename threshold_t>
constexpr auto operator()(threshold_t const threshold) const
{
static_assert(quality_alphabet<threshold_t> || std::integral<threshold_t>,
"The threshold must either be a quality alphabet or an integral type "
"in which case it is compared with the underlying Phred score type.");
return adaptor_from_functor{*this, threshold};
}
template <std::ranges::input_range irng_t, typename threshold_t>
constexpr auto operator()(irng_t && irange, threshold_t const threshold) const
{
static_assert(quality_alphabet<std::remove_reference_t<std::ranges::range_reference_t<irng_t>>>,
"views::trim_quality can only operate on ranges over seqan3::quality_alphabet.");
static_assert(
std::same_as<std::remove_cvref_t<threshold_t>, std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>
|| std::integral<std::remove_cvref_t<threshold_t>>,
"The threshold must either be a letter of the underlying alphabet or an integral type "
"in which case it is compared with the underlying Phred score type.");
return detail::take_until(
std::forward<irng_t>(irange),
[threshold](auto const value)
{
if constexpr (std::same_as<std::remove_cvref_t<threshold_t>,
std::remove_cvref_t<std::ranges::range_reference_t<irng_t>>>)
{
return to_phred(value) < to_phred(threshold);
}
else
{
using c_t = std::common_type_t<decltype(to_phred(value)), threshold_t>;
return static_cast<c_t>(to_phred(value)) < static_cast<c_t>(threshold);
}
});
}
};
} // namespace seqan3::detail
namespace seqan3::views
{
inline constexpr auto trim_quality = deep{seqan3::detail::trim_fn{}};
} // namespace seqan3::views
seqan3::views::deep
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition deep.hpp:101
deep.hpp
Provides seqan3::views::deep.
std::forward
T forward(T... args)
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:126
seqan3::views
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
seqan3::to_phred
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition alphabet/quality/concept.hpp:97
qualified.hpp
Provides quality alphabet composites.
take_until_view.hpp
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Hide me