1#ifndef SINGLEPP_LOADERS_RANKINGS_HPP
2#define SINGLEPP_LOADERS_RANKINGS_HPP
4#include "byteme/PerByte.hpp"
5#include "byteme/RawFileReader.hpp"
6#include "byteme/GzipFileReader.hpp"
7#include "byteme/ZlibBufferReader.hpp"
34template<
typename Value_ =
double,
typename Index_ =
int,
typename Rank_ =
int>
58template<
typename Value_,
typename Index_,
bool parallel_>
62 std::vector<int> values;
65 bool non_empty =
false;
68 bool has_nfeatures =
false;
69 auto check_nfeatures = [&]() ->
void {
72 nfeatures = field + 1;
73 }
else if (field + 1 != nfeatures) {
74 throw std::runtime_error(
"number of fields on each line should be equal to the number of features");
78 typename std::conditional<parallel_, byteme::PerByte<char>, byteme::PerByteParallel<char> >::type pb(&reader);
79 bool okay = pb.valid();
87 throw std::runtime_error(
"fields should not be empty");
89 values.push_back(current);
95 }
else if (x ==
',') {
97 throw std::runtime_error(
"fields should not be empty");
99 values.push_back(current);
104 }
else if (std::isdigit(x)) {
107 current += (x -
'0');
110 throw std::runtime_error(
"fields should only contain integer ranks");
114 if (field || non_empty) {
117 throw std::runtime_error(
"fields should not be empty");
119 values.push_back(current);
126template<
typename Value_,
typename Index_>
155template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
158 return internal::load_rankings<Value_, Index_>(
reader,
options.parallel);
173template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
176 return internal::load_rankings<Value_, Index_>(
reader,
options.parallel);
192template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
195 return internal::load_rankings<Value_, Index_>(
reader,
options.parallel);
Load pre-processed single reference datasets.
Definition labels.hpp:23
tatami::DenseMatrix< Value_, Index_, std::vector< Rank_ > > RankMatrix
Definition rankings.hpp:35
RankMatrix< Value_, Index_ > load_rankings_from_zlib_buffer(const unsigned char *buffer, size_t len, const LoadRankingsOptions &options)
Definition rankings.hpp:193
RankMatrix< Value_, Index_ > load_rankings_from_text_file(const char *path, const LoadRankingsOptions &options)
Definition rankings.hpp:156
RankMatrix< Value_, Index_ > load_rankings_from_gzip_file(const char *path, const LoadRankingsOptions &options)
Definition rankings.hpp:174
Options for loading rankings.
Definition rankings.hpp:40
bool parallel
Definition rankings.hpp:44
size_t buffer_size
Definition rankings.hpp:49