1 #ifndef SEQUENCE_VARIANT_MATRIX_HPP__ 2 #define SEQUENCE_VARIANT_MATRIX_HPP__ 11 #include <type_traits> 13 static_assert(
sizeof(std::int8_t) ==
sizeof(
char),
14 "sizeof(char) is not 8 bits");
48 set_max_allele(
const std::int8_t max_allele_value)
50 if (max_allele_value < 0 && !
data.empty())
52 auto itr = std::max_element(
data.begin(),
data.end());
57 else if (
data.empty())
62 return max_allele_value;
67 std::vector<std::int8_t>
data;
75 static const std::int8_t
mask;
81 template <
typename data_input,
typename positions_input>
83 const std::int8_t max_allele_value = -1)
88 : data(
std::forward<data_input>(data_)),
89 positions(
std::forward<positions_input>(positions_)),
90 nsites(positions.size()),
91 nsam((nsites > 0) ? data.size() / positions.size() : 0),
92 max_allele{ set_max_allele(max_allele_value) }
96 throw std::invalid_argument(
"max allele must be >= 0");
98 if ((!data.empty() && !positions.empty())
99 && data.size() % positions.size() != 0.0)
101 throw std::invalid_argument(
"incorrect dimensions");
109 std::int8_t&
get(
const std::size_t site,
const std::size_t haplotype);
112 const std::int8_t&
get(
const std::size_t site,
113 const std::size_t haplotype)
const;
118 std::int8_t&
at(
const std::size_t site,
const std::size_t haplotype);
121 const std::int8_t&
at(
const std::size_t site,
122 const std::size_t haplotype)
const;
const std::int8_t max_allele
Max allelic value stored in matrix.
The namespace in which this library resides.
std::int8_t & at(const std::size_t site, const std::size_t haplotype)
Get data from marker site and haplotype haplotype. std::out_of_range is thrown if indexes are invalid...
std::size_t nsites
Number of sites in data set.
VariantMatrix(data_input &&data_, positions_input &&positions_, const std::int8_t max_allele_value=-1)
"Perfect-forwarding" constructor.
std::vector< double > positions
Position of sites.
Matrix representation of variation data.
std::size_t nsam
Sample size of data set.
std::vector< std::int8_t > data
Data stored in matrix form with rows as sites.
static const std::int8_t mask
Reserved value for masked data.