takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
bed_file.hpp
Go to the documentation of this file.
1#ifndef TAKANE_BED_FILE_HPP
2#define TAKANE_BED_FILE_HPP
3
4#include "utils_files.hpp"
5
6#include "ritsuko/ritsuko.hpp"
7
8#include <filesystem>
9#include <stdexcept>
10#include <string>
11
17namespace takane {
18
23namespace bed_file {
24
33inline void validate(const std::filesystem::path& path, const ObjectMetadata& metadata, [[maybe_unused]] Options& options) {
34 const auto& bedmap = internal_json::extract_typed_object_from_metadata(metadata.other, "bed_file");
35
36 const std::string& vstring = internal_json::extract_string_from_typed_object(bedmap, "version", "bed_file");
37 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(), /* skip_patch = */ true);
38 if (version.major != 1) {
39 throw std::runtime_error("unsupported version string '" + vstring + "'");
40 }
41
42 // Check if it's indexed.
43 bool indexed = internal_files::is_indexed(bedmap);
44 auto fpath = path / "file.bed.";
45 if (indexed) {
46 fpath += "bgz";
47 } else {
48 fpath += "gz";
49 }
50
51 internal_files::check_gzip_signature(fpath);
52
53 if (indexed) {
54 auto ixpath = fpath;
55 ixpath += ".tbi";
56 internal_files::check_gzip_signature(ixpath);
57 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "TBI\1", 4, "tabix");
58 }
59
60 if (options.bed_file_strict_check) {
61 options.bed_file_strict_check(path, metadata, options, indexed);
62 }
63}
64
65}
66
67}
68
69#endif
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition bed_file.hpp:33
takane validation functions.
Definition _derived_from.hpp:15
Object metadata, including the type and other fields.
Definition utils_public.hpp:26
std::unordered_map< std::string, std::shared_ptr< millijson::Base > > other
Definition utils_public.hpp:35
Validation options.
Definition utils_public.hpp:94