33 const auto& fqmap = internal_json::extract_typed_object_from_metadata(metadata.
other,
"fastq_file");
35 const std::string& vstring = internal_json::extract_string_from_typed_object(fqmap,
"version",
"fastq_file");
36 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
37 if (version.major != 1) {
38 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
41 internal_files::check_sequence_type(fqmap,
"fastq_file");
45 const std::string& qtype = internal_json::extract_string(fqmap,
"quality_type", [&](std::exception& e) ->
void {
46 throw std::runtime_error(
"failed to extract 'fastq_file.quality_type' from the object metadata; " + std::string(e.what()));
49 if (qtype ==
"phred") {
50 auto oIt = fqmap.find(
"quality_offset");
51 if (oIt == fqmap.end()) {
52 throw std::runtime_error(
"expected a 'fastq_file.quality_offset' property");
55 const auto& val = oIt->second;
56 if (val->type() != millijson::NUMBER) {
57 throw std::runtime_error(
"'fastq_file.quality_offset' property should be a JSON number");
60 double offset =
reinterpret_cast<const millijson::Number*
>(val.get())->value;
61 if (offset != 33 && offset != 64) {
62 throw std::runtime_error(
"'fastq_file.quality_offset' property should be either 33 or 64");
64 }
else if (qtype !=
"solexa") {
65 throw std::runtime_error(
"unknown value '" + qtype +
"' for the 'fastq_file.quality_type' property");
70 bool indexed = internal_files::is_indexed(fqmap);
71 auto fpath = path /
"file.fastq.";
78 internal_files::check_gzip_signature(fpath);
79 auto reader = internal_other::open_reader<byteme::GzipFileReader>(fpath, 10);
80 byteme::PerByte<> pb(&reader);
81 if (!pb.valid() || pb.get() !=
'@') {
82 throw std::runtime_error(
"FASTQ file does not start with '@'");
86 auto fixpath = path /
"file.fastq.fai";
87 if (!std::filesystem::exists(fixpath)) {
88 throw std::runtime_error(
"missing FASTQ index file");
93 if (!std::filesystem::exists(ixpath)) {
94 throw std::runtime_error(
"missing BGZF index file");
98 if (options.fastq_file_strict_check) {
99 options.fastq_file_strict_check(path, metadata, options, indexed);
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition fastq_file.hpp:32