SeqAn3
The Modern C++ library for sequence analysis.
search.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 #include <seqan3/std/algorithm>
20 #include <seqan3/std/ranges>
21 
22 namespace seqan3
23 {
24 
49 template <FmIndex index_t, typename queries_t, typename configuration_t>
51  requires
54  detail::is_type_specialisation_of_v<remove_cvref_t<configuration_t>, configuration>
56 inline auto search(queries_t && queries, index_t const & index, configuration_t const & cfg)
57 {
58  assert(alphabet_size<innermost_value_type_t<queries_t>> == index.sigma);
59 
60  using cfg_t = remove_cvref_t<configuration_t>;
61 
62  if constexpr (cfg_t::template exists<search_cfg::max_error>())
63  {
64  auto & [total, subs, ins, del] = get<search_cfg::max_error>(cfg).value;
65  if (subs > total)
66  throw std::invalid_argument("The substitution error threshold is higher than the total error threshold.");
67  if (ins > total)
68  throw std::invalid_argument("The insertion error threshold is higher than the total error threshold.");
69  if (del > total)
70  throw std::invalid_argument("The deletion error threshold is higher than the total error threshold.");
71  }
72  else if constexpr (cfg_t::template exists<search_cfg::max_error_rate>())
73  {
74  auto & [total, subs, ins, del] = get<search_cfg::max_error_rate>(cfg).value;
75  if (subs > total)
76  throw std::invalid_argument("The substitution error threshold is higher than the total error threshold.");
77  if (ins > total)
78  throw std::invalid_argument("The insertion error threshold is higher than the total error threshold.");
79  if (del > total)
80  throw std::invalid_argument("The deletion error threshold is higher than the total error threshold.");
81  }
82 
83  if constexpr (cfg_t::template exists<search_cfg::mode>())
84  {
85  if constexpr (cfg_t::template exists<search_cfg::output>())
86  return detail::search_all(index, queries, cfg);
87  else
88  return detail::search_all(index, queries, cfg | search_cfg::output{search_cfg::text_position});
89  }
90  else
91  {
93  if constexpr (cfg_t::template exists<search_cfg::output>())
94  return detail::search_all(index, queries, cfg2);
95  else
96  return detail::search_all(index, queries, cfg2 | search_cfg::output{search_cfg::text_position});
97  }
98 }
99 
101 template <FmIndex index_t, typename configuration_t>
102 inline auto search(char const * const queries, index_t const & index, configuration_t const & cfg)
103 {
104  return search(std::string_view{queries}, index, cfg);
105 }
106 
108 template <FmIndex index_t, typename configuration_t>
110  index_t const & index,
111  configuration_t const & cfg)
112 {
114  query.reserve(std::ranges::size(queries));
115  std::ranges::for_each(queries, [&query] (char const * const q) { query.push_back(std::string_view{q}); });
116  return search(query, index, cfg);
117 }
118 
136 template <FmIndex index_t, typename queries_t>
141 inline auto search(queries_t && queries, index_t const & index)
142 {
143  assert(alphabet_size<innermost_value_type_t<queries_t>> == index.sigma);
144 
151  return search(queries, index, default_cfg);
152 }
153 
155 template <FmIndex index_t>
156 inline auto search(index_t const & index, char const * const queries)
157 {
158  return search(std::string_view{queries}, index);
159 }
160 
162 template <FmIndex index_t>
163 inline auto search(std::initializer_list<char const * const> const & queries, index_t const & index)
164 {
166  query.reserve(std::ranges::size(queries));
167  std::ranges::for_each(queries, [&query] (char const * const q) { query.push_back(std::string_view{q}); });
168  return search(query, index);
169 }
170 
172 
173 } // namespace seqan3
Configuration element to determine the output type of hits.
Definition: output.hpp:59
detail::search_output_text_position constexpr text_position
Configuration element to receive all hits within the lowest number of errors.
Definition: output.hpp:42
auto search(queries_t &&queries, index_t const &index, configuration_t const &cfg)
Search a query or a range of queries in an index.
Definition: search.hpp:56
Provides the public interface for search algorithms.
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
A strong type of underlying type uint8_t or double that represents the number or rate of deletions...
Definition: max_error_common.hpp:130
Configuration element to determine the search mode.
Definition: mode.hpp:83
T push_back(T... args)
A strong type of underlying type uint8_t or double that represents the number or rate of total errors...
Definition: max_error_common.hpp:30
A strong type of underlying type uint8_t or double that represents the number or rate of substitution...
Definition: max_error_common.hpp:64
Adaptations of concepts from the Ranges TS.
typename innermost_value_type< t >::type innermost_value_type_t
Shortcut for seqan3::innermost_value_type (TransformationTrait shortcut).
Definition: range.hpp:191
::ranges::for_each for_each
Alias for ranges::for_each. Applies a function object to the elements of a range. ...
Definition: algorithm:79
Specifies requirements of a Range type for which begin returns a type that models std::RandomAccessIt...
Specifies requirements of a Range type for which begin returns a type that models std::ForwardIterato...
detail::search_mode_all constexpr all
Configuration element to receive all hits within the error bounds.
Definition: mode.hpp:42
Meta-header for the FM index module.
Adaptations of algorithms from the Ranges TS.
Provides seqan3::view::persist.
Provides seqan3::detail::configuration and utility functions.
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:678
A configuration element for the maximum number of errors across all error types (mismatches, insertions, deletions). This is an upper bound of errors independent from error numbers of specific error types.
Definition: max_error.hpp:43
Collection of elements to configure an algorithm.
Definition: configuration.hpp:82
T reserve(T... args)
A strong type of underlying type uint8_t or double that represents the number or rate of insertions...
Definition: max_error_common.hpp:97