Skip to content

Commit

Permalink
[MISC] Remove user_bin ctor again. (#67)
Browse files Browse the repository at this point in the history
* [MISC] Remove user_bin ctor again.

* [MISC] Review

---------

Co-authored-by: Enrico Seiler <[email protected]>
  • Loading branch information
smehringer and eseiler authored Sep 4, 2023
1 parent ff69885 commit a8966ca
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 127 deletions.
17 changes: 0 additions & 17 deletions include/hibf/layout/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@ struct layout
size_t number_of_technical_bins{}; // 1 == single bin, >1 == split_bin
size_t idx{}; // The index of the user bin corresponding to the order in data

user_bin() = default;
user_bin(user_bin const &) = default;
user_bin(user_bin &&) = default;
user_bin & operator=(user_bin const &) = default;
user_bin & operator=(user_bin &&) = default;
~user_bin() = default;

user_bin(size_t const idx_,
std::vector<size_t> const & previous_TB_indices_,
size_t const number_of_technical_bins_,
size_t const storage_TB_id_) :
previous_TB_indices{previous_TB_indices_},
storage_TB_id{storage_TB_id_},
number_of_technical_bins{number_of_technical_bins_},
idx{idx_}
{}

friend auto operator<=>(user_bin const &, user_bin const &) = default;

// needs a template (instead of using std::ostream directly) to be able to only include <iosfwd>
Expand Down
12 changes: 6 additions & 6 deletions src/layout/hierarchical_binning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ size_t hierarchical_binning::backtracking(std::vector<std::vector<std::pair<size
{
size_t const kmer_count_per_bin = (kmer_count + number_of_bins - 1) / number_of_bins; // round up

data->hibf_layout->user_bins.emplace_back(data->positions[trace_j],
data->previous.bin_indices,
data->hibf_layout->user_bins.emplace_back(data->previous.bin_indices,
bin_id,
number_of_bins,
bin_id);
data->positions[trace_j]);

// std::cout << "split " << trace_j << " into " << number_of_bins << ": " << kmer_count_per_bin << std::endl;

Expand Down Expand Up @@ -312,10 +312,10 @@ size_t hierarchical_binning::backtracking(std::vector<std::vector<std::pair<size
size_t const number_of_tbs = trace_i + 1;
size_t const average_bin_size = (kmer_count + number_of_tbs - 1) / number_of_tbs; // round up

data->hibf_layout->user_bins.emplace_back(data->positions[0],
data->previous.bin_indices,
data->hibf_layout->user_bins.emplace_back(data->previous.bin_indices,
bin_id,
number_of_tbs,
bin_id);
data->positions[0]);

update_max_id(high_level_max_id, high_level_max_size, bin_id, average_bin_size);
// std::cout << "split " << trace_j << " into " << trace_i << ": " << kmer_count / number_of_tbs << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions src/layout/simple_binning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ size_t simple_binning::execute()
size_t const number_of_bins = (trace_i - next_i);
size_t const kmer_count_per_bin = (kmer_count + number_of_bins - 1) / number_of_bins; // round up

data->hibf_layout->user_bins.emplace_back(data->positions[trace_j],
data->previous.bin_indices,
data->hibf_layout->user_bins.emplace_back(data->previous.bin_indices,
bin_id,
number_of_bins,
bin_id);
data->positions[trace_j]);

if (kmer_count_per_bin > max_size)
{
Expand All @@ -96,7 +96,7 @@ size_t simple_binning::execute()
size_t const kmer_count = (*data->kmer_counts)[data->positions[0]];
size_t const kmer_count_per_bin = (kmer_count + trace_i - 1) / trace_i;

data->hibf_layout->user_bins.emplace_back(data->positions[0], data->previous.bin_indices, trace_i, bin_id);
data->hibf_layout->user_bins.emplace_back(data->previous.bin_indices, bin_id, trace_i, data->positions[0]);

if (kmer_count_per_bin > max_size)
max_id = bin_id;
Expand Down
80 changes: 40 additions & 40 deletions test/unit/hibf/layout/graph_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ TEST(layout_test, printing_max_bins)
hibf_layout.max_bins.emplace_back(std::vector<size_t>{0, 1}, 34);
hibf_layout.max_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 30);
// isnert (previous_TB_indices, storage_TB_id, number_of_technical_bins, idx)
hibf_layout.user_bins.emplace_back(15, std::vector<size_t>{0, 0, 0}, 30, 0);
hibf_layout.user_bins.emplace_back(16, std::vector<size_t>{0, 0, 0}, 11, 30);
hibf_layout.user_bins.emplace_back(17, std::vector<size_t>{0, 0, 0}, 11, 41);
hibf_layout.user_bins.emplace_back(18, std::vector<size_t>{0, 0, 0}, 6, 52);
hibf_layout.user_bins.emplace_back(19, std::vector<size_t>{0, 0, 0}, 6, 58);
hibf_layout.user_bins.emplace_back(14, std::vector<size_t>{0, 0}, 1, 1);
hibf_layout.user_bins.emplace_back(13, std::vector<size_t>{0, 0}, 1, 2);
hibf_layout.user_bins.emplace_back(12, std::vector<size_t>{0, 0}, 1, 3);
hibf_layout.user_bins.emplace_back(11, std::vector<size_t>{0, 0}, 1, 4);
hibf_layout.user_bins.emplace_back(8, std::vector<size_t>{0, 1}, 34, 0);
hibf_layout.user_bins.emplace_back(9, std::vector<size_t>{0, 1}, 15, 34);
hibf_layout.user_bins.emplace_back(10, std::vector<size_t>{0, 1}, 15, 49);
hibf_layout.user_bins.emplace_back(7, std::vector<size_t>{0}, 1, 2);
hibf_layout.user_bins.emplace_back(6, std::vector<size_t>{0}, 1, 3);
hibf_layout.user_bins.emplace_back(5, std::vector<size_t>{0}, 1, 4);
hibf_layout.user_bins.emplace_back(2, std::vector<size_t>{1}, 26, 0);
hibf_layout.user_bins.emplace_back(3, std::vector<size_t>{1}, 19, 26);
hibf_layout.user_bins.emplace_back(4, std::vector<size_t>{1}, 19, 45);
hibf_layout.user_bins.emplace_back(1, std::vector<size_t>{}, 1, 2);
hibf_layout.user_bins.emplace_back(0, std::vector<size_t>{}, 2, 3);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 0, 30, 15);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 30, 11, 16);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 41, 11, 17);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 52, 6, 18);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0, 0}, 58, 6, 19);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0}, 1, 1, 14);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0}, 2, 1, 13);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0}, 3, 1, 12);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 0}, 4, 1, 11);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 1}, 0, 34, 8);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 1}, 34, 15, 9);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0, 1}, 49, 15, 10);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0}, 2, 1, 7);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0}, 3, 1, 6);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{0}, 4, 1, 5);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{1}, 0, 26, 2);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{1}, 26, 19, 3);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{1}, 45, 19, 4);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{}, 2, 1, 1);
hibf_layout.user_bins.emplace_back(std::vector<size_t>{}, 3, 2, 0);

