fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
index_factory.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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/raptor/blob/main/LICENSE.md
6 // --------------------------------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <seqan3/search/views/minimiser_hash.hpp>
11 
12 #include <raptor/adjust_seed.hpp>
14 #include <raptor/dna4_traits.hpp>
15 #include <raptor/index.hpp>
16 
17 namespace raptor
18 {
19 
20 template <bool compressed>
22 {
23 public:
24  index_factory() = default;
25  index_factory(index_factory const &) = default;
27  index_factory & operator=(index_factory const &) = default;
29  ~index_factory() = default;
30 
31  explicit index_factory(build_arguments const & args) : arguments{std::addressof(args)}
32  {}
33 
34  template <typename view_t = int>
35  [[nodiscard]] auto operator()(view_t && hash_filter_view = 0) const
36  {
37  auto tmp = construct(std::move(hash_filter_view));
38 
39  if constexpr (!compressed)
40  return tmp;
41  else
42  return raptor_index<index_structure::ibf_compressed>{std::move(tmp)};
43  }
44 
45 private:
46  build_arguments const * const arguments{nullptr};
47 
48  template <typename view_t>
49  auto construct(view_t && hash_filter_view) const
50  {
51  using sequence_file_t = seqan3::sequence_file_input<dna4_traits, seqan3::fields<seqan3::field::seq>>;
52 
53  assert(arguments != nullptr);
54 
55  raptor_index<> index{*arguments};
56 
57  auto hash_view = [&]()
58  {
59  if constexpr (std::same_as<view_t, int>)
60  {
61  return seqan3::views::minimiser_hash(arguments->shape,
62  seqan3::window_size{arguments->window_size},
63  seqan3::seed{adjust_seed(arguments->shape.count())});
64  }
65  else
66  {
67  return seqan3::views::minimiser_hash(arguments->shape,
68  seqan3::window_size{arguments->window_size},
69  seqan3::seed{adjust_seed(arguments->shape.count())})
70  | hash_filter_view;
71  }
72  };
73 
74  auto worker = [&](auto && zipped_view, auto &&)
75  {
76  auto & ibf = index.ibf();
77 
78  for (auto && [file_names, bin_number] : zipped_view)
79  for (auto && file_name : file_names)
80  for (auto && [seq] : sequence_file_t{file_name})
81  for (auto && value : seq | hash_view())
82  ibf.emplace(value, seqan3::bin_index{bin_number});
83  };
84 
85  call_parallel_on_bins(worker, *arguments);
86 
87  return index;
88  }
89 };
90 
91 } // namespace raptor
Definition: index_factory.hpp:22
index_factory & operator=(index_factory &&)=default
index_factory(index_factory const &)=default
index_factory(build_arguments const &args)
Definition: index_factory.hpp:31
index_factory & operator=(index_factory const &)=default
index_factory(index_factory &&)=default
auto operator()(view_t &&hash_filter_view=0) const
Definition: index_factory.hpp:35
Definition: index.hpp:35
seqan3::interleaved_bloom_filter< seqan3::data_layout::uncompressed > ibf
Definition: index.hpp:22
Definition: adjust_seed.hpp:13
void call_parallel_on_bins(algorithm_t &&worker, build_arguments const &arguments)
Definition: call_parallel_on_bins.hpp:20
Definition: build_arguments.hpp:21
seqan3::shape shape
Definition: build_arguments.hpp:27