48 groups_(
std::vector<size_t>()),
49 groups_names_(
std::map<size_t,
std::string>()) {}
52 groups_(
std::vector<size_t>(pmgc.size())),
53 groups_names_(
std::map<size_t,
std::string>())
55 for (
size_t i = 0; i < pmgc.
size(); i++)
61 for (set<size_t>::iterator it = grp_ids.begin(); it != grp_ids.end(); it++)
81 for (
size_t i = 0; i < pmgc.
size(); i++)
87 for (set<size_t>::iterator it = grp_ids.begin(); it != grp_ids.end(); it++)
103 map<size_t, string>::const_iterator it =
groups_names_.find(group);
115 if (position >= size())
116 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::getMultilocusGenotype: position out of bounds.", position, 0, size() - 1);
117 return multilocusGenotypes_[position];
124 if (position >= size())
125 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::removeMultilocusGenotype: position out of bounds.", position, 0, size() - 1);
127 multilocusGenotypes_.erase(multilocusGenotypes_.begin() +
static_cast<ptrdiff_t
>(position));
128 groups_.erase(groups_.begin() +
static_cast<ptrdiff_t
>(position));
136 if (position >= size())
137 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::deleteMultilocusGenotype: position out of bounds.", position, 0, size() - 1);
138 delete multilocusGenotypes_[position];
139 multilocusGenotypes_.erase(multilocusGenotypes_.begin() +
static_cast<ptrdiff_t
>(position));
140 groups_.erase(groups_.begin() +
static_cast<ptrdiff_t
>(position));
148 for (
size_t i = 0; i <
size(); i++)
163 throw Exception(
"MultilocusGenotypes are not aligned.");
173 if (position >= size())
174 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::getGroupId: position out of bounds.", position, 0, size() - 1);
175 return groups_[position];
182 if (position >= size())
183 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::setGroupId: position out of bounds.", position, 0, size() - 1);
184 groups_[position] = group_id;
191 set<size_t> groups_ids;
192 for (
size_t i = 0; i <
size(); i++)
203 vector<string> grps_names;
204 map<size_t, string>::const_iterator it;
207 string name = it->second;
209 grps_names.push_back(name);
211 grps_names.push_back(TextTools::toString(it->first) );
221 for (
size_t i = 0; i <
size(); i++)
241 for (
size_t i = 0; i <
size(); i++)
253 string name = TextTools::toString(group_id);
254 map<size_t, string>::const_iterator it = groups_names_.find(group_id);
255 if (it != groups_names_.end() )
266 map<size_t, string>::iterator it = groups_names_.find(group_id);
267 if (it != groups_names_.end() )
287 for (
size_t i = 0; i <
size(); i++)
294 catch (IndexOutOfBoundsException& ioobe)
296 throw IndexOutOfBoundsException(
"PolymorphismMultiGContainer::getGroupSize: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
void setGroupId(size_t position, size_t group_id)
Set the Group id of a MultilocusGenotype.
std::vector< MultilocusGenotype * > multilocusGenotypes_
size_t getNumberOfGroups() const
Get the number of groups.
MultilocusGenotype * removeMultilocusGenotype(size_t position)
Remove a MultilocusGenotype.
The GroupNotFoundException class.
PolymorphismMultiGContainer & operator=(const PolymorphismMultiGContainer &pmgc)
The assignation operator=.
std::set< size_t > getAllGroupsIds() const
Get the groups' ids.
std::map< size_t, std::string > groups_names_
bool isAligned() const
Tell if the MultilocusGenotypes are aligned (i.e. same size).
PolymorphismMultiGContainer()
Build a new PolymorphismMultilocusGenotypeContainer.
The MultilocusGenotype class.
~PolymorphismMultiGContainer()
Destroy a PolymorphismMultilocusGenotypeContainer.
std::vector< size_t > groups_
size_t getGroupId(size_t position) const
Get the Group id of a MultilocusGenotype.
void deleteMultilocusGenotype(size_t position)
Delete a MultilocusGenotype.
std::vector< std::string > getAllGroupsNames() const
Get the groups names or ids if not available.
void clear()
Clear the container.
size_t getLocusGroupSize(size_t group, size_t locus_position) const
Get the size of a group for a given locus.
void addMultilocusGenotype(const MultilocusGenotype &mg, size_t group)
Add a MultilocusGenotype to the container.
size_t getGroupSize(size_t group) const
Get group size.
The PolymorphismMultiGContainer class.
const MultilocusGenotype * getMultilocusGenotype(size_t position) const
Get a MultilocusGenotype at a position.
void setGroupName(size_t group_id, std::string name)
Set the name for the given group id.
std::string getGroupName(size_t group_id) const
Get the group name for a given group id or just the id if not available juste return it's id...
size_t size() const
Get the number of MultilocusGenotype.
void addGroupName(size_t group_id, std::string name)
Inserts a name for the given group id.
bool groupExists(size_t group) const
Tell if a group exists.
size_t getNumberOfLoci() const
Get the number of loci if the MultilocusGenotypes are aligned.