File: MutationEnumerator-inl.hpp

package info (click to toggle)
consensuscore 1.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,184 kB
  • sloc: cpp: 38,940; python: 2,082; ansic: 542; sh: 184; makefile: 85; cs: 10
file content (32 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Author: David Alexander, Lance Hepler

#include <algorithm>
#include <set>
#include <vector>

namespace ConsensusCore {
///
/// Enumerate all mutations within a neighborhood of another set of
/// mutations of interest.  Note that the neighborhoods are presently
/// lopsided due to the end-exclusive definition for how we do ranges.
/// (In other words a neighborhood of size 2 includes two before but one
//   after).
template <typename T>
std::vector<Mutation> UniqueNearbyMutations(const T& mutationEnumerator,
                                            const std::vector<Mutation>& centers,
                                            int neighborhoodSize)
{
    std::set<Mutation> muts;
    foreach (const Mutation& center, centers) {
        int c = center.Start();
        int l = c - neighborhoodSize;
        // FIXME: r should probably be +1 to be symmetric
        int r = c + neighborhoodSize;
        std::vector<Mutation> mutsInRange = mutationEnumerator.Mutations(l, r);
        muts.insert(mutsInRange.begin(), mutsInRange.end());
    }
    std::vector<Mutation> result;
    std::copy(muts.begin(), muts.end(), back_inserter(result));
    return result;
}
}