Loading...
Searching...
No Matches
bi_fm_index.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 <filesystem>
#include <ranges>
#include <utility>
#include <seqan3/core/range/type_traits.hpp>
#include <seqan3/search/fm_index/bi_fm_index_cursor.hpp>
#include <seqan3/search/fm_index/fm_index.hpp>
namespace seqan3
{
template <semialphabet alphabet_t,
text_layout text_layout_mode_,
detail::sdsl_index sdsl_index_type_ = default_sdsl_index_type>
class bi_fm_index
{
private:
using sdsl_index_type = sdsl_index_type_;
using rev_sdsl_index_type =
seqan3::contrib::sdsl::csa_wt<sdsl_wt_index_type::wavelet_tree_type, // Wavelet tree type
10'000'000, // Sampling rate of the suffix array
10'000'000, // Sampling rate of the inverse suffix array
seqan3::contrib::sdsl::sa_order_sa_sampling<>, // Text or SA based sampling for SA
seqan3::contrib::sdsl::isa_sampling<>, // Text or ISA based sampling for ISA
sdsl_wt_index_type::alphabet_type>; // How to represent the alphabet
using sdsl_char_type = typename sdsl_index_type::alphabet_type::char_type;
using sdsl_sigma_type = typename sdsl_index_type::alphabet_type::sigma_type;
using fm_index_type = fm_index<alphabet_t, text_layout_mode_, sdsl_index_type>;
using rev_fm_index_type = detail::reverse_fm_index<alphabet_t, text_layout_mode_, rev_sdsl_index_type>;
fm_index_type fwd_fm;
rev_fm_index_type rev_fm;
template <std::ranges::range text_t>
void construct(text_t && text)
{
detail::fm_index_validator::validate<alphabet_t, text_layout_mode_>(text);
fwd_fm = fm_index_type{text};
rev_fm = rev_fm_index_type{text};
}
public:
static constexpr text_layout text_layout_mode = text_layout_mode_;
using alphabet_type = typename fm_index_type::alphabet_type;
using size_type = typename sdsl_index_type::size_type;
using cursor_type = bi_fm_index_cursor<bi_fm_index>;
using fwd_cursor_type = fm_index_cursor<fm_index_type>;
template <typename bi_fm_index_t>
friend class bi_fm_index_cursor;
bi_fm_index() = default;
bi_fm_index(bi_fm_index const &) = default;
bi_fm_index & operator=(bi_fm_index const &) = default;
bi_fm_index(bi_fm_index &&) = default;
bi_fm_index & operator=(bi_fm_index &&) = default;
~bi_fm_index() = default;
template <std::ranges::range text_t>
bi_fm_index(text_t && text)
{
construct(std::forward<text_t>(text));
}
size_type size() const noexcept
{
return fwd_fm.size();
}
bool empty() const noexcept
{
return size() == 0;
}
bool operator==(bi_fm_index const & rhs) const noexcept
{
return std::tie(fwd_fm, rev_fm) == std::tie(rhs.fwd_fm, rhs.rev_fm);
}
bool operator!=(bi_fm_index const & rhs) const noexcept
{
return !(*this == rhs);
}
cursor_type cursor() const noexcept
{
return {*this};
}
fwd_cursor_type fwd_cursor() const noexcept
{
return {fwd_fm};
}
template <cereal_archive archive_t>
void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
{
archive(fwd_fm);
archive(rev_fm);
}
};
template <std::ranges::range text_t>
bi_fm_index(text_t &&) -> bi_fm_index<range_innermost_value_t<text_t>, text_layout{range_dimension_v<text_t> != 1}>;
} // namespace seqan3
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
The SeqAn Bidirectional FM Index.
Definition bi_fm_index.hpp:58
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:169
seqan3::bi_fm_index::bi_fm_index
bi_fm_index(bi_fm_index &&)=default
Defaulted.
seqan3::bi_fm_index::operator=
bi_fm_index & operator=(bi_fm_index &&)=default
Defaulted.
seqan3::bi_fm_index::bi_fm_index
bi_fm_index()=default
Defaulted.
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:270
seqan3::bi_fm_index::operator==
bool operator==(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition bi_fm_index.hpp:218
seqan3::bi_fm_index::operator!=
bool operator!=(bi_fm_index const &rhs) const noexcept
Compares two indices.
Definition bi_fm_index.hpp:234
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:126
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:253
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:134
seqan3::bi_fm_index::fwd_cursor_type
fm_index_cursor< fm_index_type > fwd_cursor_type
The type of the unidirectional cursor on the original text.
Definition bi_fm_index.hpp:143
seqan3::bi_fm_index::cursor_type
bi_fm_index_cursor< bi_fm_index > cursor_type
The type of the bidirectional cursor.
Definition bi_fm_index.hpp:141
seqan3::bi_fm_index::empty
bool empty() const noexcept
Checks whether the index is empty.
Definition bi_fm_index.hpp:202
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 const &)=default
Defaulted.
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:132
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:186
seqan3::bi_fm_index::~bi_fm_index
~bi_fm_index()=default
Defaulted.
seqan3::fm_index_cursor
The SeqAn FM Index Cursor.
Definition fm_index_cursor.hpp:83
seqan3::fm_index
The SeqAn FM Index.
Definition fm_index.hpp:185
seqan3::fm_index< alphabet_t, text_layout_mode_, sdsl_index_type >::alphabet_type
alphabet_t alphabet_type
Definition fm_index.hpp:384
type_traits.hpp
Provides various transformation traits used by the range module.
filesystem
fm_index.hpp
Provides the unidirectional seqan3::fm_index.
std::forward
T forward(T... args)
seqan3::range_dimension_v
constexpr size_t range_dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t (type trait).
Definition core/range/type_traits.hpp:112
seqan3::text_layout
text_layout
The possible text layouts (single, collection) the seqan3::fm_index and seqan3::bi_fm_index can suppo...
Definition search/fm_index/concept.hpp:69
seqan3::default_sdsl_index_type
sdsl_wt_index_type default_sdsl_index_type
The default FM Index Configuration.
Definition fm_index.hpp:141
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:296
std::tie
T tie(T... args)
utility
Hide me