Loading...
Searching...
No Matches
alignment_result.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 <concepts>
#include <optional>
#include <seqan3/core/configuration/configuration.hpp>
#include <seqan3/core/debug_stream/debug_stream_type.hpp>
#include <seqan3/core/detail/template_inspection.hpp>
namespace seqan3::detail
{
// forward declaration for friend declaration in alignment_result.
template <typename configuration_t>
requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
class policy_alignment_result_builder;
template <typename sequence1_id_t,
typename sequence2_id_t,
typename score_t,
typename end_positions_t = std::nullopt_t *,
typename begin_positions_t = std::nullopt_t *,
typename alignment_t = std::nullopt_t *,
typename score_debug_matrix_t = std::nullopt_t *,
typename trace_debug_matrix_t = std::nullopt_t *>
struct alignment_result_value_type
{
sequence1_id_t sequence1_id{};
sequence2_id_t sequence2_id{};
score_t score{};
end_positions_t end_positions{};
begin_positions_t begin_positions{};
alignment_t alignment{};
score_debug_matrix_t score_debug_matrix{};
trace_debug_matrix_t trace_debug_matrix{};
};
alignment_result_value_type() -> alignment_result_value_type<std::nullopt_t *, std::nullopt_t *, std::nullopt_t *>;
template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
alignment_result_value_type(sequence1_id_t,
sequence2_id_t,
score_t) -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t>;
template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
-> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t>;
template <typename sequence1_id_t,
typename sequence2_id_t,
typename score_t,
typename end_positions_t,
typename begin_positions_t>
alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
-> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t>;
template <typename sequence1_id_t,
typename sequence2_id_t,
typename score_t,
typename end_positions_t,
typename begin_positions_t,
typename alignment_t>
alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
-> alignment_result_value_type<sequence1_id_t,
sequence2_id_t,
score_t,
end_positions_t,
begin_positions_t,
alignment_t>;
template <typename result_t>
struct alignment_result_value_type_accessor;
} // namespace seqan3::detail
namespace seqan3
{
template <typename alignment_result_value_t>
requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
class alignment_result
{
private:
alignment_result_value_t data{};
using sequence1_id_t = decltype(data.sequence1_id);
using sequence2_id_t = decltype(data.sequence2_id);
using score_t = decltype(data.score);
using end_positions_t = decltype(data.end_positions);
using begin_positions_t = decltype(data.begin_positions);
using alignment_t = decltype(data.alignment);
template <typename configuration_t>
requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
friend class detail::policy_alignment_result_builder;
template <typename>
friend struct alignment_result_printer;
public:
alignment_result(alignment_result_value_t value) : data(std::move(value))
{}
alignment_result() = default;
alignment_result(alignment_result const &) = default;
alignment_result(alignment_result &&) = default;
alignment_result & operator=(alignment_result const &) = default;
alignment_result & operator=(alignment_result &&) = default;
~alignment_result() = default;
constexpr sequence1_id_t sequence1_id() const noexcept
{
static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
"Trying to access the id of the first sequence, although it was not requested in the"
" alignment configuration.");
return data.sequence1_id;
}
constexpr sequence2_id_t sequence2_id() const noexcept
{
static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
"Trying to access the id of the second sequence, although it was not requested in the"
" alignment configuration.");
return data.sequence2_id;
}
constexpr score_t score() const noexcept
{
static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
"Trying to access the score, although it was not requested in the alignment configuration.");
return data.score;
}
constexpr auto sequence1_end_position() const noexcept
{
static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
"Trying to access the end position of the first sequence, although it was not requested in the"
" alignment configuration.");
return data.end_positions.first;
}
constexpr auto sequence2_end_position() const noexcept
{
static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
"Trying to access the end position of the second sequence, although it was not requested in the"
" alignment configuration.");
return data.end_positions.second;
}
constexpr auto sequence1_begin_position() const noexcept
{
static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
"Trying to access the begin position of the first sequence, although it was not requested in the"
" alignment configuration.");
return data.begin_positions.first;
}
constexpr auto sequence2_begin_position() const noexcept
{
static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
"Trying to access the begin position of the second sequence, although it was not requested in the"
" alignment configuration.");
return data.begin_positions.second;
}
constexpr alignment_t const & alignment() const noexcept
{
static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
"Trying to access the alignment, although it was not requested in the alignment configuration.");
return data.alignment;
}
constexpr auto const & score_matrix() const noexcept
{
static_assert(
!std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
"Trying to access the score matrix, although it was not requested in the alignment configuration.");
return data.score_debug_matrix;
}
constexpr auto const & trace_matrix() const noexcept
{
static_assert(
!std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
"Trying to access the trace matrix, although it was not requested in the alignment configuration.");
return data.trace_debug_matrix;
}
};
} // namespace seqan3
namespace seqan3::detail
{
template <typename result_value_t>
struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
{
using type = result_value_t;
};
} // namespace seqan3::detail
namespace seqan3
{
template <typename result_value_t>
struct alignment_result_printer<alignment_result<result_value_t>>
{
template <typename stream_t, typename arg_t>
constexpr void operator()(stream_t & stream, arg_t && arg) const noexcept
{
using disabled_t = std::nullopt_t *;
using result_t = std::remove_cvref_t<arg_t>;
constexpr bool has_sequence1_id = !std::is_same_v<typename result_t::sequence1_id_t, disabled_t>;
constexpr bool has_sequence2_id = !std::is_same_v<typename result_t::sequence2_id_t, disabled_t>;
constexpr bool has_score = !std::is_same_v<typename result_t::score_t, disabled_t>;
constexpr bool has_end_positions = !std::is_same_v<typename result_t::end_positions_t, disabled_t>;
constexpr bool has_begin_positions = !std::is_same_v<typename result_t::begin_positions_t, disabled_t>;
constexpr bool has_alignment = !std::is_same_v<typename result_t::alignment_t, disabled_t>;
bool prepend_comma = false;
auto append_to_stream = [&](auto &&... args)
{
((stream << (prepend_comma ? std::string{", "} : std::string{}))
<< ... << std::forward<decltype(args)>(args));
prepend_comma = true;
};
stream << '{';
if constexpr (has_sequence1_id)
append_to_stream("sequence1 id: ", arg.sequence1_id());
if constexpr (has_sequence2_id)
append_to_stream("sequence2 id: ", arg.sequence2_id());
if constexpr (has_score)
append_to_stream("score: ", arg.score());
if constexpr (has_begin_positions)
append_to_stream("begin: (", arg.sequence1_begin_position(), ",", arg.sequence2_begin_position(), ")");
if constexpr (has_end_positions)
append_to_stream("end: (", arg.sequence1_end_position(), ",", arg.sequence2_end_position(), ")");
if constexpr (has_alignment)
append_to_stream("\nalignment:\n", arg.alignment());
stream << '}';
}
};
} // namespace seqan3
std::string
seqan3::alignment_result
Stores the alignment results and gives access to score, alignment and the front and end positions.
Definition alignment_result.hpp:147
seqan3::alignment_result::sequence2_id
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition alignment_result.hpp:219
seqan3::alignment_result::operator=
alignment_result & operator=(alignment_result &&)=default
Defaulted.
seqan3::alignment_result::operator=
alignment_result & operator=(alignment_result const &)=default
Defaulted.
seqan3::alignment_result::sequence1_id
constexpr sequence1_id_t sequence1_id() const noexcept
Returns the alignment identifier of the first sequence.
Definition alignment_result.hpp:208
seqan3::alignment_result::sequence2_end_position
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition alignment_result.hpp:273
seqan3::alignment_result::sequence1_begin_position
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition alignment_result.hpp:297
seqan3::alignment_result::alignment_result
alignment_result(alignment_result const &)=default
Defaulted.
seqan3::alignment_result::alignment
constexpr alignment_t const & alignment() const noexcept
Returns the actual alignment, i.e. the base pair matching.
Definition alignment_result.hpp:335
seqan3::alignment_result::sequence2_begin_position
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition alignment_result.hpp:321
seqan3::alignment_result::~alignment_result
~alignment_result()=default
Defaulted.
seqan3::alignment_result::score
constexpr score_t score() const noexcept
Returns the alignment score.
Definition alignment_result.hpp:230
seqan3::alignment_result::sequence1_end_position
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition alignment_result.hpp:251
seqan3::alignment_result::alignment_result
alignment_result()=default
Defaulted.
seqan3::alignment_result::alignment_result
alignment_result(alignment_result &&)=default
Defaulted.
configuration.hpp
Provides seqan3::configuration and utility functions.
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
std::forward
T forward(T... args)
std::is_same_v
T is_same_v
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
std::nullopt_t
optional
seqan3::alignment_result_printer< alignment_result< result_value_t > >::operator()
constexpr void operator()(stream_t &stream, arg_t &&arg) const noexcept
Prints the formatted output of the alignment result to the stream.
Definition alignment_result.hpp:426
seqan3::alignment_result_printer
Definition default_printer.hpp:30
template_inspection.hpp
Provides type traits for working with templates.
Hide me