Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
DiploidIndividual.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu> Florence Jornod <florence@jornod.com>
2
3/*********************************************************************** * This program is free software; you can
4 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
5 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
6 * *
7 ************************************************************************/
8
9#ifndef __DIPLOID_INDIVIDUAL_H_INCLUDED__
10#define __DIPLOID_INDIVIDUAL_H_INCLUDED__
11
12#include <map>
13#include <set>
14#include <string>
15
16namespace quetzal::format
17{
18namespace genetics
19{
20
21template <typename Allele> class DiploidIndividual
22{
23 public:
24 using allele_type = Allele;
25 using locus_ID_type = std::string;
26
27 DiploidIndividual() = default;
28
29 DiploidIndividual(std::pair<allele_type, allele_type> const &locus, locus_ID_type const &name)
30 {
31 m_loci[name] = locus;
32 }
33
34 DiploidIndividual(locus_ID_type const &name, std::pair<allele_type, allele_type> const &locus)
35 {
36 m_loci[name] = locus;
37 }
38 DiploidIndividual(locus_ID_type const &name, allele_type allele_1, allele_type allele_2)
39 {
40 m_loci[name] = std::make_pair(allele_1, allele_2);
41 }
42 DiploidIndividual(allele_type allele_1, allele_type allele_2, locus_ID_type const &name)
43 {
44 m_loci[name] = std::make_pair(allele_1, allele_2);
45 }
46
47 DiploidIndividual<Allele> &add(locus_ID_type const &name, allele_type a1, allele_type a2)
48 {
49 m_loci[name] = std::make_pair(a1, a2);
50 return *this;
51 }
52
53 DiploidIndividual<Allele> &add(std::pair<allele_type, allele_type> const &locus, locus_ID_type const &name)
54 {
55 m_loci[name] = locus;
56 return *this;
57 }
58
59 DiploidIndividual<Allele> &add(locus_ID_type const &name, std::pair<allele_type, allele_type> const &locus)
60 {
61 m_loci[name] = locus;
62 return *this;
63 }
64
65 unsigned int nGenotypedLoci() const
66 {
67 return m_loci.size();
68 }
69
70 std::pair<allele_type, allele_type> const &alleles(locus_ID_type const &locus) const
71 {
72 return m_loci.at(locus);
73 }
74
75 std::set<locus_ID_type> loci() const
76 {
77 std::set<locus_ID_type> loci;
78 for (auto const &it : m_loci)
79 {
80 loci.insert(it.first);
81 }
82 return loci;
83 }
84
85 private:
86 std::map<locus_ID_type, std::pair<allele_type, allele_type>> m_loci;
87};
88
89} // namespace genetics
90} // namespace quetzal::format
91
92#endif
Definition Allele.hpp:16
Definition DiploidIndividual.hpp:22
Parsers and generators for input/output.
Definition io.hpp:23