bpp-popgen3  3.0.0
Group.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 _GROUP_H_
6 #define _GROUP_H_
7 
8 // From STL
9 #include <vector>
10 #include <memory>
11 
12 #include <Bpp/Exceptions.h>
13 #include <Bpp/Graphics/Point2D.h>
14 
15 // From bpp-seq
19 
20 // From bpp-popgen
21 #include "Individual.h"
22 #include "../GeneralExceptions.h"
23 
24 namespace bpp
25 {
34 class Group :
35  public virtual Clonable
36 {
37 protected:
38  size_t id_;
39  std::string name_;
40  std::vector<std::unique_ptr<Individual>> individuals_;
41 
42 public:
43  // Constructors and destructor :
47  Group(size_t groupId) :
48  id_(groupId),
49  name_(""),
50  individuals_()
51  {}
52 
59  Group(const Group& group) :
60  id_(group.id_),
61  name_(group.name_),
62  individuals_()
63  {
64  for (size_t i = 0; i < group.getNumberOfIndividuals(); ++i)
65  {
67  }
68  }
69 
73  Group& operator=(const Group& group)
74  {
75  id_ = group.id_;
76  name_ = group.name_;
77  individuals_.clear();
78  for (size_t i = 0; i < group.getNumberOfIndividuals(); ++i)
79  {
81  }
82  return *this;
83  }
84 
88  Group(const Group& group, size_t groupId) :
89  id_(groupId),
90  name_(group.name_),
91  individuals_()
92  {
93  for (size_t i = 0; i < group.getNumberOfIndividuals(); ++i)
94  {
96  }
97  }
98 
99 
103  virtual ~Group() = default;
104 
105  Group* clone() const override { return new Group(*this); }
106 
107 public:
113  void setGroupId(size_t groupId){ id_ = groupId; }
114 
120  const std::string& getGroupName() const { return name_; }
121 
127  void setGroupName(const std::string& groupName) { name_ = groupName; }
128 
134  size_t getGroupId() const { return id_; }
135 
144  void addIndividual(const Individual& ind);
145 
151  void addEmptyIndividual(const std::string& individualId);
152 
158  size_t getNumberOfIndividuals() const { return individuals_.size(); }
159 
166  size_t getMaxNumberOfSequences() const;
167 
173  size_t getIndividualPosition(const std::string& individualId) const;
174 
182  const Individual& getIndividualById(const std::string& individualId) const;
183 
192  const Individual& getIndividualAtPosition(size_t individualPosition) const;
193 
205  std::unique_ptr<Individual> removeIndividualById(const std::string& individualId);
206 
217  std::unique_ptr<Individual> removeIndividualAtPosition(size_t individualPosition);
218 
229  void deleteIndividualById(const std::string& individualId);
230 
238  void deleteIndividualAtPosition(size_t individualPosition);
239 
245  void clear() { individuals_.clear(); }
246 
247  // -- Dealing with Individuals -----------------------------
253  void setIndividualSexAtPosition(size_t individualPosition, const unsigned short sex);
254 
260  unsigned short getIndividualSexAtPosition(size_t individualPosition) const;
261 
267  void setIndividualDateAtPosition(size_t individualPosition, const Date& date);
268 
275  const Date& getIndividualDateAtPosition(size_t individualPosition) const;
276 
282  void setIndividualCoordAtPosition(size_t individualPosition, const Point2D<double>& coord);
283 
290  const Point2D<double>& getIndividualCoordAtPosition(size_t individualPosition) const;
291 
298  size_t individualPosition,
299  std::shared_ptr<const Locality<double>> locality);
300 
307  std::shared_ptr<const Locality<double>> getIndividualLocalityAtPosition(size_t individualPosition) const;
308 
317  void addIndividualSequenceAtPosition(size_t individualPosition,
318  size_t sequencePosition,
319  std::unique_ptr<Sequence>& sequence);
320 
329  size_t individualPosition,
330  const std::string& sequence_name) const;
331 
340  size_t individualPosition,
341  size_t sequencePosition) const;
342 
350  void deleteIndividualSequenceByName(size_t individualPosition, const std::string& sequence_name);
351 
359  void deleteIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition);
360 
366  bool hasIndividualSequences(size_t individualPosition) const;
367 
374  std::vector<std::string> getIndividualSequencesNames(size_t individualPosition) const;
375 
384  size_t individualPosition,
385  const std::string& sequence_name) const;
386 
393  size_t getIndividualNumberOfSequences(size_t individualPosition) const;
394 
400  void setIndividualSequences(size_t individualPosition, const SequenceContainerInterface& sc);
401 
407  void setIndividualGenotype(size_t individualPosition, const MultilocusGenotype& genotype);
408 
416  void initIndividualGenotype(size_t individualPosition, size_t loci_number);
417 
423  void deleteIndividualGenotype(size_t individualPosition);
424 
430  bool hasIndividualGenotype(size_t individualPosition) const;
431 
440  size_t individualPosition,
441  size_t locusPosition,
442  const MonolocusGenotypeInterface& monogen);
443 
453  size_t individualPosition,
454  size_t locusPosition,
455  const std::vector<size_t>& alleleKeys);
456 
466  size_t individualPosition,
467  size_t locusPosition,
468  const std::vector<std::string>& alleleId,
469  const LocusInfo& locusInfo);
470 
479  size_t individualPosition,
480  size_t locusPosition) const;
481 
485  bool hasSequenceData() const;
486 
490  std::shared_ptr<const Alphabet> getAlphabet() const;
491 
495  size_t getGroupSizeForLocus(size_t locusPosition) const;
496 
500  size_t getGroupSizeForSequence(size_t sequencePosition) const;
501 };
502 } // end of namespace bpp;
503 
504 #endif // _GROUP_H_
The Date class.
Definition: Date.h:21
The Group class.
Definition: Group.h:36
size_t getGroupSizeForSequence(size_t sequencePosition) const
Get the number of individual that have a sequence at the specified position.
Definition: Group.cpp:515
const Sequence & getIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition) const
Get a sequence of an Individual.
Definition: Group.cpp:243
Group(const Group &group)
Copy constructor.
Definition: Group.h:59
void deleteIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition)
Delete a sequence of an Individual.
Definition: Group.cpp:279
void deleteIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name)
Delete a sequence of an Individual.
Definition: Group.cpp:261
void setIndividualSexAtPosition(size_t individualPosition, const unsigned short sex)
Set the sex of an Individual.
Definition: Group.cpp:126
std::vector< std::string > getIndividualSequencesNames(size_t individualPosition) const
Get the sequences' names from an Individual.
Definition: Group.cpp:304
void deleteIndividualGenotype(size_t individualPosition)
Delete the genotype of an Individual.
Definition: Group.cpp:382
size_t getGroupSizeForLocus(size_t locusPosition) const
Get the number of individual that have a data at the specified locus.
Definition: Group.cpp:504
size_t getGroupId() const
Get the id of the Group.
Definition: Group.h:134
void clear()
Clear the Group.
Definition: Group.h:245
Group * clone() const override
Definition: Group.h:105
const Date & getIndividualDateAtPosition(size_t individualPosition) const
Get the date of an Individual.
Definition: Group.cpp:147
void addIndividual(const Individual &ind)
Add an Individual.
Definition: Group.cpp:12
const Individual & getIndividualById(const std::string &individualId) const
Get a reference to an Individual.
Definition: Group.cpp:92
const Point2D< double > & getIndividualCoordAtPosition(size_t individualPosition) const
Get the coordinates of an Individual.
Definition: Group.cpp:168
virtual ~Group()=default
Destroy a Group.
size_t getIndividualSequencePosition(size_t individualPosition, const std::string &sequence_name) const
Get the position of a sequence in an Individual.
Definition: Group.cpp:318
void setIndividualDateAtPosition(size_t individualPosition, const Date &date)
Set the date of an Individual.
Definition: Group.cpp:140
bool hasIndividualSequences(size_t individualPosition) const
Tell if the Individual has some sequences.
Definition: Group.cpp:297
std::unique_ptr< Individual > removeIndividualById(const std::string &individualId)
Remove an Individual from the Group.
Definition: Group.cpp:44
void setIndividualMonolocusGenotypeByAlleleId(size_t individualPosition, size_t locusPosition, const std::vector< std::string > &alleleId, const LocusInfo &locusInfo)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:442
bool hasSequenceData() const
Tell if at least one individual has at least one sequence.
Definition: Group.cpp:484
size_t getIndividualNumberOfSequences(size_t individualPosition) const
Get the number of sequences in an Individual.
Definition: Group.cpp:336
std::shared_ptr< const Alphabet > getAlphabet() const
Get the alphabet used for the sequences.
Definition: Group.cpp:494
void setIndividualSequences(size_t individualPosition, const SequenceContainerInterface &sc)
Set all the sequences by copying an OrderedSequenceContainer.
Definition: Group.cpp:350
void addIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition, std::unique_ptr< Sequence > &sequence)
Add a sequence to an Individual.
Definition: Group.cpp:203
size_t getNumberOfIndividuals() const
Get the number of Individual in the Group.
Definition: Group.h:158
void setIndividualCoordAtPosition(size_t individualPosition, const Point2D< double > &coord)
Set the coordinates of an Individual.
Definition: Group.cpp:161
size_t getMaxNumberOfSequences() const
Get the maximum number of sequence.
Definition: Group.cpp:109
Group & operator=(const Group &group)
The assignation operator =.
Definition: Group.h:73
std::string name_
Definition: Group.h:39
void initIndividualGenotype(size_t individualPosition, size_t loci_number)
Initialize the genotype of an Individual.
Definition: Group.cpp:364
size_t id_
Definition: Group.h:38
unsigned short getIndividualSexAtPosition(size_t individualPosition) const
Get the sex of an Individual.
Definition: Group.cpp:133
bool hasIndividualGenotype(size_t individualPosition) const
Tell if an Individual has a genotype.
Definition: Group.cpp:389
void setIndividualMonolocusGenotypeByAlleleKey(size_t individualPosition, size_t locusPosition, const std::vector< size_t > &alleleKeys)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:417
size_t getIndividualPosition(const std::string &individualId) const
Get the position of an Individual.
Definition: Group.cpp:34
Group(const Group &group, size_t groupId)
A duplication constructor with new Group Id.
Definition: Group.h:88
std::unique_ptr< Individual > removeIndividualAtPosition(size_t individualPosition)
Remove an Individual from the Group.
Definition: Group.cpp:59
void deleteIndividualById(const std::string &individualId)
Delete an Individual from the Group.
Definition: Group.cpp:68
std::shared_ptr< const Locality< double > > getIndividualLocalityAtPosition(size_t individualPosition) const
Get the locality of an Individual.
Definition: Group.cpp:189
const Individual & getIndividualAtPosition(size_t individualPosition) const
Get a reference to an Individual by its position.
Definition: Group.cpp:102
Group(size_t groupId)
Build a void new Group.
Definition: Group.h:47
void setIndividualLocalityAtPosition(size_t individualPosition, std::shared_ptr< const Locality< double >> locality)
Set the locality of an Individual.
Definition: Group.cpp:182
void setGroupId(size_t groupId)
Set the id of the Group.
Definition: Group.h:113
void setGroupName(const std::string &groupName)
Set the name of the Group.
Definition: Group.h:127
const MonolocusGenotypeInterface & getIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition) const
Get a MonolocusGenotype of an Individual.
Definition: Group.cpp:464
void addEmptyIndividual(const std::string &individualId)
Add an empty Individual to the Group.
Definition: Group.cpp:24
void setIndividualGenotype(size_t individualPosition, const MultilocusGenotype &genotype)
Set the genotype of an Individual.
Definition: Group.cpp:357
const std::string & getGroupName() const
Get the name of the Group.
Definition: Group.h:120
const Sequence & getIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name) const
Get a sequence of an Individual.
Definition: Group.cpp:225
void setIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:396
std::vector< std::unique_ptr< Individual > > individuals_
Definition: Group.h:40
void deleteIndividualAtPosition(size_t individualPosition)
Delete an Individual from the Group.
Definition: Group.cpp:80
The Individual class.
Definition: Individual.h:40
The Locality class.
Definition: Locality.h:25
The LocusInfo class.
Definition: LocusInfo.h:31
The MonolocusGenotype virtual class.
The MultilocusGenotype class.