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& vstring = internal_json::extract_version_for_type(metadata.other, "bam_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://samtools.github.io/hts-specs/SAMv1.pdf
41 auto ipath = path / "file.bam";
42 internal_files::check_gzip_signature(ipath);
43 internal_files::check_signature<byteme::GzipFileReader>(ipath, "BAM\1", 4, "BAM");
44
45 auto ixpath = ipath;
46 ixpath += ".bai";
47 if (std::filesystem::exists(ixpath)) {
48 internal_files::check_signature(ixpath, "BAI\1", 4, "BAM index");
49 }
50
51 // Magic number taken from https://samtools.github.io/hts-specs/CSIv1.pdf
52 ixpath = ipath;
53 ixpath += ".csi";
54 if (std::filesystem::exists(ixpath)) {
55 internal_files::check_gzip_signature(ixpath);
56 internal_files::check_signature<byteme::GzipFileReader>(ixpath, "CSI\1", 4, "CSI index");
57 }
58
59 if (options.bam_file_strict_check) {
60 options.bam_file_strict_check(path, metadata, options);
61 }
62}
63
64}
65
66}
67
68#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