bpp-popgen3  3.0.0
PolymorphismMultiGContainer.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 _POLYMORPHYSMMULTIGCONTAINER_H_
6 #define _POLYMORPHYSMMULTIGCONTAINER_H_
7 
8 // From Utils
9 #include <Bpp/Clonable.h>
10 #include <Bpp/Exceptions.h>
11 #include <Bpp/Utils/MapTools.h>
12 #include <Bpp/Text/TextTools.h>
13 
14 // From popgenlib
15 #include "MultilocusGenotype.h"
16 #include "GeneralExceptions.h"
17 
18 // From STL
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <set>
23 
24 namespace bpp
25 {
34  public virtual Clonable
35 {
36 private:
37  std::vector<std::unique_ptr<MultilocusGenotype>> multilocusGenotypes_;
38  std::vector<size_t> groups_; // group id for each multilocusgenotype
39  std::map<size_t, std::string> groupsNames_;
40 
41 public:
42  // Constructors and destructor
48  groups_(std::vector<size_t>()),
49  groupsNames_(std::map<size_t, std::string>())
50  {}
51 
56 
61  {
62  clear();
63  }
64 
65  PolymorphismMultiGContainer* clone() const override { return new PolymorphismMultiGContainer(*this); }
66 
67 public:
72 
76  void addMultilocusGenotype(std::unique_ptr<MultilocusGenotype>& mg, size_t group);
77 
83  const MultilocusGenotype& multilocusGenotype(size_t position) const;
84 
90  std::unique_ptr<MultilocusGenotype> removeMultilocusGenotype(size_t position);
91 
97  void deleteMultilocusGenotype(size_t position);
98 
102  bool isAligned() const;
103 
109  size_t getNumberOfLoci() const;
110 
116  size_t getGroupId(size_t position) const;
117 
123  void setGroupId(size_t position, size_t groupId);
124 
128  std::set<size_t> getAllGroupsIds() const;
129 
133  std::vector<std::string> getAllGroupsNames() const;
134 
138  bool groupExists(size_t group) const;
139 
143  size_t getNumberOfGroups() const
144  {
145  return getAllGroupsIds().size();
146  }
147 
151  size_t getGroupSize(size_t group) const;
152 
156  std::string getGroupName(size_t groupId) const;
157 
161  void setGroupName(size_t groupId, const std::string& name);
162 
166  void addGroupName(size_t groupId, const std::string& name);
167 
171  size_t getLocusGroupSize(size_t group, size_t locusPosition) const;
172 
176  size_t size() const;
177 
181  void clear();
182 };
183 } // end of namespace bpp;
184 
185 #endif // _POLYMORPHYSMMULTIGCONTAINER_H_
The MultilocusGenotype class.
The PolymorphismMultiGContainer class.
virtual ~PolymorphismMultiGContainer()
Destroy a PolymorphismMultilocusGenotypeContainer.
void addMultilocusGenotype(std::unique_ptr< MultilocusGenotype > &mg, size_t group)
Add a MultilocusGenotype to the container.
size_t getNumberOfGroups() const
Get the number of groups.
void deleteMultilocusGenotype(size_t position)
Delete a MultilocusGenotype.
size_t getGroupId(size_t position) const
Get the Group id of a MultilocusGenotype.
std::map< size_t, std::string > groupsNames_
void setGroupName(size_t groupId, const std::string &name)
Set the name for the given group id.
PolymorphismMultiGContainer & operator=(const PolymorphismMultiGContainer &pmgc)
The assignation operator=.
bool groupExists(size_t group) const
Tell if a group exists.
PolymorphismMultiGContainer()
Build a new PolymorphismMultilocusGenotypeContainer.
size_t getLocusGroupSize(size_t group, size_t locusPosition) const
Get the size of a group for a given locus.
size_t getNumberOfLoci() const
Get the number of loci if the MultilocusGenotypes are aligned.
const MultilocusGenotype & multilocusGenotype(size_t position) const
Get a MultilocusGenotype at a position.
std::vector< std::string > getAllGroupsNames() const
Get the groups names or ids if not available.
void addGroupName(size_t groupId, const std::string &name)
Inserts a name for the given group id.
std::string getGroupName(size_t groupId) const
Get the group name for a given group id or just the id if not available juste return it's id.
std::set< size_t > getAllGroupsIds() const
Get the groups' ids.
bool isAligned() const
Tell if the MultilocusGenotypes are aligned (i.e. same size).
PolymorphismMultiGContainer * clone() const override
size_t size() const
Get the number of MultilocusGenotype.
std::vector< std::unique_ptr< MultilocusGenotype > > multilocusGenotypes_
size_t getGroupSize(size_t group) const
Get group size.
std::unique_ptr< MultilocusGenotype > removeMultilocusGenotype(size_t position)
Remove a MultilocusGenotype.
void setGroupId(size_t position, size_t groupId)
Set the Group id of a MultilocusGenotype.