1#ifndef TAKANE_SUMMARIZED_EXPERIMENT_HPP
2#define TAKANE_SUMMARIZED_EXPERIMENT_HPP
4#include "millijson/millijson.hpp"
5#include "byteme/byteme.hpp"
8#include "utils_other.hpp"
9#include "utils_summarized_experiment.hpp"
25void validate(
const std::filesystem::path&,
const ObjectMetadata&, Options& options);
26size_t height(
const std::filesystem::path&,
const ObjectMetadata&, Options& options);
27std::vector<size_t>
dimensions(
const std::filesystem::path&,
const ObjectMetadata&, Options& options);
37namespace summarized_experiment {
45 const auto& semap = internal_json::extract_typed_object_from_metadata(metadata.
other,
"summarized_experiment");
47 const std::string& vstring = internal_json::extract_string_from_typed_object(semap,
"version",
"summarized_experiment");
48 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
49 if (version.major != 1) {
50 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
54 auto dims = internal_summarized_experiment::extract_dimensions_json(semap,
"summarized_experiment");
55 size_t num_rows = dims.first;
56 size_t num_cols = dims.second;
60 auto adir = path /
"assays";
61 if (std::filesystem::exists(adir)) {
62 size_t num_assays = internal_summarized_experiment::check_names_json(adir);
63 for (
size_t i = 0; i < num_assays; ++i) {
64 auto aname = std::to_string(i);
65 auto apath = adir / aname;
70 if (dims.size() < 2) {
71 throw std::runtime_error(
"object in 'assays/" + aname +
"' should have two or more dimensions");
73 if (dims[0] != num_rows) {
74 throw std::runtime_error(
"object in 'assays/" + aname +
"' should have the same number of rows as its parent '" + metadata.
type +
"'");
76 if (dims[1] != num_cols) {
77 throw std::runtime_error(
"object in 'assays/" + aname +
"' should have the same number of columns as its parent '" + metadata.
type +
"'");
81 size_t num_dir_obj = internal_other::count_directory_entries(adir);
82 if (num_dir_obj - 1 != num_assays) {
83 throw std::runtime_error(
"more objects than expected inside the 'assays' subdirectory");
87 auto rd_path = path /
"row_data";
88 if (std::filesystem::exists(rd_path)) {
91 throw std::runtime_error(
"object in 'row_data' should satisfy the 'DATA_FRAME' interface");
95 throw std::runtime_error(
"data frame at 'row_data' should have number of rows equal to that of the '" + metadata.
type +
"'");
99 auto cd_path = path /
"column_data";
100 if (std::filesystem::exists(cd_path)) {
103 throw std::runtime_error(
"object in 'column_data' should satisfy the 'DATA_FRAME' interface");
107 throw std::runtime_error(
"data frame at 'column_data' should have number of rows equal to the number of columns of its parent '" + metadata.
type +
"'");
111 internal_other::validate_metadata(path,
"other_data", options);
122 const auto& semap = internal_json::extract_object(metadata.
other,
"summarized_experiment");
123 auto dims = internal_summarized_experiment::extract_dimensions_json(semap,
"summarized_experiment");
135 const auto& semap = internal_json::extract_object(metadata.
other,
"summarized_experiment");
136 auto dims = internal_summarized_experiment::extract_dimensions_json(semap,
"summarized_experiment");
137 return std::vector<size_t>{ dims.first, dims.second };
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition summarized_experiment.hpp:44
std::vector< size_t > dimensions(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition summarized_experiment.hpp:133
size_t height(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition summarized_experiment.hpp:120
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
std::vector< size_t > dimensions(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition _dimensions.hpp:69
Validation options.
Definition utils_public.hpp:94