Skip to content

Commit

Permalink
Merge branch 'feature/format_read_as_string' into 'master'
Browse files Browse the repository at this point in the history
Format a read id as a string

See merge request minknow/mkr-file-format!15
  • Loading branch information
0x55555555 committed May 10, 2022
2 parents 7a024bd + fc8e909 commit 1d947e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions c++/mkr_format/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <arrow/array/array_primitive.h>
#include <arrow/memory_pool.h>
#include <arrow/type.h>
#include <boost/uuid/uuid_io.hpp>

#include <chrono>
#include <iostream>
Expand Down Expand Up @@ -962,6 +963,26 @@ mkr_error_t mkr_vbz_decompress_signal(char const* compressed_signal,

return MKR_OK;
}

mkr_error_t mkr_format_read_id(uint8_t* read_id, char* read_id_string) {
mkr_reset_error();

if (!check_not_null(read_id) || !check_output_pointer_not_null(read_id_string)) {
return g_mkr_error_no;
}

boost::uuids::uuid* uuid_data = reinterpret_cast<boost::uuids::uuid*>(read_id);
std::string string_data = boost::uuids::to_string(*uuid_data);
if (string_data.size() != 36) {
mkr_set_error(mkr::Status::Invalid("Unexpected length of UUID"));
return g_mkr_error_no;
}

std::copy(string_data.begin(), string_data.end(), read_id_string);
read_id_string[string_data.size()] = '\0';

return MKR_OK;
}
}

//---------------------------------------------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions c++/mkr_format/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,15 @@ MKR_FORMAT_EXPORT mkr_error_t mkr_vbz_decompress_signal(char const* compressed_s
size_t sample_count,
short* signal_out);

//---------------------------------------------------------------------------------------------------------------------
// Global state
//---------------------------------------------------------------------------------------------------------------------

/// \brief Format a packed binary read id as a readable read id string:
/// \param read_id A 16 byte binary formatted UUID.
/// \param[out] read_id_string Output string containing the string formatted UUID (expects a string of at least 37 bytes, one null byte is written.)
MKR_FORMAT_EXPORT mkr_error_t mkr_format_read_id(uint8_t* read_id, char* read_id_string);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions c++/test/c_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <boost/filesystem.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <catch2/catch.hpp>
#include <gsl/gsl-lite.hpp>

Expand Down Expand Up @@ -136,6 +137,11 @@ SCENARIO("C API") {
&median_before, &end_reason, &run_info,
&signal_row_count) == MKR_OK);

std::string formatted_uuid(36, '\0');
CHECK(mkr_format_read_id((uint8_t*)read_id.begin(), &formatted_uuid[0]) == MKR_OK);
CHECK(formatted_uuid.size() == boost::uuids::to_string(read_id).size());
CHECK(formatted_uuid == boost::uuids::to_string(read_id));

CHECK(read_number == 12);
CHECK(start_sample == 10245);
CHECK(median_before == 200.0f);
Expand Down

0 comments on commit 1d947e7

Please sign in to comment.