Raptor
A fast and space-efficient pre-filter
All Classes Namespaces Files Functions Variables Macros Pages Concepts
sync_out.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <filesystem>
13#include <fstream>
14#include <mutex>
15
16#include <hibf/contrib/std/join_with_view.hpp>
17
19
20namespace raptor
21{
22
24{
25public:
26 sync_out() = default;
27 sync_out(sync_out const &) = delete; // std::ofstream
28 sync_out & operator=(sync_out const &) = delete; // std::ofstream
29 sync_out(sync_out &&) = delete; // std::mutex
30 sync_out & operator=(sync_out &&) = delete; // std::mutex
31 ~sync_out() = default;
32
33 sync_out(search_arguments const & arguments) : file{arguments.out_file}
34 {}
35
36 template <typename t>
37 void write(t && data)
38 {
39 std::lock_guard<std::mutex> lock{write_mutex};
40 file << std::forward<t>(data);
41 }
42
43 bool write_header(search_arguments const & arguments, size_t const hash_function_count)
44 {
45 file << "### Minimiser parameters\n";
46 file << "## Window size = " << arguments.window_size << '\n';
47 file << "## Shape = " << arguments.shape.to_string() << '\n';
48 file << "## Shape size (length) = " << static_cast<uint16_t>(arguments.shape_size) << '\n';
49 file << "## Shape count (number of 1s) = " << static_cast<uint16_t>(arguments.shape_weight) << '\n';
50 file << "### Search parameters\n";
51 file << "## Query file = " << arguments.query_file << '\n';
52 file << "## Pattern size = " << arguments.query_length << '\n';
53 file << "## Output file = " << arguments.out_file << '\n';
54 file << "## Threads = " << static_cast<uint16_t>(arguments.threads) << '\n';
55 file << "## tau = " << arguments.tau << '\n';
56 file << "## p_max = " << arguments.p_max << '\n';
57 file << "## Percentage threshold = " << arguments.threshold << '\n';
58 file << "## Errors = " << static_cast<uint16_t>(arguments.errors) << '\n';
59 file << "## Cache thresholds = " << std::boolalpha << arguments.cache_thresholds << '\n';
60 file << "### Index parameters\n";
61 file << "## Index = " << arguments.index_file << '\n';
62 file << "## Index hashes = " << hash_function_count << '\n';
63 file << "## Index parts = " << static_cast<uint16_t>(arguments.parts) << '\n';
64 file << "## False positive rate = " << arguments.fpr << '\n';
65 file << "## Index is HIBF = " << std::boolalpha << arguments.is_hibf << '\n';
66
67 size_t user_bin_id{};
68 for (auto const & file_list : arguments.bin_path)
69 {
70 file << '#' << user_bin_id << '\t';
71 for (auto const elem : seqan::stl::views::join_with(file_list, ','))
72 file << elem;
73 file << '\n';
74 ++user_bin_id;
75 }
76
77 file << "#QUERY_NAME\tUSER_BINS\n";
78
79 return true;
80 }
81
82private:
83 std::ofstream file;
84 std::mutex write_mutex;
85};
86
87} // namespace raptor
T boolalpha(T... args)
Definition sync_out.hpp:24
Provides raptor::search_arguments.
Definition search_arguments.hpp:27
Hide me