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& vstring = internal_json::extract_version_for_type(metadata.other, "bcf_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 number taken from https://samtools.github.io/hts-specs/BCFv2_qref.pdf
41 // We relax it a little to support both BCF1 and BCF2+ formats.
42 auto ipath = path / "file.bcf";
43 internal_files::check_gzip_signature(ipath);
44 internal_files::check_signature<byteme::GzipFileReader>(ipath, "BCF", 3, "BCF");
45
46 // Magic number taken from https://samtools.github.io/hts-specs/tabix.pdf
47 auto ixpath = ipath;
48 ixpath += ".tbi";
49 if (std::filesystem::exists(ixpath)) {
50 internal_files::check_gzip_signature(ixpath);
51 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "TBI\1", 4, "tabix");
52 }
53
54 // Magic number taken from https://samtools.github.io/hts-specs/CSIv1.pdf
55 ixpath = ipath;
56 ixpath += ".csi";
57 if (std::filesystem::exists(ixpath)) {
58 internal_files::check_gzip_signature(ixpath);
59 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "CSI\1", 4, "CSI index");
60 }
61
62 if (options.bcf_file_strict_check) {
63 options.bcf_file_strict_check(path, metadata, options);
64 }
65}
66
67}
68
69}
70
71#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