takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
bam_file.hpp
Go to the documentation of this file.
1#ifndef TAKANE_BAM_FILE_HPP
2#define TAKANE_BAM_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 bam_file {
24
33inline void validate(const std::filesystem::path& path, const ObjectMetadata& metadata, Options& options) {
34 const std::string type_name = "bam_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 numbers taken from https://samtools.github.io/hts-specs/SAMv1.pdf
42 auto ipath = path / "file.bam";
43 internal_files::check_gzip_signature(ipath);
44 internal_files::check_signature<byteme::GzipFileReader>(ipath, "BAM\1", 4, "BAM");
45
46 auto ixpath = ipath;
47 ixpath += ".bai";
48 if (std::filesystem::exists(ixpath)) {
49 internal_files::check_signature(ixpath, "BAI\1", 4, "BAM index");
50 }
51
52 // Magic number taken from https://samtools.github.io/hts-specs/CSIv1.pdf
53 ixpath = ipath;
54 ixpath += ".csi";
55 if (std::filesystem::exists(ixpath)) {
56 internal_files::check_gzip_signature(ixpath);
57 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "CSI\1", 4, "CSI index");
58 }
59
60 if (options.bam_file_strict_check) {
61 options.bam_file_strict_check(path, metadata, options);
62 }
63}
64
65}
66
67}
68
69#endif
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition bam_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 &)> bam_file_strict_check
Definition utils_public.hpp:155