takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
bcf_file.hpp
Go to the documentation of this file.
1#ifndef TAKANE_BCF_FILE_HPP
2#define TAKANE_BCF_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 bcf_file {
24
33inline void validate(const std::filesystem::path& path, const ObjectMetadata& metadata, Options& options) {
34 const std::string type_name = "bcf_file"; // use a separate variable to avoid dangling reference warnings from GCC.
35 const std::string& vstring = internal_json::extract_version_for_type(metadata.other, type_name);
36 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(), /* skip_patch = */ true);
37 if (version.major != 1) {
38 throw std::runtime_error("unsupported version string '" + vstring + "'");
39 }
40
41 // Magic number taken from https://samtools.github.io/hts-specs/BCFv2_qref.pdf
42 // We relax it a little to support both BCF1 and BCF2+ formats.
43 auto ipath = path / "file.bcf";
44 internal_files::check_gzip_signature(ipath);
45 internal_files::check_signature<byteme::GzipFileReader>(ipath, "BCF", 3, "BCF");
46
47 // Magic number taken from https://samtools.github.io/hts-specs/tabix.pdf
48 auto ixpath = ipath;
49 ixpath += ".tbi";
50 if (std::filesystem::exists(ixpath)) {
51 internal_files::check_gzip_signature(ixpath);
52 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "TBI\1", 4, "tabix");
53 }
54
55 // Magic number taken from https://samtools.github.io/hts-specs/CSIv1.pdf
56 ixpath = ipath;
57 ixpath += ".csi";
58 if (std::filesystem::exists(ixpath)) {
59 internal_files::check_gzip_signature(ixpath);
60 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "CSI\1", 4, "CSI index");
61 }
62
63 if (options.bcf_file_strict_check) {
64 options.bcf_file_strict_check(path, metadata, options);
65 }
66}
67
68}
69
70}
71
72#endif
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition bcf_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 &)> bcf_file_strict_check
Definition utils_public.hpp:162