34 const std::string type_name =
"fastq_file";
35 const auto& fqmap = internal_json::extract_typed_object_from_metadata(metadata.
other, type_name);
37 const std::string version_name =
"version";
38 const std::string& vstring = internal_json::extract_string_from_typed_object(fqmap, version_name, type_name);
39 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
40 if (version.major != 1) {
41 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
44 internal_files::check_sequence_type(fqmap, type_name.c_str());
48 const std::string qtype_name =
"quality_type";
49 const std::string& qtype = internal_json::extract_string(fqmap, qtype_name, [&](std::exception& e) ->
void {
50 throw std::runtime_error(
"failed to extract 'fastq_file." + qtype_name +
"' from the object metadata; " + std::string(e.what()));
53 if (qtype ==
"phred") {
54 auto oIt = fqmap.find(
"quality_offset");
55 if (oIt == fqmap.end()) {
56 throw std::runtime_error(
"expected a 'fastq_file.quality_offset' property");
59 const auto& val = oIt->second;
60 if (val->type() != millijson::NUMBER) {
61 throw std::runtime_error(
"'fastq_file.quality_offset' property should be a JSON number");
64 double offset =
reinterpret_cast<const millijson::Number*
>(val.get())->value();
65 if (offset != 33 && offset != 64) {
66 throw std::runtime_error(
"'fastq_file.quality_offset' property should be either 33 or 64");
68 }
else if (qtype !=
"solexa") {
69 throw std::runtime_error(
"unknown value '" + qtype +
"' for the 'fastq_file." + qtype_name +
"' property");
74 bool indexed = internal_files::is_indexed(fqmap);
75 auto fpath = path /
"file.fastq.";
82 internal_files::check_gzip_signature(fpath);
84 auto reader = internal_other::open_reader<byteme::GzipFileReader>(fpath, byteme::GzipFileReaderOptions());
86 if (reader->read(
reinterpret_cast<unsigned char*
>(&first_val), 1) == 0 || first_val !=
'@') {
87 throw std::runtime_error(
"FASTQ file does not start with '@'");
92 auto fixpath = path /
"file.fastq.fai";
93 if (!std::filesystem::exists(fixpath)) {
94 throw std::runtime_error(
"missing FASTQ index file");
99 if (!std::filesystem::exists(ixpath)) {
100 throw std::runtime_error(
"missing BGZF index file");
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition fastq_file.hpp:33
std::function< void(const std::filesystem::path &, const ObjectMetadata &, Options &, bool)> fastq_file_strict_check
Definition utils_public.hpp:206