84 uint64_t total_sets = 0;
86 auto coll_info = internal::load_ranges_with_sizes(prefix +
"collections.tsv.ranges.gz");
87 internal::check_collection_details(prefix +
"collections.tsv", coll_info.first, coll_info.second);
88 constexpr uint64_t limit = std::numeric_limits<uint64_t>::max();
89 for (
auto x : coll_info.second) {
90 if (limit - total_sets < x) {
91 throw std::runtime_error(
"64-bit unsigned integer overflow for the sum of the number of sets in 'collections.tsv.ranges.gz'");
97 std::vector<uint64_t> set_sizes;
99 auto set_info = internal::load_ranges_with_sizes(prefix +
"sets.tsv.ranges.gz");
100 if (
static_cast<uint64_t
>(set_info.first.size()) != total_sets) {
101 throw std::runtime_error(
"total number of sets in 'sets.tsv' does not match with the reported number from 'collections.tsv.ranges.gz'");
103 set_sizes.swap(set_info.second);
105 std::unordered_map<std::string, std::vector<uint64_t> > token_n, token_d;
106 internal::check_set_details(
110 [&](uint64_t line,
const std::string& name,
const std::string& description) {
111 internal::tokenize(line, name, token_n);
112 internal::tokenize(line, description, token_d);
117 for (
int tt = 0; tt < 2; ++tt) {
118 std::string type = (tt == 0 ?
"names" :
"descriptions");
119 const auto& tokens = (tt == 0 ? token_n : token_d);
121 auto path =
"tokens-" + type +
".tsv";
122 auto ranges_path = path +
".ranges.gz";
123 auto tok_info = internal::load_named_ranges(prefix + ranges_path);
124 internal::check_tokens(tok_info.first, ranges_path);
125 if (tok_info.first.size() != tokens.size()) {
126 throw std::runtime_error(
"different number of tokens from " + type +
" between '" + ranges_path +
"' and 'sets.tsv'");
129 internal::check_indices<false>(
133 [&](uint64_t line,
const std::vector<uint64_t>& indices) {
134 const auto& tok = tok_info.first[line];
135 auto tIt = tokens.find(tok);
136 if (tIt == tokens.end()) {
137 throw std::runtime_error(
"token '" + tok +
"' in '" + ranges_path +
"' is not present in " + type +
" in 'sets.tsv'");
139 if (!internal::same_vectors(tIt->second, indices)) {
140 throw std::runtime_error(
"sets for token '" + tok +
"' in '" + path +
"' are inconsistent with " + type +
" in 'sets.tsv'");
148 std::vector<std::vector<uint64_t> > reverse_map(num_genes);
150 auto s2g_info = internal::load_ranges(prefix +
"set2gene.tsv.ranges.gz");
151 if (s2g_info.size() !=
static_cast<size_t>(total_sets)) {
152 throw std::runtime_error(
"number of lines in 'set2gene.tsv.ranges.gz' does not match the total number of sets");
155 internal::check_indices<true>(
156 prefix +
"set2gene.tsv",
159 [&](uint64_t line,
const std::vector<uint64_t>& indices) {
160 if (
static_cast<uint64_t
>(indices.size()) != set_sizes[line]) {
161 throw std::runtime_error(
"size of set " + std::to_string(line) +
" from 'sets.tsv.ranges.gz' does not match with that in 'set2gene.tsv'");
163 for (
auto i : indices) {
164 reverse_map[i].push_back(line);
172 auto g2s_info = internal::load_ranges(prefix +
"gene2set.tsv.ranges.gz");
173 if (g2s_info.size() !=
static_cast<size_t>(num_genes)) {
174 throw std::runtime_error(
"number of lines in 'gene2set.tsv.ranges.gz' does not match the total number of genes");
177 internal::check_indices<true>(
178 prefix +
"gene2set.tsv",
181 [&](uint64_t line,
const std::vector<uint64_t>& indices) {
182 if (!internal::same_vectors(reverse_map[line], indices)) {
183 throw std::runtime_error(
"sets for gene " + std::to_string(line) +
" in 'gene2set.tsv' are inconsistent with 'set2gene.tsv'");