HIBF 1.0.0-rc.1
Loading...
Searching...
No Matches
layout.hpp
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
5#pragma once
6
7#include <concepts> // for derived_from
8#include <cstddef> // for size_t
9#include <iosfwd> // for ostream, istream
10#include <vector> // for operator==, vector
11
12#include <hibf/layout/prefixes.hpp> // for layout_fullest_technical_bin_idx, layout_header, layout_lower_level
13#include <hibf/platform.hpp>
14
15namespace seqan::hibf::layout
16{
17
21struct layout
22{
23 struct max_bin
24 {
25 std::vector<size_t> previous_TB_indices{}; // identifies the IBF based on upper levels
26 size_t id{}; // the technical bin id that has the maximum kmer content
27
28 friend auto operator<=>(max_bin const &, max_bin const &) = default;
29
30 // needs a template (instead of using std::ostream directly) to be able to only include <iosfwd>
31 template <typename stream_type>
33 friend stream_type & operator<<(stream_type & stream, max_bin const & object)
34 {
35 stream << prefix::layout_header << prefix::layout_lower_level << '_';
36 auto it = object.previous_TB_indices.begin();
37 auto end = object.previous_TB_indices.end();
38 // If not empty, we join with ';'
39 if (it != end)
40 {
41 stream << *it;
42 while (++it != end)
43 stream << ';' << *it;
44 }
45 stream << " " << prefix::layout_fullest_technical_bin_idx << object.id;
46
47 return stream;
48 }
49 };
50
51 struct user_bin
52 {
53 std::vector<size_t> previous_TB_indices{}; // previous technical bin indices which refer to merged bin indices.
54 size_t storage_TB_id{}; // id of the technical bin that the user bin is actuallly stored in
55 size_t number_of_technical_bins{}; // 1 == single bin, >1 == split_bin
56 size_t idx{}; // The index of the user bin corresponding to the order in data
57
58 friend auto operator<=>(user_bin const &, user_bin const &) = default;
59
60 // needs a template (instead of using std::ostream directly) to be able to only include <iosfwd>
61 template <typename stream_type>
63 friend stream_type & operator<<(stream_type & stream, user_bin const & object)
64 {
65 stream << object.idx << '\t';
66 for (auto bin : object.previous_TB_indices)
67 stream << bin << ';';
68 stream << object.storage_TB_id << '\t';
69 for ([[maybe_unused]] auto && elem : object.previous_TB_indices) // number of bins per merged level is 1
70 stream << "1;";
71 stream << object.number_of_technical_bins;
72
73 return stream;
74 }
75 };
76
77 void read_from(std::istream & stream);
78 void write_to(std::ostream & stream) const;
79
80 void clear();
81
82 size_t top_level_max_bin_id{};
83 std::vector<max_bin> max_bins{};
84 std::vector<user_bin> user_bins{};
85
86 bool operator==(layout const &) const = default;
87};
88
89} // namespace seqan::hibf::layout
T begin(T... args)
T is_base_of_v
Provides platform and dependency checks.
Definition layout.hpp:24
The layout.
Definition layout.hpp:22