fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
build_from_files.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
12
13namespace raptor
14{
15
16template <bool compressed>
17void build_from_files(build_arguments const & arguments)
18{
19 index_factory<compressed> generator{arguments};
20
21 if (arguments.parts == 1u)
22 {
23 auto index = generator();
24 store_index(arguments.out_path, index, arguments);
25 }
26 else
27 {
28 std::vector<std::vector<size_t>> association(arguments.parts);
29 size_t next_power_of_four{4u};
30
31 if (arguments.parts == 4u) // one-to-one
32 {
33 for (size_t i : std::views::iota(0u, arguments.parts))
34 association[i] = std::vector<size_t>{i};
35 }
36 else if (arguments.parts == 2u) // More than 1 prefix per part
37 {
38 association[0] = std::vector<size_t>{0, 1};
39 association[1] = std::vector<size_t>{2, 3};
40 }
41 else // More parts than prefixes
42 {
43 // How long must the suffix be such that 4^suffix_length >= arguments.parts
44 size_t suffix_length{0};
45 for (; 0b100 << (2 * suffix_length) < arguments.parts; ++suffix_length)
46 {}
47 next_power_of_four = 0b100 << (2 * suffix_length);
48
49 size_t const prefixes_per_part = next_power_of_four / arguments.parts;
50
51 for (size_t i : std::views::iota(0u, next_power_of_four))
52 association[i / prefixes_per_part].push_back(i);
53 }
54
55 for (size_t part : std::views::iota(0u, arguments.parts))
56 {
57 size_t const mask{next_power_of_four - 1};
58 auto filter_view = std::views::filter(
59 [&](auto && hash)
60 {
61 return std::ranges::find(association[part], hash & mask) != association[part].end();
62 });
63
64 auto index = generator(std::move(filter_view));
65 std::filesystem::path out_path{arguments.out_path};
66 out_path += "_" + std::to_string(part);
67 store_index(out_path, index, arguments);
68 }
69 }
70}
71
72} // namespace raptor
Definition: index_factory.hpp:22
Definition: adjust_seed.hpp:13
void build_from_files(build_arguments const &arguments)
Definition: build_from_files.hpp:17
Definition: build_arguments.hpp:21
uint8_t parts
Definition: build_arguments.hpp:37
std::filesystem::path out_path
Definition: build_arguments.hpp:32