bpp-popgen3  3.0.0
LocusInfo.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 _LOCUSINFO_H_
6 #define _LOCUSINFO_H_
7 
8 // From STL
9 #include <string>
10 #include <vector>
11 #include <memory>
12 
13 // From local bpp-popgen
14 #include "AlleleInfo.h"
15 #include "GeneralExceptions.h"
16 
17 #include <Bpp/Exceptions.h>
18 
19 namespace bpp
20 {
29 class LocusInfo :
30  public virtual Clonable
31 {
32 private:
33  std::string name_;
34  unsigned int ploidy_;
35  std::vector<std::unique_ptr<AlleleInfo>> alleles_;
36 
37 public:
38  static unsigned int HAPLODIPLOID;
39  static unsigned int HAPLOID;
40  static unsigned int DIPLOID;
41  static unsigned int UNKNOWN;
42 
43 public:
44  // Constructors and destructor
51  LocusInfo(const std::string& name, const unsigned int ploidy = DIPLOID) :
52  name_(name),
53  ploidy_(ploidy),
54  alleles_()
55  {}
56 
60  LocusInfo(const LocusInfo& locusInfo) :
61  name_(locusInfo.name_),
62  ploidy_(locusInfo.ploidy_),
63  alleles_(locusInfo.getNumberOfAlleles())
64  {
65  for (unsigned int i = 0; i < locusInfo.getNumberOfAlleles(); ++i)
66  {
67  alleles_[i].reset(locusInfo.getAlleleInfoByKey(i).clone());
68  }
69  }
70 
71  LocusInfo& operator=(const LocusInfo& locusInfo)
72  {
73  name_ = locusInfo.name_;
74  ploidy_ = locusInfo.ploidy_;
75  alleles_.resize(locusInfo.getNumberOfAlleles());
76  for (unsigned int i = 0; i < locusInfo.getNumberOfAlleles(); ++i)
77  {
78  alleles_[i].reset(locusInfo.getAlleleInfoByKey(i).clone());
79  }
80  return *this;
81  }
82 
86  virtual ~LocusInfo() = default;
87 
88  LocusInfo* clone() const override { return new LocusInfo(*this); }
89 
90 public:
94  const std::string& getName() const { return name_; }
95 
101  unsigned int getPloidy() const { return ploidy_; }
102 
108  void addAlleleInfo(const AlleleInfo& allele);
109 
115  const AlleleInfo& getAlleleInfoById(const std::string& id) const;
116 
122  const AlleleInfo& getAlleleInfoByKey(size_t key) const;
123 
129  unsigned int getAlleleInfoKey(const std::string& id) const;
130 
134  size_t getNumberOfAlleles() const { return alleles_.size(); }
135 
139  void clear() { alleles_.clear(); }
140 };
141 } // end of namespace bpp;
142 
143 #endif // _LOCUSINFO_H_
The AlleleInfo interface.
Definition: AlleleInfo.h:25
AlleleInfo * clone() const =0
The LocusInfo class.
Definition: LocusInfo.h:31
static unsigned int UNKNOWN
Definition: LocusInfo.h:41
std::vector< std::unique_ptr< AlleleInfo > > alleles_
Definition: LocusInfo.h:35
void clear()
Delete all alleles from the locus.
Definition: LocusInfo.h:139
virtual ~LocusInfo()=default
Destroy the LocusInfo.
unsigned int getPloidy() const
Get the ploidy of the locus.
Definition: LocusInfo.h:101
size_t getNumberOfAlleles() const
Get the number of alleles at this locus.
Definition: LocusInfo.h:134
unsigned int getAlleleInfoKey(const std::string &id) const
Get the position of an AlleleInfo.
Definition: LocusInfo.cpp:49
LocusInfo(const std::string &name, const unsigned int ploidy=DIPLOID)
Build a new LocusInfo object.
Definition: LocusInfo.h:51
static unsigned int DIPLOID
Definition: LocusInfo.h:40
LocusInfo & operator=(const LocusInfo &locusInfo)
Definition: LocusInfo.h:71
LocusInfo * clone() const override
Definition: LocusInfo.h:88
unsigned int ploidy_
Definition: LocusInfo.h:34
const AlleleInfo & getAlleleInfoByKey(size_t key) const
Retrieve an AlleleInfo object of the LocusInfo.
Definition: LocusInfo.cpp:42
static unsigned int HAPLOID
Definition: LocusInfo.h:39
void addAlleleInfo(const AlleleInfo &allele)
Add an AlleleInfo to the LocusInfo.
Definition: LocusInfo.cpp:21
static unsigned int HAPLODIPLOID
Definition: LocusInfo.h:38
const AlleleInfo & getAlleleInfoById(const std::string &id) const
Retrieve an AlleleInfo object of the LocusInfo.
Definition: LocusInfo.cpp:32
const std::string & getName() const
Get the name of the locus.
Definition: LocusInfo.h:94
std::string name_
Definition: LocusInfo.h:33
LocusInfo(const LocusInfo &locusInfo)
Copy constructor.
Definition: LocusInfo.h:60