2 #include <Sequence/AlleleCountMatrix.hpp> 3 #include <Sequence/StateCounts.hpp> 7 std::vector<std::int32_t>
8 AlleleCountMatrix::init_counts(
const VariantMatrix& m)
12 throw std::invalid_argument(
"matrix max_allele must be >= 0");
14 std::vector<std::int32_t> counts;
15 counts.reserve(m.nsam * static_cast<std::size_t>(m.max_allele + 1));
17 for (std::size_t i = 0; i < m.nsites; ++i)
20 if (static_cast<std::int8_t>(c.max_allele_idx) > m.max_allele)
22 throw std::runtime_error(
"found allele value greater " 23 "than matrix.max_allele");
26 for (std::size_t j = 0;
27 j < static_cast<std::size_t>(m.max_allele + 1); ++j)
29 counts.push_back(c.counts[j]);
35 AlleleCountMatrix::AlleleCountMatrix(
const VariantMatrix& m)
36 : counts(init_counts(m)),
37 ncol(!m.data.empty() ? static_cast<
std::size_t>(m.max_allele) + 1
39 nrow(!m.data.empty() ? counts.size() / ncol : 0), nsam(m.nsam)
43 std::pair<std::vector<std::int32_t>::const_iterator,
44 std::vector<std::int32_t>::const_iterator>
45 AlleleCountMatrix::row(
const std::size_t i)
const 49 throw std::out_of_range(
"row index out of range");
51 return std::make_pair(counts.begin() + i * ncol,
52 counts.begin() + i * ncol + ncol);
The namespace in which this library resides.
ConstRowView get_ConstRowView(const VariantMatrix &m, const std::size_t row)
Return a ConstRowView from VariantMatrix m at row row. std::out_of_range is thrown if row is out of r...