31namespace bio::ranges::detail
36struct translate_single_fn
44 return detail::adaptor_from_functor{*
this, tf};
52 template <std::ranges::range urng_t>
55 static_assert(std::ranges::viewable_range<urng_t>,
56 "The range parameter to views::translate_single must be viewable.");
57 static_assert(std::ranges::sized_range<urng_t>,
58 "The range parameter to views::translate_single must model std::ranges::sized_range.");
59 static_assert(std::ranges::random_access_range<urng_t>,
60 "The range parameter to views::translate_single must model std::ranges::random_access_range.");
61 static_assert(alphabet::nucleotide<std::ranges::range_reference_t<urng_t>>,
62 "The range parameter to views::translate_single must be over elements of "
63 "bio::alphabet::alphabet::nucleotide.");
66 if (
size_t const num_frames =
std::popcount(
static_cast<uint8_t
>(tf));
71 "Error: Invalid type of frame. Choose one out of FWD_FRAME_0, "
72 "REV_FRAME_0, FWD_FRAME_1, REV_FRAME_1, FWD_FRAME_2 and "
77 size_t const old_size = std::ranges::size(urange);
78 size_t const new_size = comp_new_size(old_size, tf);
80 return detail::view_transform_by_pos{
81 std::forward<urng_t>(urange),
82 trans_fn{.old_size = old_size, .new_size = new_size, .tf = tf},
88 template <std::ranges::range urng_t>
89 constexpr friend auto operator|(urng_t && urange, translate_single_fn
const & me)
91 return me(std::forward<urng_t>(urange));
107 return (std::max<size_t>(old_size, 1) - 1) / 3;
111 return (std::max<size_t>(old_size, 2) - 2) / 3;
131 auto operator()(
auto && urange2,
size_t const n)
const
133 assert(n < new_size);
Provides bio::alphabet::aa27, container aliases and string literals.
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:104
#define BIOCPP_UNREACHABLE
A macro to mark unreachable code.
Definition: core.hpp:186
Provides bio::views::deep.
Provides bio::alphabet::dna5, container aliases and string literals.
constexpr aa27 translate_triplet(nucl_type const &n1, nucl_type const &n2, nucl_type const &n3) noexcept
Translate one nucleotide triplet into single amino acid (single nucleotide interface).
Definition: translation.hpp:54
translation_frames
Specialisation values for single and multiple translation frames.
Definition: translation.hpp:85
@ REV_FRAME_0
The first reverse frame starting at position 0.
@ REV_FRAME_1
The second reverse frame starting at position 1.
@ FWD_FRAME_2
The third forward frame starting at position 2.
@ FWD_FRAME_1
The second forward frame starting at position 1.
@ REV_FRAME_2
The third reverse frame starting at position 2.
@ FWD_FRAME_0
The first forward frame starting at position 0.
constexpr auto complement
Return the complement of a nucleotide object.
Definition: concept.hpp:68
constexpr auto translate_single
A view that translates nucleotide into aminoacid alphabet for one of the six frames.
Definition: translate_single.hpp:225
constexpr translation_frames operator|(translation_frames lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:111
The BioC++ namespace for views.
Provides functions for translating a triplet of nucleotides into an amino acid.