31 const std::string type_name =
"sequence_information";
34 const auto& type_meta = extract_json_object(metadata.
other, type_name);
36 const auto& vstring = extract_json_version_string(type_meta);
37 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
38 if (version.major != 1) {
39 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
42 std::throw_with_nested(std::runtime_error(
"failed to read 'version'"));
45 std::throw_with_nested(std::runtime_error(
"failed to validate 'sequence_information' in the object metadata"));
49 H5::H5File handle(path /
"info.h5", H5F_ACC_RDONLY);
50 auto ghandle = handle.openGroup(type_name);
54 auto nhandle = ghandle.openDataSet(
"name");
55 if (!ritsuko::hdf5::is_utf8_string(nhandle)) {
56 throw std::runtime_error(
"expected a datatype that can be represented by a UTF-8 encoded string");
59 auto nspace = nhandle.getSpace();
60 if (nspace.getSimpleExtentNdims() != 1) {
61 throw std::runtime_error(
"expected a 1-dimensional dataset");
63 nspace.getSimpleExtentDims(&nseq);
65 ritsuko::hdf5::Stream1dStringDataset stream(
69 ritsuko::hdf5::Stream1dStringDatasetOptions opt;
75 std::unordered_set<std::string> collected;
76 iterate_stream<std::string>(
78 [&](hsize_t, std::string x) ->
void {
79 if (collected.find(x) != collected.end()) {
80 throw std::runtime_error(
"detected duplicated sequence name '" + x +
"'");
82 collected.insert(std::move(x));
86 std::throw_with_nested(std::runtime_error(
"failed to validate 'name'"));
90 auto lhandle = ghandle.openDataSet(
"length");
91 if (ritsuko::hdf5::exceeds_integer_limit(lhandle, 64,
false)) {
92 throw std::runtime_error(
"expected a datatype that fits in a 64-bit unsigned integer");
95 auto lspace = lhandle.getSpace();
96 if (lspace.getSimpleExtentNdims() != 1) {
97 throw std::runtime_error(
"expected a 1-dimensional dataset");
100 lspace.getSimpleExtentDims(&nlen);
102 throw std::runtime_error(
"dataset extent should the same as that of 'name'");
105 validate_numeric_missing_placeholder(lhandle,
"missing-value-placeholder");
107 std::throw_with_nested(std::runtime_error(
"failed to validate 'length'"));
111 auto chandle = ghandle.openDataSet(
"circular");
112 if (ritsuko::hdf5::exceeds_integer_limit(chandle, 32,
true)) {
113 throw std::runtime_error(
"expected a datatype that fits in a 32-bit signed integer");
116 auto cspace = chandle.getSpace();
117 if (cspace.getSimpleExtentNdims() != 1) {
118 throw std::runtime_error(
"expected a 1-dimensional dataset");
121 cspace.getSimpleExtentDims(&ncirc);
123 throw std::runtime_error(
"dataset extent should the same as that of 'name'");
126 validate_numeric_missing_placeholder(chandle,
"missing-value-placeholder");
128 std::throw_with_nested(std::runtime_error(
"failed to validate 'circular'"));
132 auto gnhandle = ghandle.openDataSet(
"genome");
133 if (!ritsuko::hdf5::is_utf8_string(gnhandle)) {
134 throw std::runtime_error(
"expected a datatype that can be represented by a UTF-8 encoded string");
137 auto gnspace = gnhandle.getSpace();
138 if (gnspace.getSimpleExtentNdims() != 1) {
139 throw std::runtime_error(
"expected a 1-dimensional dataset");
142 gnspace.getSimpleExtentDims(&ngen);
144 throw std::runtime_error(
"dataset extent should the same as that of 'name'");
147 validate_string_missing_placeholder(gnhandle,
"missing-value-placeholder");
149 std::throw_with_nested(std::runtime_error(
"failed to validate 'circular'"));
152 std::throw_with_nested(std::runtime_error(
"failed to validate 'sequence_information' in 'info.h5'"));