33 const std::string type_name =
"fastq_file";
34 const auto& fqmap = internal_json::extract_typed_object_from_metadata(metadata.
other, type_name);
36 const std::string version_name =
"version";
37 const std::string& vstring = internal_json::extract_string_from_typed_object(fqmap, version_name, type_name);
38 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
39 if (version.major != 1) {
40 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
43 internal_files::check_sequence_type(fqmap, type_name.c_str());
47 const std::string qtype_name =
"quality_type";
48 const std::string& qtype = internal_json::extract_string(fqmap, qtype_name, [&](std::exception& e) ->
void {
49 throw std::runtime_error(
"failed to extract 'fastq_file." + qtype_name +
"' from the object metadata; " + std::string(e.what()));
52 if (qtype ==
"phred") {
53 auto oIt = fqmap.find(
"quality_offset");
54 if (oIt == fqmap.end()) {
55 throw std::runtime_error(
"expected a 'fastq_file.quality_offset' property");
58 const auto& val = oIt->second;
59 if (val->type() != millijson::NUMBER) {
60 throw std::runtime_error(
"'fastq_file.quality_offset' property should be a JSON number");
63 double offset =
reinterpret_cast<const millijson::Number*
>(val.get())->value;
64 if (offset != 33 && offset != 64) {
65 throw std::runtime_error(
"'fastq_file.quality_offset' property should be either 33 or 64");
67 }
else if (qtype !=
"solexa") {
68 throw std::runtime_error(
"unknown value '" + qtype +
"' for the 'fastq_file." + qtype_name +
"' property");
73 bool indexed = internal_files::is_indexed(fqmap);
74 auto fpath = path /
"file.fastq.";
81 internal_files::check_gzip_signature(fpath);
82 auto reader = internal_other::open_reader<byteme::GzipFileReader>(fpath, 10);
83 byteme::PerByte<> pb(&reader);
84 if (!pb.valid() || pb.get() !=
'@') {
85 throw std::runtime_error(
"FASTQ file does not start with '@'");
89 auto fixpath = path /
"file.fastq.fai";
90 if (!std::filesystem::exists(fixpath)) {
91 throw std::runtime_error(
"missing FASTQ index file");
96 if (!std::filesystem::exists(ixpath)) {
97 throw std::runtime_error(
"missing BGZF index file");
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition fastq_file.hpp:32
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> fastq_file_strict_check
Definition utils_public.hpp:207