|
| 1 | +// Copyright (c) 2015-2019 Daniel Cooke |
| 2 | +// Use of this source code is governed by the MIT license that can be found in the LICENSE file. |
| 3 | + |
| 4 | +#include "assigned_depth.hpp" |
| 5 | + |
| 6 | +#include <numeric> |
| 7 | +#include <algorithm> |
| 8 | +#include <iterator> |
| 9 | + |
| 10 | +#include <boost/variant.hpp> |
| 11 | + |
| 12 | +#include "core/types/allele.hpp" |
| 13 | +#include "io/variant/vcf_record.hpp" |
| 14 | +#include "utils/genotype_reader.hpp" |
| 15 | +#include "../facets/samples.hpp" |
| 16 | +#include "../facets/read_assignments.hpp" |
| 17 | + |
| 18 | +namespace octopus { namespace csr { |
| 19 | + |
| 20 | +const std::string AssignedDepth::name_ = "ADP"; |
| 21 | + |
| 22 | +std::unique_ptr<Measure> AssignedDepth::do_clone() const |
| 23 | +{ |
| 24 | + return std::make_unique<AssignedDepth>(*this); |
| 25 | +} |
| 26 | + |
| 27 | +namespace { |
| 28 | + |
| 29 | +template <typename Map> |
| 30 | +std::size_t sum_value_sizes(const Map& map) noexcept |
| 31 | +{ |
| 32 | + return std::accumulate(std::cbegin(map), std::cend(map), std::size_t {0}, |
| 33 | + [] (auto curr, const auto& p) noexcept { return curr + p.second.size(); }); |
| 34 | +} |
| 35 | + |
| 36 | +} // namespace |
| 37 | + |
| 38 | +Measure::ResultType AssignedDepth::do_evaluate(const VcfRecord& call, const FacetMap& facets) const |
| 39 | +{ |
| 40 | + const auto& samples = get_value<Samples>(facets.at("Samples")); |
| 41 | + const auto& assignments = get_value<ReadAssignments>(facets.at("ReadAssignments")); |
| 42 | + std::vector<std::size_t> result {}; |
| 43 | + result.reserve(samples.size()); |
| 44 | + for (const auto& sample : samples) { |
| 45 | + const auto alleles = get_called_alleles(call, sample).first; |
| 46 | + const auto allele_support = compute_allele_support(alleles, assignments, sample); |
| 47 | + result.push_back(sum_value_sizes(allele_support)); |
| 48 | + } |
| 49 | + return result; |
| 50 | +} |
| 51 | + |
| 52 | +Measure::ResultCardinality AssignedDepth::do_cardinality() const noexcept |
| 53 | +{ |
| 54 | + return ResultCardinality::num_samples; |
| 55 | +} |
| 56 | + |
| 57 | +const std::string& AssignedDepth::do_name() const |
| 58 | +{ |
| 59 | + return name_; |
| 60 | +} |
| 61 | + |
| 62 | +std::string AssignedDepth::do_describe() const |
| 63 | +{ |
| 64 | + return "Number of reads overlapping the position that could be assigned to an allele"; |
| 65 | +} |
| 66 | + |
| 67 | +std::vector<std::string> AssignedDepth::do_requirements() const |
| 68 | +{ |
| 69 | + return {"Samples", "ReadAssignments"}; |
| 70 | +} |
| 71 | + |
| 72 | +} // namespace csr |
| 73 | +} // namespace octopus |
0 commit comments