Skip to content

Commit

Permalink
[MISC] Update and extend prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
smehringer committed Aug 23, 2023
1 parent 203e333 commit 7817dc2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
4 changes: 2 additions & 2 deletions include/hibf/detail/layout/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct layout
requires std::derived_from<stream_type, std::ostream>
friend stream_type & operator<<(stream_type & stream, max_bin const & object)
{
stream << prefix::header << prefix::merged_bin << '_';
stream << prefix::layout_header << prefix::layout_lower_level << '_';
auto it = object.previous_TB_indices.begin();
auto end = object.previous_TB_indices.end();
// If not empty, we join with ';'
Expand All @@ -37,7 +37,7 @@ struct layout
while (++it != end)
stream << ';' << *it;
}
stream << " max_bin_id:" << object.id;
stream << " " << prefix::layout_fullest_technical_bin_idx << object.id;

return stream;
}
Expand Down
66 changes: 50 additions & 16 deletions include/hibf/detail/prefixes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,55 @@

namespace hibf::prefix
{

constexpr std::string_view chopper{"chopper"};

constexpr std::string_view header{"#"};

constexpr std::string_view header_config{"#"};

constexpr std::string_view high_level{"HIGH_LEVEL_IBF"};

constexpr std::string_view first_header_line{"#HIGH_LEVEL_IBF"};
static_assert(first_header_line.starts_with(header));
static_assert(first_header_line.ends_with(high_level));

constexpr std::string_view merged_bin{"MERGED_BIN"};

constexpr std::string_view split_bin{"SPLIT_BIN"};
/* These prefixes are for writing the layout file
* It is structured like this:
*
* [0) Possibly metadata added by chopper/raptor-layout]
* 1) Metadata: the hibf config
* 2) Layout header: max bin ids for the merged bins
* 3) Layout content: Assignment of user bin idx to technical bin idx
*
* And marked like this:
* [0) First character is @; Start and End of meta data should be marked accordingly to (1)]
* 1) First character is @; Start and End are marked by @HIBF_CONFIG and @HIBF_CONFIG_END respectively
* 2) First character is #;
* 3) No mark, plain content.
*
* Example:
*
* ```
* @CHOPPER_USER_BINS
* @0 /path/to/file1.fa
* @CHOPPER_USER_BINS_END
* @CHOPPER_CONFIG
* @0 k = 20
* @CHOPPER_CONFIG_END
*
* ``
*/

constexpr std::string_view meta_header{"@"};

constexpr std::string_view meta_hibf_config_start{"@HIBF_CONFIG"};
static_assert(meta_hibf_config_start.starts_with(meta_header));

constexpr std::string_view meta_hibf_config_end{"@HIBF_CONFIG_END"};
static_assert(meta_hibf_config_end.starts_with(meta_header));

constexpr std::string_view layout_header{"#"};

constexpr std::string_view layout_top_level{"TOP_LEVEL_IBF"};

constexpr std::string_view layout_lower_level{"LOWER_LEVEL_IBF"};

constexpr std::string_view layout_fullest_technical_bin_idx{"fullest_technical_bin_idx:"};

constexpr std::string_view layout_first_header_line{"#TOP_LEVEL_IBF"};
static_assert(layout_first_header_line.starts_with(layout_header));
static_assert(layout_first_header_line.ends_with(layout_top_level));

constexpr std::string_view layout_column_names{"#USER_BIN_IDX\tTECHNICAL_BIN_INDICES\tNUMBER_OF_TECHNICAL_BINS"};
static_assert(layout_column_names.starts_with(layout_header));

} // namespace hibf::prefix
6 changes: 3 additions & 3 deletions test/unit/hibf/detail/layout/layout_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ TEST(layout_test, printing_max_bins)
for (auto const & mb : layout.max_bins)
ss << mb << "\n";

std::string expected = R"mb(#MERGED_BIN_ max_bin_id:0
#MERGED_BIN_2 max_bin_id:2
#MERGED_BIN_1;2;3;4 max_bin_id:22
std::string expected = R"mb(#LOWER_LEVEL_IBF_ fullest_technical_bin_idx:0
#LOWER_LEVEL_IBF_2 fullest_technical_bin_idx:2
#LOWER_LEVEL_IBF_1;2;3;4 fullest_technical_bin_idx:22
)mb";

EXPECT_EQ(ss.str(), expected);
Expand Down

0 comments on commit 7817dc2

Please sign in to comment.