takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
bigbed_file.hpp
Go to the documentation of this file.
1#ifndef TAKANE_BIGBED_FILE_HPP
2#define TAKANE_BIGBED_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 bigbed_file {
24
33inline void validate(const std::filesystem::path& path, const ObjectMetadata& metadata, Options& options) {
34 const std::string& vstring = internal_json::extract_version_for_type(metadata.other, "bigbed_file");
35 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(), /* skip_patch = */ true);
36 if (version.major != 1) {
37 throw std::runtime_error("unsupported version string '" + vstring + "'");
38 }
39
40 // Magic numbers taken from https://data.broadinstitute.org/igv/projects/downloads/2.1/IGVDistribution_2.1.11/src/org/broad/igv/bbfile/BBFileHeader.java,
41 // which seems to use the magic number to detect endianness of the file as well.
42 auto ipath = path / "file.bb";
43 std::array<unsigned char, 4> store;
44 internal_files::extract_signature(ipath, store.data(), store.size());
45
46 std::array<unsigned char, 4> be_magic { 0xEB, 0xF2, 0x89, 0x87 };
47 std::array<unsigned char, 4> le_magic { 0x87, 0x89, 0xF2, 0xEB };
48 if (store != be_magic && store != le_magic) {
49 throw std::runtime_error("incorrect bigBed file signature for '" + ipath.string() + "'");
50 }
51
52 if (options.bigbed_file_strict_check) {
53 options.bigbed_file_strict_check(path, metadata, options);
54 }
55}
56
57}
58
59}
60
61#endif
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition bigbed_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
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &)> bigbed_file_strict_check
Definition utils_public.hpp:177