1#ifndef TAKANE_DATA_FRAME_FACTOR_HPP
2#define TAKANE_DATA_FRAME_FACTOR_HPP
8#include "ritsuko/hdf5/hdf5.hpp"
11#include "utils_string.hpp"
12#include "utils_factor.hpp"
13#include "utils_json.hpp"
14#include "utils_other.hpp"
26void validate(
const std::filesystem::path&,
const ObjectMetadata&, Options&);
27size_t height(
const std::filesystem::path&,
const ObjectMetadata&, Options&);
37namespace data_frame_factor {
48 const auto& vstring = internal_json::extract_version_for_type(metadata.
other,
"data_frame_factor");
49 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
50 if (version.major != 1) {
51 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
55 auto lpath = path /
"levels";
58 throw std::runtime_error(
"expected 'levels' to be an object that satifies the 'DATA_FRAME' interface");
63 }
catch (std::exception& e) {
64 throw std::runtime_error(
"failed to validate 'levels'; " + std::string(e.what()));
70 throw std::runtime_error(
"'levels' should not contain duplicated rows");
74 auto handle = ritsuko::hdf5::open_file(path /
"contents.h5");
75 auto ghandle = ritsuko::hdf5::open_group(handle,
"data_frame_factor");
76 size_t num_codes = internal_factor::validate_factor_codes(ghandle,
"codes", num_levels, options.
hdf5_buffer_size,
false);
78 internal_other::validate_mcols(path,
"element_annotations", num_codes, options);
79 internal_other::validate_metadata(path,
"other_annotations", options);
81 internal_string::validate_names(ghandle,
"names", num_codes, options.
hdf5_buffer_size);
91 auto handle = ritsuko::hdf5::open_file(path /
"contents.h5");
92 auto ghandle = handle.openGroup(
"data_frame_factor");
93 auto dhandle = ghandle.openDataSet(
"codes");
94 return ritsuko::hdf5::get_1d_length(dhandle.getSpace(),
false);
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition data_frame_factor.hpp:47
size_t height(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition data_frame_factor.hpp:90
takane validation functions.
Definition _derived_from.hpp:15
size_t height(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition _height.hpp:88
bool satisfies_interface(const std::string &type, const std::string &interface, const Options &options)
Definition _satisfies_interface.hpp:67
ObjectMetadata read_object_metadata(const std::filesystem::path &path)
Definition utils_public.hpp:74
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition _validate.hpp:107
Validation options.
Definition utils_public.hpp:94
hsize_t hdf5_buffer_size
Definition utils_public.hpp:103
std::function< bool(const std::filesystem::path &, const ObjectMetadata &, Options &options)> data_frame_factor_any_duplicated
Definition utils_public.hpp:191