61 template <
typename structure_alph_type,
typename bpp_type, std::ranges::Range structure_type>
63 void bpp_from_rna_structure(bpp_type & bpp, structure_type
const & structure,
double weight = 1.)
65 if constexpr (!rna_structure_concept<structure_alph_type>)
66 throw parse_error{
"Cannot create base pair probabilities from a structure that is not RNA structure."};
70 bpp.reserve(
size(structure));
72 std::stack<size_t> brackets[max_pseudoknot_depth_v<structure_alph_type>];
74 for (structure_alph_type symbol : structure)
77 uint8_t
const id = pseudoknot_id(symbol).value_or(0);
79 if (symbol.is_pair_open())
81 brackets[id].push(pos);
83 else if (symbol.is_pair_close())
85 if (!brackets[
id].
empty())
87 bpp[pos].emplace(weight, brackets[
id].top());
88 bpp[brackets[id].top()].emplace(weight, pos);
93 throw parse_error{std::string{
"Invalid bracket notation: Unpaired closing bracket at position "}
94 + std::to_string(pos) +
"."};
100 for (uint8_t
id = 0u; id < max_pseudoknot_depth_v<structure_alph_type>; ++id)
102 if (!brackets[
id].
empty())
104 throw parse_error{std::string{
"Invalid bracket notation: Unpaired opening bracket at position "}
105 + std::to_string(brackets[
id].top()) +
"."};
Provides seqan3::rna_structure_concept.
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
Definition: aligned_sequence_concept.hpp:288
::ranges::empty empty
Alias for ranges::empty. Checks whether a range is empty.
Definition: ranges:205
Specifies the requirements of a Range type that knows its size in constant time with the size functio...