Loading...
Searching...
No Matches
minimiser_hash.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 <seqan3/alphabet/views/complement.hpp>
#include <seqan3/core/detail/strong_type.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/search/views/minimiser.hpp>
namespace seqan3
{
struct seed : seqan3::detail::strong_type<uint64_t, seed>
{
using seqan3::detail::strong_type<uint64_t, seed>::strong_type;
};
struct window_size : seqan3::detail::strong_type<uint32_t, window_size>
{
using seqan3::detail::strong_type<uint32_t, window_size>::strong_type;
};
} // namespace seqan3
namespace seqan3::detail
{
struct minimiser_hash_fn
{
constexpr auto operator()(shape const & shape, window_size const window_size) const
{
return seqan3::detail::adaptor_from_functor{*this, shape, window_size};
}
constexpr auto operator()(shape const & shape, window_size const window_size, seed const seed) const
{
return seqan3::detail::adaptor_from_functor{*this, shape, window_size, seed};
}
template <std::ranges::range urng_t>
constexpr auto operator()(urng_t && urange,
shape const & shape,
window_size const window_size,
seed const seed = seqan3::seed{0x8F'3F'73'B5'CF'1C'9A'DE}) const
{
static_assert(std::ranges::viewable_range<urng_t>,
"The range parameter to views::minimiser_hash cannot be a temporary of a non-view range.");
static_assert(std::ranges::forward_range<urng_t>,
"The range parameter to views::minimiser_hash must model std::ranges::forward_range.");
static_assert(semialphabet<std::ranges::range_reference_t<urng_t>>,
"The range parameter to views::minimiser_hash must be over elements of seqan3::semialphabet.");
if (shape.size() > window_size.get())
throw std::invalid_argument{"The size of the shape cannot be greater than the window size."};
auto forward_strand = std::forward<urng_t>(urange) | seqan3::views::kmer_hash(shape)
| std::views::transform(
[seed](uint64_t i)
{
return i ^ seed.get();
});
auto reverse_strand = std::forward<urng_t>(urange) | seqan3::views::complement | std::views::reverse
| seqan3::views::kmer_hash(shape)
| std::views::transform(
[seed](uint64_t i)
{
return i ^ seed.get();
})
| std::views::reverse;
return seqan3::detail::minimiser_view(forward_strand, reverse_strand, window_size.get() - shape.size() + 1);
}
};
} // namespace seqan3::detail
namespace seqan3::views
{
inline constexpr auto minimiser_hash = detail::minimiser_hash_fn{};
} // namespace seqan3::views
complement.hpp
Provides seqan3::views::complement.
std::forward
T forward(T... args)
seqan3::views::minimiser_hash
constexpr auto minimiser_hash
Computes minimisers for a range with a given shape, window size and seed.
Definition minimiser_hash.hpp:190
seqan3::views::complement
auto const complement
A view that converts a range of nucleotides to their complement.
Definition complement.hpp:64
seqan3::views::kmer_hash
constexpr auto kmer_hash
Computes hash values for each position of a range via a given shape.
Definition kmer_hash.hpp:766
kmer_hash.hpp
Provides seqan3::views::kmer_hash.
minimiser.hpp
Provides seqan3::views::minimiser.
seqan3::views
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
strong_type.hpp
Provides basic data structure for strong types.
seqan3::seed
strong_type for seed.
Definition minimiser_hash.hpp:22
seqan3::window_size
strong_type for the window_size.
Definition minimiser_hash.hpp:29
Hide me