seqan::hibf::layout::graph hibf_graph{hibf_layout};

Expand All @@ -50,9 +50,9 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(hibf_graph.root.favourite_child_idx.value(), 0);
ASSERT_EQ(hibf_graph.root.remaining_records.size(), 2);
EXPECT_EQ(hibf_graph.root.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{1, std::vector<size_t>{}, 1, 2}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{}, 2, 1, 1}));
EXPECT_EQ(hibf_graph.root.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{0, std::vector<size_t>{}, 2, 3}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{}, 3, 2, 0}));

// tree structure:
ASSERT_EQ(hibf_graph.root.children.size(), 2);
Expand All @@ -73,11 +73,11 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(root_child0.favourite_child_idx.value(), 1);
ASSERT_EQ(root_child0.remaining_records.size(), 3);
EXPECT_EQ(root_child0.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{7, std::vector<size_t>{0}, 1, 2}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0}, 2, 1, 7}));
EXPECT_EQ(root_child0.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{6, std::vector<size_t>{0}, 1, 3}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0}, 3, 1, 6}));
EXPECT_EQ(root_child0.remaining_records[2],
(seqan::hibf::layout::layout::user_bin{5, std::vector<size_t>{0}, 1, 4}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0}, 4, 1, 5}));

// child 1 of root
EXPECT_EQ(root_child1.parent_bin_index, 1);
Expand All @@ -86,11 +86,11 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(root_child1.favourite_child_idx.has_value(), false);
ASSERT_EQ(root_child1.remaining_records.size(), 3);
EXPECT_EQ(root_child1.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{3, std::vector<size_t>{1}, 19, 26}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{1}, 26, 19, 3}));
EXPECT_EQ(root_child1.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{2, std::vector<size_t>{1}, 26, 0}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{1}, 0, 26, 2}));
EXPECT_EQ(root_child1.remaining_records[2],
(seqan::hibf::layout::layout::user_bin{4, std::vector<size_t>{1}, 19, 45}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{1}, 45, 19, 4}));

