takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
utils_public.hpp
Go to the documentation of this file.
1#ifndef TAKANE_UTILS_PUBLIC_HPP
2#define TAKANE_UTILS_PUBLIC_HPP
3
4#include <string>
5#include <filesystem>
6#include <unordered_map>
7#include <functional>
8
9#include "H5Cpp.h"
10
11#include "millijson/millijson.hpp"
12#include "chihaya/chihaya.hpp"
13#include "utils_json.hpp"
14
20namespace takane {
21
29 std::string type;
30
34 std::unordered_map<std::string, std::shared_ptr<millijson::Base> > other;
35};
36
44inline ObjectMetadata reformat_object_metadata(millijson::Base* raw) {
45 if (raw->type() != millijson::OBJECT) {
46 throw std::runtime_error("metadata should be a JSON object");
47 }
48
49 ObjectMetadata output;
50 output.other = std::move(reinterpret_cast<millijson::Object*>(raw)->value());
51
52 auto tIt = output.other.find("type");
53 if (tIt == output.other.end()) {
54 throw std::runtime_error("metadata should have a 'type' property");
55 }
56
57 const auto& tval = tIt->second;
58 if (tval->type() != millijson::STRING) {
59 throw std::runtime_error("metadata should have a 'type' string");
60 }
61
62 output.type = std::move(reinterpret_cast<millijson::String*>(tval.get())->value());
63 output.other.erase(tIt);
64 return output;
65}
66
73inline ObjectMetadata read_object_metadata(const std::filesystem::path& path) try {
74 std::shared_ptr<millijson::Base> obj = internal_json::parse_file(path / "OBJECT");
75 return reformat_object_metadata(obj.get());
76} catch (std::exception& e) {
77 throw std::runtime_error("failed to read the OBJECT file at '" + path.string() + "'; " + std::string(e.what()));
78}
79
93struct Options {
97 bool parallel_reads = true;
98
102 hsize_t hdf5_buffer_size = 10000;
103
104public:
110 std::unordered_map<std::string, std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> > custom_validate;
111
116 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> custom_global_validate;
117
118public:
124 std::unordered_map<std::string, std::function<std::vector<size_t>(const std::filesystem::path&, const ObjectMetadata&, Options&)> > custom_dimensions;
125
131 std::unordered_map<std::string, std::function<size_t(const std::filesystem::path&, const ObjectMetadata& m, Options&)> > custom_height;
132
133public:
139 std::unordered_map<std::string, std::unordered_set<std::string> > custom_derived_from;
140
146 std::unordered_map<std::string, std::unordered_set<std::string> > custom_satisfies_interface;
147
148public:
154 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> bam_file_strict_check;
155
161 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> bcf_file_strict_check;
162
169 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&, bool)> bed_file_strict_check;
170
176 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> bigbed_file_strict_check;
177
183 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> bigwig_file_strict_check;
184
190 std::function<bool(const std::filesystem::path&, const ObjectMetadata&, Options& options)> data_frame_factor_any_duplicated;
191
198 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&, bool)> fasta_file_strict_check;
199
206 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&, bool)> fastq_file_strict_check;
207
214 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&, bool)> gff_file_strict_check;
215
221 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> gmt_file_strict_check;
222
228 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> rds_file_strict_check;
229
233 chihaya::Options delayed_array_options;
234
240 std::function<void(const std::filesystem::path&, const ObjectMetadata&, Options&)> image_file_strict_check;
241
242};
243
244}
245
246#endif
takane validation functions.
Definition _derived_from.hpp:15
ObjectMetadata read_object_metadata(const std::filesystem::path &path)
Definition utils_public.hpp:73
ObjectMetadata reformat_object_metadata(millijson::Base *raw)
Definition utils_public.hpp:44
Object metadata, including the type and other fields.
Definition utils_public.hpp:25
std::unordered_map< std::string, std::shared_ptr< millijson::Base > > other
Definition utils_public.hpp:34
std::string type
Definition utils_public.hpp:29
Validation options.
Definition utils_public.hpp:93
chihaya::Options delayed_array_options
Definition utils_public.hpp:233
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> bigwig_file_strict_check
Definition utils_public.hpp:183
bool parallel_reads
Definition utils_public.hpp:97
std::unordered_map< std::string, std::unordered_set< std::string > > custom_satisfies_interface
Definition utils_public.hpp:146
std::unordered_map< std::string, std::function< size_t(const std::filesystem::path &, const ObjectMetadata &m, Options &)> > custom_height
Definition utils_public.hpp:131
hsize_t hdf5_buffer_size
Definition utils_public.hpp:102
std::function< bool(const std::filesystem::path &, const ObjectMetadata &, Options &options)> data_frame_factor_any_duplicated
Definition utils_public.hpp:190
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> image_file_strict_check
Definition utils_public.hpp:240
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> bam_file_strict_check
Definition utils_public.hpp:154
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> gmt_file_strict_check
Definition utils_public.hpp:221
std::unordered_map< std::string, std::function< std::vector< size_t >(const std::filesystem::path &, const ObjectMetadata &, Options &)> > custom_dimensions
Definition utils_public.hpp:124
std::unordered_map< std::string, std::unordered_set< std::string > > custom_derived_from
Definition utils_public.hpp:139
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> gff_file_strict_check
Definition utils_public.hpp:214
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> bcf_file_strict_check
Definition utils_public.hpp:161
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> bigbed_file_strict_check
Definition utils_public.hpp:176
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> fastq_file_strict_check
Definition utils_public.hpp:206
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> custom_global_validate
Definition utils_public.hpp:116
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> rds_file_strict_check
Definition utils_public.hpp:228
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> fasta_file_strict_check
Definition utils_public.hpp:198
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> bed_file_strict_check
Definition utils_public.hpp:169
std::unordered_map< std::string, std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> > custom_validate
Definition utils_public.hpp:110