1#ifndef SINGLEPP_LOADERS_MARKERS_HPP
2#define SINGLEPP_LOADERS_MARKERS_HPP
4#include "byteme/PerByte.hpp"
5#include "byteme/RawFileReader.hpp"
6#include "byteme/GzipFileReader.hpp"
7#include "byteme/ZlibBufferReader.hpp"
45template<
typename Index_,
bool parallel_>
48 typename std::conditional<parallel_, byteme::PerByte<char>, byteme::PerByteParallel<char> >::type pb(&reader);
50 bool okay = pb.valid();
53 size_t first = 0, second = 0;
54 for (
int l = 0; l < 2; ++l) {
55 auto& current = (l == 0 ? first : second);
56 bool non_empty =
false;
64 throw std::runtime_error(
"empty field detected in the label indices");
67 }
else if (x ==
'\n') {
70 }
else if (!std::isdigit(x)) {
71 throw std::runtime_error(
"label indices should be integers");
80 throw std::runtime_error(
"expected at least three tab-separated fields on each line");
84 if (first >= markers.size()) {
85 markers.resize(first + 1);
87 auto& fmarkers = markers[first];
88 if (second >= fmarkers.size()) {
89 fmarkers.resize(second + 1);
91 auto& values = fmarkers[second];
92 if (!values.empty()) {
93 throw std::runtime_error(
"multiple marker sets listed for a single pairwise comparison");
97 bool non_empty =
false;
103 if (std::isdigit(x)) {
106 current += (x -
'0');
108 }
else if (x ==
'\t') {
110 throw std::runtime_error(
"gene index fields should not be empty");
112 values.push_back(current);
116 }
else if (x ==
'\n') {
120 throw std::runtime_error(
"gene index fields should be integers");
127 throw std::runtime_error(
"gene index fields should not be empty");
129 values.push_back(current);
133 size_t expected_nlabels = markers.size();
134 for (
const auto& m : markers) {
135 expected_nlabels = std::max(expected_nlabels, m.size());
137 markers.resize(expected_nlabels);
138 for (
auto& m : markers) {
139 m.resize(expected_nlabels);
145template<
typename Index_>
148 return load_markers<Index_, true>(reader);
150 return load_markers<Index_, false>(reader);
173template<
typename Index_ = singlepp::DefaultIndex>
175 byteme::RawFileReader reader(path, options.
buffer_size);
176 return internal::load_markers<Index_>(reader, options.
parallel);
189template<
typename Index_ = singlepp::DefaultIndex>
191 byteme::GzipFileReader reader(path, options.
buffer_size);
192 return internal::load_markers<Index_>(reader, options.
parallel);
206template<
typename Index_ = singlepp::DefaultIndex>
208 byteme::ZlibBufferReader reader(buffer, len, 3, options.
buffer_size);
209 return internal::load_markers<Index_>(reader, options.
parallel);
Load pre-processed single reference datasets.
Definition labels.hpp:23
singlepp::Markers< Index_ > load_markers_from_gzip_file(const char *path, const LoadMarkersOptions &options)
Definition markers.hpp:190
singlepp::Markers< Index_ > load_markers_from_zlib_buffer(const unsigned char *buffer, size_t len, const LoadMarkersOptions &options)
Definition markers.hpp:207
singlepp::Markers< Index_ > load_markers_from_text_file(const char *path, const LoadMarkersOptions &options)
Definition markers.hpp:174
std::vector< std::vector< std::vector< Index_ > > > Markers
Options for loading markers.
Definition markers.hpp:28
bool parallel
Definition markers.hpp:32
size_t buffer_size
Definition markers.hpp:37