SeqAn3
3.4.0
The Modern C++ library for sequence analysis.
Toggle main menu visibility
Loading...
Searching...
No Matches
io/structure_file/detail.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3
// SPDX-License-Identifier: BSD-3-Clause
4
9
10
#pragma once
11
12
#include <
map
>
13
#include <ranges>
14
#include <
stack
>
15
16
#include <
seqan3/alphabet/structure/concept.hpp
>
17
#include <
seqan3/io/exception.hpp
>
18
19
namespace
seqan3::detail
20
{
32
template
<
typename
structure_alph_type,
typename
bpp_type, std::ranges::range structure_type>
33
inline
void
bpp_from_rna_structure(bpp_type &
bpp
, structure_type
const
&
structure
,
double
weight = 1.)
34
{
35
if
constexpr
(!rna_structure_alphabet<structure_alph_type>)
36
throw
parse_error{
"Cannot create base pair probabilities from a structure that is not RNA structure."
};
37
38
bpp
.clear();
39
if
constexpr
(std::ranges::sized_range<structure_type>)
40
bpp
.reserve(
size
(
structure
));
41
42
std::stack<size_t> brackets[
max_pseudoknot_depth<structure_alph_type>
];
43
size_t
pos = 0ul;
44
for
(structure_alph_type symbol :
structure
)
45
{
46
bpp
.push_back({});
47
uint8_t
const
id
=
pseudoknot_id
(symbol).value_or(0);
48
49
if
(symbol.is_pair_open())
50
{
51
brackets[
id
].
push
(pos);
52
}
53
else
if
(symbol.is_pair_close())
54
{
55
if
(!brackets[
id
].
empty
())
56
{
57
bpp
[pos].emplace(weight, brackets[
id
].top());
58
bpp
[brackets[
id
].
top
()].emplace(weight, pos);
59
brackets[
id
].
pop
();
60
}
61
else
62
{
63
throw
parse_error{std::string{
"Invalid bracket notation: Unpaired closing bracket at position "
}
64
+
std::to_string
(pos) +
"."
};
65
};
66
}
67
// no actions for unpaired
68
++pos;
69
}
70
for
(uint8_t
id
= 0u;
id < max_pseudoknot_depth<structure_alph_type>
; ++
id
)
71
{
72
if
(!brackets[
id
].
empty
())
73
{
74
throw
parse_error{std::string{
"Invalid bracket notation: Unpaired opening bracket at position "
}
75
+
std::to_string
(brackets[
id
].top()) +
"."
};
76
}
77
}
78
}
79
80
}
// namespace seqan3::detail
concept.hpp
Provides seqan3::rna_structure_alphabet.
std::empty
T empty(T... args)
seqan3::pseudoknot_id
constexpr auto pseudoknot_id
Retrieve an id for the level of a pseudoknotted interaction (also known as 'page number').
Definition
alphabet/structure/concept.hpp:454
seqan3::max_pseudoknot_depth
constexpr auto max_pseudoknot_depth
A type trait that holds the ability of the structure alphabet to represent pseudoknots,...
Definition
alphabet/structure/concept.hpp:371
seqan3::field::structure
@ structure
Fixed interactions, usually a string of structure alphabet characters.
Definition
record.hpp:70
seqan3::field::bpp
@ bpp
Base pair probability matrix of interactions, usually a matrix of float numbers.
Definition
record.hpp:69
seqan3::field::id
@ id
The identifier, usually a string.
Definition
record.hpp:63
seqan3::pack_traits::size
constexpr size_t size
The size of a type pack.
Definition
type_pack/traits.hpp:143
exception.hpp
Provides exceptions used in the I/O module.
map
std::stack::pop
T pop(T... args)
std::stack::push
T push(T... args)
stack
std::to_string
T to_string(T... args)
std::stack::top
T top(T... args)
Hide me
Version:
seqan3
io
structure_file
detail.hpp
Generated on
for SeqAn3 by
1.17.0