SeqAn3  3.0.2
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 <utility>
16 
18 #include <seqan3/std/filesystem>
22 #include <seqan3/std/ranges>
23 
24 namespace seqan3
25 {
26 
62 template <semialphabet alphabet_t,
63  text_layout text_layout_mode_,
64  detail::sdsl_index sdsl_index_type_ = default_sdsl_index_type>
66 {
67 private:
71  using sdsl_index_type = sdsl_index_type_;
73 
75  using rev_sdsl_index_type = sdsl::csa_wt<sdsl_wt_index_type::wavelet_tree_type, // Wavelet tree type
76  10'000'000, // Sampling rate of the suffix array
77  10'000'000, // Sampling rate of the inverse suffix array
78  sdsl::sa_order_sa_sampling<>, // Text or SA based sampling for SA
79  sdsl::isa_sampling<>, // Text or ISA based sampling for ISA
80  sdsl_wt_index_type::alphabet_type>; // How to represent the alphabet
81 
85  using sdsl_char_type = typename sdsl_index_type::alphabet_type::char_type;
86 
88  using sdsl_sigma_type = typename sdsl_index_type::alphabet_type::sigma_type;
89 
92 
94  using rev_fm_index_type = detail::reverse_fm_index<alphabet_t, text_layout_mode_, rev_sdsl_index_type>;
96 
98  fm_index_type fwd_fm;
99 
101  rev_fm_index_type rev_fm;
102 
122  template <std::ranges::range text_t>
123  void construct(text_t && text)
124  {
125  detail::fm_index_validator::validate<alphabet_t, text_layout_mode_>(text);
126 
127  fwd_fm = fm_index_type{text};
128  rev_fm = rev_fm_index_type{text};
129  }
130 
131 public:
133  static constexpr text_layout text_layout_mode = text_layout_mode_;
134 
141  using size_type = typename sdsl_index_type::size_type;
143 
151 
153 
154  template <typename bi_fm_index_t>
155  friend class bi_fm_index_cursor;
156 
160  bi_fm_index() = default;
161  bi_fm_index(bi_fm_index const &) = default;
162  bi_fm_index & operator=(bi_fm_index const &) = default;
163  bi_fm_index(bi_fm_index &&) = default;
165  ~bi_fm_index() = default;
166 
175  template <std::ranges::range text_t>
176  bi_fm_index(text_t && text)
177  {
178  construct(std::forward<text_t>(text));
179  }
181 
193  size_type size() const noexcept
194  {
195  return fwd_fm.size();
196  }
197 
209  bool empty() const noexcept
210  {
211  return size() == 0;
212  }
213 
225  bool operator==(bi_fm_index const & rhs) const noexcept
226  {
227  return std::tie(fwd_fm, rev_fm) == std::tie(rhs.fwd_fm, rhs.rev_fm);
228  }
229 
241  bool operator!=(bi_fm_index const & rhs) const noexcept
242  {
243  return !(*this == rhs);
244  }
245 
260  cursor_type cursor() const noexcept
261  {
262  return {*this};
263  }
264 
277  fwd_cursor_type fwd_cursor() const noexcept
278  {
279  return {fwd_fm};
280  }
281 
289  template <cereal_archive archive_t>
290  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
291  {
292  archive(fwd_fm);
293  archive(rev_fm);
294  }
296 };
297 
301 template <std::ranges::range text_t>
303 bi_fm_index(text_t &&) -> bi_fm_index<range_innermost_value_t<text_t>, text_layout{range_dimension_v<text_t> != 1}>;
305 
307 
308 } // namespace seqan3
seqan3::bi_fm_index::empty
bool empty() const noexcept
Checks whether the index is empty.
Definition: bi_fm_index.hpp:209
utility
seqan3::fm_index< alphabet_t, text_layout_mode_, sdsl_index_type >
seqan3::bi_fm_index::~bi_fm_index
~bi_fm_index()=default
Defaulted.
seqan3::bi_fm_index::operator==
bool operator==(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition: bi_fm_index.hpp:225
seqan3::bi_fm_index::operator=
bi_fm_index & operator=(bi_fm_index const &)=default
Defaulted.
seqan3::bi_fm_index::bi_fm_index
bi_fm_index(bi_fm_index &&)=default
Defaulted.
filesystem
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
seqan3::bi_fm_index
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:303
seqan3::bi_fm_index
The SeqAn Bidirectional FM Index.
Definition: bi_fm_index.hpp:66
std::tie
T tie(T... args)
seqan3::bi_fm_index::alphabet_type
typename fm_index_type::alphabet_type alphabet_type
The type of the underlying character of the indexed text.
Definition: bi_fm_index.hpp:139
seqan3::text_layout
text_layout
The possible text layouts (single, collection) the seqan3::fm_index and seqan3::bi_fm_index can suppo...
Definition: concept.hpp:82
seqan3::bi_fm_index::size_type
typename sdsl_index_type::size_type size_type
Type for representing positions in the indexed text.
Definition: bi_fm_index.hpp:141
seqan3::bi_fm_index::text_layout_mode
static constexpr text_layout text_layout_mode
Indicates whether index is built over a collection.
Definition: bi_fm_index.hpp:133
seqan3::fm_index< alphabet_t, text_layout_mode_, sdsl_index_type >::alphabet_type
alphabet_t alphabet_type
The type of the underlying character of the indexed text.
Definition: fm_index.hpp:381
range.hpp
Provides various transformation traits used by the range module.
seqan3::bi_fm_index::cursor
cursor_type cursor() const noexcept
Returns a seqan3::bi_fm_index_cursor on the index that can be used for searching.
Definition: bi_fm_index.hpp:260
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
persist.hpp
Provides seqan3::views::persist.
seqan3::fm_index::size
size_type size() const noexcept
Returns the length of the indexed text including sentinel characters.
Definition: fm_index.hpp:461
seqan3::bi_fm_index::operator=
bi_fm_index & operator=(bi_fm_index &&)=default
Defaulted.
seqan3::default_sdsl_index_type
sdsl_wt_index_type default_sdsl_index_type
The default FM Index Configuration.
Definition: fm_index.hpp:150
ranges
Adaptations of concepts from the Ranges TS.
seqan3::bi_fm_index::bi_fm_index
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:176
seqan3::bi_fm_index_cursor
The SeqAn Bidirectional FM Index Cursor.
Definition: bi_fm_index_cursor.hpp:57
seqan3::bi_fm_index::fwd_cursor
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:277
seqan3::fm_index_cursor
The SeqAn FM Index Cursor.
Definition: fm_index_cursor.hpp:57
bi_fm_index_cursor.hpp
Provides the seqan3::bi_fm_index_cursor for searching in the bidirectional seqan3::bi_fm_index.
seqan3::bi_fm_index::bi_fm_index
bi_fm_index()=default
Defaulted.
seqan3::bi_fm_index::operator!=
bool operator!=(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition: bi_fm_index.hpp:241
seqan3::bi_fm_index::bi_fm_index
bi_fm_index(bi_fm_index const &)=default
Defaulted.
fm_index.hpp
Provides the unidirectional seqan3::fm_index.
semialphabet
The basis for seqan3::alphabet, but requires only rank interface (not char).
seqan3::bi_fm_index::size
size_type size() const noexcept
Returns the length of the indexed text including sentinel characters.
Definition: bi_fm_index.hpp:193