SeqAn3
search.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
45 
46 namespace seqan3
47 {
48 
75 template <fm_index_concept index_t, typename queries_t, typename configuration_t>
77  requires
80  detail::is_algorithm_configuration_v<remove_cvref_t<configuration_t>>
82 inline auto search(index_t const & index, queries_t && queries, configuration_t const & cfg)
83 {
84  if constexpr (contains<search_cfg::id::max_error>(cfg))
85  {
86  auto & [total, subs, ins, del] = get<search_cfg::id::max_error>(cfg);
87  if (subs > total)
88  throw std::invalid_argument("The substitution error threshold is higher than the total error threshold.");
89  if (ins > total)
90  throw std::invalid_argument("The insertion error threshold is higher than the total error threshold.");
91  if (del > total)
92  throw std::invalid_argument("The deletion error threshold is higher than the total error threshold.");
93  }
94  else if constexpr (contains<search_cfg::id::max_error_rate>(cfg))
95  {
96  auto & [total, subs, ins, del] = get<search_cfg::id::max_error_rate>(cfg);
97  if (subs > total)
98  throw std::invalid_argument("The substitution error threshold is higher than the total error threshold.");
99  if (ins > total)
100  throw std::invalid_argument("The insertion error threshold is higher than the total error threshold.");
101  if (del > total)
102  throw std::invalid_argument("The deletion error threshold is higher than the total error threshold.");
103  }
104 
105  if constexpr (contains<search_cfg::id::mode>(cfg))
106  {
107  if constexpr (contains<search_cfg::id::output>(cfg))
108  return detail::search_all(index, queries, cfg);
109  else
110  return detail::search_all(index, queries, cfg | search_cfg::output(search_cfg::text_position));
111  }
112  else
113  {
114  detail::configuration const cfg2 = cfg | search_cfg::mode(search_cfg::all);
115  if constexpr (contains<search_cfg::id::output>(cfg))
116  return detail::search_all(index, queries, cfg2);
117  else
118  return detail::search_all(index, queries, cfg2 | search_cfg::output(search_cfg::text_position));
119  }
120 }
121 
139 template <fm_index_concept index_t, typename queries_t>
144 inline auto search(index_t const & index, queries_t && queries)
145 {
146  detail::configuration const default_cfg = search_cfg::max_error(search_cfg::total{0},
152  return search(index, queries, default_cfg);
153 }
154 
156 
157 } // namespace seqan3
detail::search_output_text_position constexpr text_position
Configuration element to receive all hits within the lowest number of errors.
Definition: output.hpp:67
detail::search_config_output_adaptor< seqan3::detail::search_config_output > constexpr output
Configuration element to determine the output type of hits.
Definition: output.hpp:137
Provides the public interface for search algorithms.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
A strong type of underlying type uint8_t or double that represents the number or rate of deletions...
Definition: max_error_common.hpp:139
auto search(index_t const &index, queries_t &&queries, configuration_t const &cfg)
Search a query or a range of queries in an index.
Definition: search.hpp:82
A strong type of underlying type uint8_t or double that represents the number or rate of total errors...
Definition: max_error_common.hpp:57
A strong type of underlying type uint8_t or double that represents the number or rate of substitution...
Definition: max_error_common.hpp:85
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:67
Meta-header for the FM index module.
detail::search_config_mode_adaptor< seqan3::detail::search_config_mode > constexpr mode
Configuration element to determine the search mode.
Definition: mode.hpp:150
Provides seqan3::view::persist.
constexpr detail::search_config_max_error_adaptor max_error
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:168
A strong type of underlying type uint8_t or double that represents the number or rate of insertions...
Definition: max_error_common.hpp:112