libsequence  1.9.5
VariantMatrix.cc
1 #include <Sequence/VariantMatrix.hpp>
2 #include <Sequence/VariantMatrixViews.hpp>
3 #include <Sequence/StateCounts.hpp>
4 #include <stdexcept>
5 
6 namespace Sequence
7 {
8  const std::int8_t VariantMatrix::mask
9  = std::numeric_limits<std::int8_t>::min();
10  // Non range-checked access
11  std::int8_t&
12  VariantMatrix::get(const std::size_t site, const std::size_t haplotype)
13  {
14  return data[site * nsam + haplotype];
15  }
16 
17  const std::int8_t&
18  VariantMatrix::get(const std::size_t site,
19  const std::size_t haplotype) const
20  {
21  return data[site * nsam + haplotype];
22  }
23 
24  // Ranged-checked access after std::vector<T>::at.
25  std::int8_t&
26  VariantMatrix::at(const std::size_t site, const std::size_t haplotype)
27  {
28  if (site >= nsites || haplotype >= nsam)
29  {
30  throw std::out_of_range(
31  "VariantMatrix::at -- index out of range");
32  }
33  return data.at(site * nsam + haplotype);
34  }
35 
36  const std::int8_t&
37  VariantMatrix::at(const std::size_t site,
38  const std::size_t haplotype) const
39  {
40  if (site >= nsites || haplotype >= nsam)
41  {
42  throw std::out_of_range(
43  "VariantMatrix::at -- index out of range");
44  }
45  return data.at(site * nsam + haplotype);
46  }
47 } // namespace Sequence
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.
std::size_t nsam
Sample size of data set.
std::int8_t & get(const std::size_t site, const std::size_t haplotype)
Get data from marker site and haplotype haplotype. No range-checking is done.
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.