SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
minimiser_hash.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
19 
20 namespace seqan3
21 {
23 struct seed : seqan3::detail::strong_type<uint64_t, seed>
24 {
25  using seqan3::detail::strong_type<uint64_t, seed>::strong_type;
26 };
27 
29 struct window_size : seqan3::detail::strong_type<uint32_t, window_size>
30 {
31  using seqan3::detail::strong_type<uint32_t, window_size>::strong_type;
32 };
33 } // namespace seqan3
34 
35 namespace seqan3::detail
36 {
38 struct minimiser_hash_fn
39 {
46  constexpr auto operator()(shape const & shape, window_size const window_size) const
47  {
48  return seqan3::detail::adaptor_from_functor{*this, shape, window_size};
49  }
50 
58  constexpr auto operator()(shape const & shape, window_size const window_size, seed const seed) const
59  {
60  return seqan3::detail::adaptor_from_functor{*this, shape, window_size, seed};
61  }
62 
72  template <std::ranges::range urng_t>
73  constexpr auto operator()(urng_t && urange,
74  shape const & shape,
75  window_size const window_size,
76  seed const seed = seed{0x8F3F73B5CF1C9ADE}) const
77  {
78  static_assert(std::ranges::viewable_range<urng_t>,
79  "The range parameter to views::minimiser_hash cannot be a temporary of a non-view range.");
80  static_assert(std::ranges::forward_range<urng_t>,
81  "The range parameter to views::minimiser_hash must model std::ranges::forward_range.");
82  static_assert(semialphabet<std::ranges::range_reference_t<urng_t>>,
83  "The range parameter to views::minimiser_hash must be over elements of seqan3::semialphabet.");
84 
85  if (shape.size() > window_size.get())
86  throw std::invalid_argument{"The size of the shape cannot be greater than the window size."};
87 
88  auto forward_strand = std::forward<urng_t>(urange) | seqan3::views::kmer_hash(shape)
89  | std::views::transform([seed] (uint64_t i)
90  {return i ^ seed.get();});
91 
92  auto reverse_strand = std::forward<urng_t>(urange) | seqan3::views::complement
93  | std::views::reverse
95  | std::views::transform([seed] (uint64_t i)
96  {return i ^ seed.get();})
97  | std::views::reverse;
98 
99  return seqan3::detail::minimiser_view(forward_strand, reverse_strand, window_size.get() - shape.size() + 1);
100  }
101 };
102 
103 } // namespace seqan3::detail
104 
105 namespace seqan3::views
106 {
107 
181 inline constexpr auto minimiser_hash = detail::minimiser_hash_fn{};
182 
184 
185 } // namespace seqan3::views
minimiser.hpp
Provides seqan3::views::minimiser.
seqan3::views
The SeqAn namespace for views.
Definition: view_iota_simd.hpp:218
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:788
strong_type.hpp
Provides basic data structure for strong types.
complement.hpp
Provides seqan3::views::complement.
seqan3::seed
strong_type for seed.
Definition: minimiser_hash.hpp:24
seqan3::views::complement
auto const complement
A view that converts a range of nucleotides to their complement.
Definition: complement.hpp:69
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
std::invalid_argument
seqan3::window_size
strong_type for the window_size.
Definition: minimiser_hash.hpp:30
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:181
seqan3::pack_traits::transform
seqan3::type_list< trait_t< pack_t >... > transform
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
Definition: traits.hpp:307
semialphabet
The basis for seqan3::alphabet, but requires only rank interface (not char).
kmer_hash.hpp
Provides seqan3::views::kmer_hash.