SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
bi_fm_index.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 
15 #include <seqan3/std/filesystem>
16 #include <seqan3/std/ranges>
17 #include <utility>
18 
23 
24 namespace seqan3
25 {
26 
61 template <semialphabet alphabet_t,
62  text_layout text_layout_mode_,
63  detail::sdsl_index sdsl_index_type_ = default_sdsl_index_type>
65 {
66 private:
71  using sdsl_index_type = sdsl_index_type_;
72 
74  using rev_sdsl_index_type = sdsl::csa_wt<sdsl_wt_index_type::wavelet_tree_type, // Wavelet tree type
75  10'000'000, // Sampling rate of the suffix array
76  10'000'000, // Sampling rate of the inverse suffix array
77  sdsl::sa_order_sa_sampling<>, // Text or SA based sampling for SA
78  sdsl::isa_sampling<>, // Text or ISA based sampling for ISA
79  sdsl_wt_index_type::alphabet_type>; // How to represent the alphabet
80 
84  using sdsl_char_type = typename sdsl_index_type::alphabet_type::char_type;
85 
87  using sdsl_sigma_type = typename sdsl_index_type::alphabet_type::sigma_type;
88 
91 
95 
98 
101 
121  template <std::ranges::range text_t>
122  void construct(text_t && text)
123  {
124  detail::fm_index_validator::validate<alphabet_t, text_layout_mode_>(text);
125 
126  fwd_fm = fm_index_type{text};
127  rev_fm = rev_fm_index_type{text};
128  }
129 
130 public:
132  static constexpr text_layout text_layout_mode = text_layout_mode_;
133 
140  using size_type = typename sdsl_index_type::size_type;
142 
150 
152 
153  template <typename bi_fm_index_t>
154  friend class bi_fm_index_cursor;
155 
159  bi_fm_index() = default;
160  bi_fm_index(bi_fm_index const &) = default;
161  bi_fm_index & operator=(bi_fm_index const &) = default;
162  bi_fm_index(bi_fm_index &&) = default;
164  ~bi_fm_index() = default;
165 
174  template <std::ranges::range text_t>
175  bi_fm_index(text_t && text)
176  {
177  construct(std::forward<text_t>(text));
178  }
180 
192  size_type size() const noexcept
193  {
194  return fwd_fm.size();
195  }
196 
208  bool empty() const noexcept
209  {
210  return size() == 0;
211  }
212 
224  bool operator==(bi_fm_index const & rhs) const noexcept
225  {
226  return std::tie(fwd_fm, rev_fm) == std::tie(rhs.fwd_fm, rhs.rev_fm);
227  }
228 
240  bool operator!=(bi_fm_index const & rhs) const noexcept
241  {
242  return !(*this == rhs);
243  }
244 
259  cursor_type cursor() const noexcept
260  {
261  return {*this};
262  }
263 
276  fwd_cursor_type fwd_cursor() const noexcept
277  {
278  return {fwd_fm};
279  }
280 
288  template <cereal_archive archive_t>
289  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
290  {
291  archive(fwd_fm);
292  archive(rev_fm);
293  }
295 };
296 
301 template <std::ranges::range text_t>
302 bi_fm_index(text_t &&) -> bi_fm_index<range_innermost_value_t<text_t>, text_layout{range_dimension_v<text_t> != 1}>;
304 
306 
307 } // namespace seqan3
Provides the seqan3::bi_fm_index_cursor for searching in the bidirectional seqan3::bi_fm_index.
The SeqAn Bidirectional FM Index Cursor.
Definition: bi_fm_index_cursor.hpp:58
The SeqAn Bidirectional FM Index.
Definition: bi_fm_index.hpp:65
bi_fm_index(text_t &&text)
Constructor that immediately constructs the index given a range. The range cannot be empty.
Definition: bi_fm_index.hpp:175
bi_fm_index & operator=(bi_fm_index const &)=default
Defaulted.
bi_fm_index(bi_fm_index &&)=default
Defaulted.
fm_index_type fwd_fm
Underlying FM index for the original text.
Definition: bi_fm_index.hpp:97
bi_fm_index()=default
Defaulted.
fwd_cursor_type fwd_cursor() const noexcept
Returns a unidirectional seqan3::fm_index_cursor on the original text of the bidirectional index that...
Definition: bi_fm_index.hpp:276
bool operator==(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition: bi_fm_index.hpp:224
bool operator!=(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition: bi_fm_index.hpp:240
static constexpr text_layout text_layout_mode
Indicates whether index is built over a collection.
Definition: bi_fm_index.hpp:132
cursor_type cursor() const noexcept
Returns a seqan3::bi_fm_index_cursor on the index that can be used for searching. Cursor is pointing ...
Definition: bi_fm_index.hpp:259
typename sdsl_index_type::size_type size_type
Type for representing positions in the indexed text.
Definition: bi_fm_index.hpp:140
typename sdsl_index_type::alphabet_type::char_type sdsl_char_type
The type of the reduced alphabet type. (The reduced alphabet might be smaller than the original alpha...
Definition: bi_fm_index.hpp:84
sdsl_index_type_ sdsl_index_type
The type of the underlying SDSL index for the original text.
Definition: bi_fm_index.hpp:71
rev_fm_index_type rev_fm
Underlying FM index for the reversed text.
Definition: bi_fm_index.hpp:100
typename sdsl_index_type::alphabet_type::sigma_type sdsl_sigma_type
The type of the alphabet size of the underlying SDSL index.
Definition: bi_fm_index.hpp:87
void construct(text_t &&text)
Constructs the index given a range. The range cannot be an rvalue (i.e. a temporary object) and has t...
Definition: bi_fm_index.hpp:122
sdsl::csa_wt< sdsl_wt_index_type::wavelet_tree_type, 10 '000 '000, 10 '000 '000, sdsl::sa_order_sa_sampling<>, sdsl::isa_sampling<>, sdsl_wt_index_type::alphabet_type > rev_sdsl_index_type
The type of the underlying SDSL index for the reversed text.
Definition: bi_fm_index.hpp:79
bi_fm_index & operator=(bi_fm_index &&)=default
Defaulted.
bool empty() const noexcept
Checks whether the index is empty.
Definition: bi_fm_index.hpp:208
bi_fm_index(bi_fm_index const &)=default
Defaulted.
typename fm_index_type::alphabet_type alphabet_type
The type of the underlying character of the indexed text.
Definition: bi_fm_index.hpp:138
size_type size() const noexcept
Returns the length of the indexed text including sentinel characters.
Definition: bi_fm_index.hpp:192
~bi_fm_index()=default
Defaulted.
The SeqAn FM Index Cursor.
Definition: fm_index_cursor.hpp:90
size_type size() const noexcept
Returns the length of the indexed text including sentinel characters.
Definition: fm_index.hpp:461
alphabet_t alphabet_type
The type of the underlying character of the indexed text.
Definition: fm_index.hpp:381
Provides various transformation traits used by the range module.
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
Provides the unidirectional seqan3::fm_index.
text_layout
The possible text layouts (single, collection) the seqan3::fm_index and seqan3::bi_fm_index can suppo...
Definition: concept.hpp:82
sdsl_wt_index_type default_sdsl_index_type
The default FM Index Configuration.
Definition: fm_index.hpp:151
bi_fm_index(text_t &&) -> bi_fm_index< range_innermost_value_t< text_t >, text_layout
Deduces the dimensions of the text.
Definition: bi_fm_index.hpp:302
The basis for seqan3::alphabet, but requires only rank interface (not char).
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides seqan3::views::persist.
#define CEREAL_SERIALIZE_FUNCTION_NAME
Macro for Cereal's serialize function.
Definition: platform.hpp:134
Adaptations of concepts from the Ranges TS.
T tie(T... args)