// child 0 of child 0
EXPECT_EQ(c0_child0.parent_bin_index, 0);
Expand All @@ -99,13 +99,13 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(c0_child0.favourite_child_idx.has_value(), false);
ASSERT_EQ(c0_child0.remaining_records.size(), 4);
EXPECT_EQ(c0_child0.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{11, std::vector<size_t>{0, 0}, 1, 4}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0}, 4, 1, 11}));
EXPECT_EQ(c0_child0.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{14, std::vector<size_t>{0, 0}, 1, 1}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0}, 1, 1, 14}));
EXPECT_EQ(c0_child0.remaining_records[2],
(seqan::hibf::layout::layout::user_bin{13, std::vector<size_t>{0, 0}, 1, 2}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0}, 2, 1, 13}));
EXPECT_EQ(c0_child0.remaining_records[3],
(seqan::hibf::layout::layout::user_bin{12, std::vector<size_t>{0, 0}, 1, 3}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0}, 3, 1, 12}));

// child 1 of child 0
EXPECT_EQ(c0_child1.parent_bin_index, 1);
Expand All @@ -114,11 +114,11 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(c0_child1.favourite_child_idx.has_value(), false);
ASSERT_EQ(c0_child1.remaining_records.size(), 3);
EXPECT_EQ(c0_child1.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{9, std::vector<size_t>{0, 1}, 15, 34}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 1}, 34, 15, 9}));
EXPECT_EQ(c0_child1.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{8, std::vector<size_t>{0, 1}, 34, 0}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 1}, 0, 34, 8}));
EXPECT_EQ(c0_child1.remaining_records[2],
(seqan::hibf::layout::layout::user_bin{10, std::vector<size_t>{0, 1}, 15, 49}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 1}, 49, 15, 10}));

// child 0 of child 0 of child 0
EXPECT_EQ(c0_c0_child0.parent_bin_index, 0);
Expand All @@ -127,13 +127,13 @@ TEST(layout_test, printing_max_bins)
EXPECT_EQ(c0_c0_child0.favourite_child_idx.has_value(), false);
ASSERT_EQ(c0_c0_child0.remaining_records.size(), 5);
EXPECT_EQ(c0_c0_child0.remaining_records[0],
(seqan::hibf::layout::layout::user_bin{16, std::vector<size_t>{0, 0, 0}, 11, 30}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0, 0}, 30, 11, 16}));
EXPECT_EQ(c0_c0_child0.remaining_records[1],
(seqan::hibf::layout::layout::user_bin{15, std::vector<size_t>{0, 0, 0}, 30, 0}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0, 0}, 0, 30, 15}));
EXPECT_EQ(c0_c0_child0.remaining_records[2],
(seqan::hibf::layout::layout::user_bin{17, std::vector<size_t>{0, 0, 0}, 11, 41}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0, 0}, 41, 11, 17}));
EXPECT_EQ(c0_c0_child0.remaining_records[3],
(seqan::hibf::layout::layout::user_bin{18, std::vector<size_t>{0, 0, 0}, 6, 52}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0, 0}, 52, 6, 18}));
EXPECT_EQ(c0_c0_child0.remaining_records[4],
(seqan::hibf::layout::layout::user_bin{19, std::vector<size_t>{0, 0, 0}, 6, 58}));
(seqan::hibf::layout::layout::user_bin{std::vector<size_t>{0, 0, 0}, 58, 6, 19}));
}
Loading

0 comments on commit a8966ca

Please sign in to comment.