bpp-popgen3  3.0.0
MultiAlleleMonolocusGenotype.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 using namespace bpp;
8 using namespace std;
9 
10 // ** Class constructor: *******************************************************/
11 
12 MultiAlleleMonolocusGenotype::MultiAlleleMonolocusGenotype(std::vector<size_t> allele_index) : alleleIndex_(vector<size_t>(allele_index.size()))
13 {
14  for (size_t i = 0; i < allele_index.size(); ++i)
15  {
16  alleleIndex_[i] = allele_index[i];
17  }
18 }
19 
20 MultiAlleleMonolocusGenotype::MultiAlleleMonolocusGenotype(const MultiAlleleMonolocusGenotype& mmg) : alleleIndex_(vector<size_t>(mmg.alleleIndex_.size()))
21 {
22  for (size_t i = 0; i < mmg.getAlleleIndex().size(); ++i)
23  {
24  alleleIndex_[i] = mmg.getAlleleIndex()[i];
25  }
26 }
27 
28 // ** Class destructor: ********************************************************/
29 
31 {
32  alleleIndex_.clear();
33 }
34 
35 // ** Other methodes: **********************************************************/
36 
38 {
39  for (size_t i = 0; i < mmg.getAlleleIndex().size(); ++i)
40  {
41  alleleIndex_.push_back(mmg.getAlleleIndex()[i]);
42  }
43  return *this;
44 }
45 
47 {
48  return (alleleIndex_[0] == mmg.getAlleleIndex()[0] && alleleIndex_[1] == mmg.getAlleleIndex()[1])
49  || (alleleIndex_[0] == mmg.getAlleleIndex()[1] && alleleIndex_[1] == mmg.getAlleleIndex()[0]);
50 }
51 
53 {
54  for (size_t i = 1; i < alleleIndex_.size(); ++i)
55  {
56  if (alleleIndex_[i - 1] != alleleIndex_[i])
57  return false;
58  }
59  return true;
60 }
The MultiAlleleMonolocusGenotype class.
bool isHomozygous() const
Test the homozygozity of the locus (i.e. all allele are identical).
MultiAlleleMonolocusGenotype & operator=(const MultiAlleleMonolocusGenotype &mmg)
The affectation operator.
MultiAlleleMonolocusGenotype(std::vector< size_t > alleleIndex)
Build a monolocus genotype containing many alleles.
virtual ~MultiAlleleMonolocusGenotype()
Destroy the MultiAlleleMonolocusGenotype.
std::vector< size_t > getAlleleIndex() const override
Get the alleles' index.
bool operator==(const MultiAlleleMonolocusGenotype &mmg) const
The == operator.