Skip to content

Commit 702109e

Browse files
author
Daniel Cooke
committed
Add AssignedDepth Measure
1 parent cb3faf9 commit 702109e

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ set(CORE_SOURCES
383383
core/csr/measures/base_mismatch_count.cpp
384384
core/csr/measures/base_mismatch_fraction.hpp
385385
core/csr/measures/base_mismatch_fraction.cpp
386+
core/csr/measures/assigned_depth.hpp
387+
core/csr/measures/assigned_depth.cpp
386388

387389
core/models/haplotype_likelihood_array.hpp
388390
core/models/haplotype_likelihood_array.cpp
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
#ifndef assigned_depth_hpp
5+
#define assigned_depth_hpp
6+
7+
#include <string>
8+
#include <vector>
9+
10+
#include "measure.hpp"
11+
12+
namespace octopus {
13+
14+
class VcfRecord;
15+
16+
namespace csr {
17+
18+
class AssignedDepth : public Measure
19+
{
20+
const static std::string name_;
21+
std::unique_ptr<Measure> do_clone() const override;
22+
ResultType do_evaluate(const VcfRecord& call, const FacetMap& facets) const override;
23+
ResultCardinality do_cardinality() const noexcept override;
24+
const std::string& do_name() const override;
25+
std::string do_describe() const override;
26+
std::vector<std::string> do_requirements() const override;
27+
};
28+
29+
} // namespace csr
30+
} // namespace octopus
31+
32+
#endif

src/core/csr/measures/measure_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void init(MeasureMakerMap& measure_makers)
6060
measure_makers[name<VariantLength>()] = [] () { return make_wrapped_measure<VariantLength>(); };
6161
measure_makers[name<BaseMismatchCount>()] = [] () { return make_wrapped_measure<BaseMismatchCount>(); };
6262
measure_makers[name<BaseMismatchFraction>()] = [] () { return make_wrapped_measure<BaseMismatchFraction>(); };
63+
measure_makers[name<AssignedDepth>()] = [] () { return make_wrapped_measure<AssignedDepth>(); };
6364
}
6465

6566
class BadParameterList : public UserError

src/core/csr/measures/measures_fwd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
#include "core/csr/measures/variant_length.hpp"
4848
#include "core/csr/measures/base_mismatch_count.hpp"
4949
#include "core/csr/measures/base_mismatch_fraction.hpp"
50+
#include "core/csr/measures/assigned_depth.hpp"
5051

5152
#endif

0 commit comments

Comments
 (0)