Skip to content

Commit

Permalink
[FIX] Make it throw
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jun 3, 2024
1 parent b14cc34 commit e836084
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/util/display_layout/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ int execute(config const & cfg)
std::vector<uint64_t> current_kmers{};
// How many user bins are stored in the current technical bin? Always 1 for split bins.
size_t const ub_count{chunk.size()};
// The current technical bin is a merged bin if it contains more than one user bin or if the (only) user bin
// has previous technical bins.
bool const is_merged{ub_count > 1u || hibf_layout.user_bins[chunk[0]].previous_TB_indices.size() != 0};
bool const is_merged{ub_count > 1u};
bool const has_lower_level = hibf_layout.user_bins[chunk[0]].previous_TB_indices.size() != 0;
if (!(is_merged ^ has_lower_level))
throw std::logic_error{"Invalid Layout: There is a merged bin that only consists of a single user bin."};

for (size_t const ub_index : chunk)
{
Expand Down Expand Up @@ -328,8 +329,7 @@ int execute(config const & cfg)
progress.report();
}

// Into how many techincal bins is the user bin split? Always 1 for merged bins. If it is a split bin,
// there is only one user bin.
// Into how many techincal bins is the user bin split? Always 1 for merged bins.
size_t const split_count{is_merged ? 1u : hibf_layout.user_bins[chunk[0]].number_of_technical_bins};
size_t const avg_kmer_count = (current_kmer_set.size() + split_count - 1u) / split_count;
size_t const sketch_estimate = (sketch.estimate() + split_count - 1u) / split_count;
Expand Down
44 changes: 44 additions & 0 deletions test/cli/util_display_layout_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,50 @@ TEST_F(cli_test, display_layout_general)
EXPECT_EQ(expected_general_file, actual_file);
}

TEST_F(cli_test, display_layout_general_throw_invalid_layout)
{
std::string const seq1_filename = data("seq1.fa");
std::string const seq2_filename = data("seq2.fa");
std::string const seq3_filename = data("seq3.fa");
std::string const small_filename = data("small.fa");
seqan3::test::tmp_directory tmp_dir{};
std::filesystem::path const layout_filename{tmp_dir.path() / "small.layout"};
std::filesystem::path const general_filename{tmp_dir.path() / "small.layout.general"};

{
std::ofstream fout{layout_filename};
std::string content = get_layout_with_correct_filenames(seq1_filename,
seq2_filename,
seq3_filename,
small_filename,
layout_filename.string());
size_t const last_header_line_start = content.rfind('#');
size_t const last_header_line_end = content.find('\n', last_header_line_start);
ASSERT_GT(content.size(), last_header_line_end);
content.erase(last_header_line_end + 1u);
content += "0\t0\t1\n"
"1\t1;0\t1;64\n"
"2\t2\t1\n"
"3\t3\t2\n";
fout << content;
}

ASSERT_TRUE(std::filesystem::exists(layout_filename));

cli_test_result result = execute_app("display_layout",
"general",
"--input",
layout_filename.c_str(),
"--output",
general_filename.c_str());

ASSERT_NE(result.exit_code, 0) << "PWD: " << result.pwd << "\nCMD: " << result.command;
EXPECT_EQ(result.out, std::string{});
EXPECT_TRUE(result.err.find("Invalid Layout: There is a merged bin that only consists of a single user bin.")
!= std::string::npos)
<< result.err;
}

TEST_F(cli_test, display_layout_general_with_shared_kmers)
{
std::string const seq1_filename = data("seq1.fa");
Expand Down

0 comments on commit e836084

Please sign in to comment.