bpp-popgen3  3.0.0
AnalyzedLoci.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef _ANALYZEDLOCI_H_
6 #define _ANALYZEDLOCI_H_
7 
8 // From STL
9 #include <vector>
10 #include <string>
11 
12 #include <Bpp/Exceptions.h>
13 
14 // From local
15 #include "../LocusInfo.h"
16 #include "../GeneralExceptions.h"
17 
18 namespace bpp
19 {
29 class AnalyzedLoci :
30  public virtual Clonable
31 {
32 private:
33  std::vector<std::unique_ptr<LocusInfo>> loci_;
34 
35 public:
36  // Constructors and Destructor
40  AnalyzedLoci(size_t numberOfLoci) : loci_(numberOfLoci) {}
41 
45  AnalyzedLoci(const AnalyzedLoci& analyzedLoci) :
46  loci_(analyzedLoci.loci_.size())
47  {
48  size_t i = 0;
49  for (const auto& locus : analyzedLoci.loci_)
50  {
51  loci_[i++].reset(locus->clone());
52  }
53  }
54 
55  AnalyzedLoci& operator=(const AnalyzedLoci& analyzedLoci)
56  {
57  loci_.resize(analyzedLoci.loci_.size());
58  size_t i = 0;
59  for (const auto& locus : analyzedLoci.loci_)
60  {
61  loci_[i++].reset(locus->clone());
62  }
63  return *this;
64  }
65 
69  virtual ~AnalyzedLoci() = default;
70 
71  AnalyzedLoci* clone() const { return new AnalyzedLoci(*this); }
72 
73 public:
74  // Other methods
80  void setLocusInfo(size_t locusPosition, const LocusInfo& locus);
81 
87  size_t getLocusInfoPosition(const std::string& locusName) const;
88 
94  const LocusInfo& getLocusInfoByName(const std::string& locusName) const;
95 
102  const LocusInfo& getLocusInfoAtPosition(size_t locusPosition) const;
103 
110  void addAlleleInfoByLocusName(const std::string& locusName,
111  const AlleleInfo& allele);
112 
119  void addAlleleInfoByLocusPosition(size_t locusosition,
120  const AlleleInfo& allele);
121 
125  size_t getNumberOfLoci() const { return loci_.size(); }
126 
130  std::vector<size_t> getNumberOfAlleles() const;
131 
137  unsigned int getPloidyByLocusName(const std::string& locusName) const;
138 
144  unsigned int getPloidyByLocusPosition(size_t locusPosition) const;
145 };
146 } // end of namespace bpp;
147 
148 #endif // _ANALYZEDLOCI_H_
The AlleleInfo interface.
Definition: AlleleInfo.h:25
The AnalyzedLoci class.
Definition: AnalyzedLoci.h:31
std::vector< size_t > getNumberOfAlleles() const
Get the number of alleles at each locus.
size_t getNumberOfLoci() const
Get the number of loci.
Definition: AnalyzedLoci.h:125
AnalyzedLoci * clone() const
Definition: AnalyzedLoci.h:71
std::vector< std::unique_ptr< LocusInfo > > loci_
Definition: AnalyzedLoci.h:33
AnalyzedLoci(size_t numberOfLoci)
Build a void AnalyzedLoci with a specific number of loci.
Definition: AnalyzedLoci.h:40
void addAlleleInfoByLocusName(const std::string &locusName, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo by LocusInfo name.
const LocusInfo & getLocusInfoByName(const std::string &locusName) const
Get a LocusInfo by name.
virtual ~AnalyzedLoci()=default
Destroy the AnalyzedLoci.
unsigned int getPloidyByLocusName(const std::string &locusName) const
Get the ploidy of a locus by name.
const LocusInfo & getLocusInfoAtPosition(size_t locusPosition) const
Get a LocusInfo by its position.
unsigned int getPloidyByLocusPosition(size_t locusPosition) const
Get the ploidy of a locus by its position.
void addAlleleInfoByLocusPosition(size_t locusosition, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo by its position.
AnalyzedLoci(const AnalyzedLoci &analyzedLoci)
Copy constructor.
Definition: AnalyzedLoci.h:45
void setLocusInfo(size_t locusPosition, const LocusInfo &locus)
Set a LocusInfo.
size_t getLocusInfoPosition(const std::string &locusName) const
Get the position of a LocusInfo.
AnalyzedLoci & operator=(const AnalyzedLoci &analyzedLoci)
Definition: AnalyzedLoci.h:55
The LocusInfo class.
Definition: LocusInfo.h:31