bpp-popgen3  3.0.0
Individual.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 _INDIVIDUAL_H_
6 #define _INDIVIDUAL_H_
7 
8 // From STL
9 #include <vector>
10 #include <memory>
11 
12 #include <Bpp/Graphics/Point2D.h>
13 #include <Bpp/Exceptions.h>
14 #include <Bpp/Text/TextTools.h>
15 
16 // From bpp-seq
17 #include <Bpp/Seq/Sequence.h>
20 
21 // From bpp-popgen
22 #include "Locality.h"
23 #include "Date.h"
24 #include "../MultilocusGenotype.h"
25 #include "../GeneralExceptions.h"
26 
27 namespace bpp
28 {
40 {
41 protected:
42  std::string id_;
43  unsigned short sex_;
44  std::unique_ptr<Date> date_;
45  std::unique_ptr<Point2D<double>> coord_;
46  std::shared_ptr<const Locality<double>> locality_;
47  std::unique_ptr<VectorSequenceContainer> sequences_;
48  std::unique_ptr<MultilocusGenotype> genotype_;
49 
50 public:
51  // Constructors and destructor :
55  Individual();
56 
60  Individual(const std::string& id);
61 
72  Individual(const std::string& id,
73  const Date& date,
74  const Point2D<double>& coord,
75  std::shared_ptr<Locality<double>> locality,
76  const unsigned short sex);
77 
81  Individual(const Individual& ind);
82 
86  virtual ~Individual();
87 
88 public:
89  // Methods
96  Individual& operator=(const Individual& ind);
97 
103  void setId(const std::string& id);
104 
110  const std::string& getId() const { return id_; }
111 
117  void setSex(const unsigned short sex);
118 
124  unsigned short getSex() const { return sex_; }
125 
131  void setDate(const Date& date);
132 
139  const Date& date() const;
140 
144  bool hasDate() const;
145 
151  void setCoord(const Point2D<double>& coord);
152 
159  void setCoord(const double x, const double y);
160 
167  const Point2D<double>& coord() const;
168 
172  bool hasCoord() const;
173 
182  void setX(const double x);
183 
192  void setY(const double y);
193 
200  double getX() const;
201 
208  double getY() const;
209 
215  void setLocality(std::shared_ptr<const Locality<double>> locality)
216  {
218  }
219 
225  std::shared_ptr<const Locality<double>> getLocality() const;
226 
232  const Locality<double>& locality() const;
233 
237  bool hasLocality() const
238  {
239  return locality_ != nullptr;
240  }
241 
254  void addSequence(size_t sequenceKey, std::unique_ptr<Sequence>& sequence);
255 
264  const Sequence& sequenceByName(const std::string& sequenceName) const;
265 
274  const Sequence& sequenceAtPosition(size_t sequencePosition) const;
275 
283  void deleteSequenceByName(const std::string& sequenceName);
284 
292  void deleteSequenceAtPosition(size_t sequencePosition);
293 
300  bool hasSequences() const;
301 
305  bool hasSequenceAtPosition(size_t position) const;
306 
312  std::shared_ptr<const Alphabet> getSequenceAlphabet() const;
313 
319  const Alphabet& sequenceAlphabet() const;
320 
327  std::vector<std::string> getSequenceNames() const
328  {
329  if (!sequences_)
330  throw NullPointerException("Individual::getSequencesNames: no sequence data.");
331  return sequences_->getSequenceNames();
332  }
333 
340  std::vector<size_t> getSequencePositions() const;
341 
348  size_t getSequencePosition(const std::string& sequenceKey) const;
349 
353  size_t getNumberOfSequences() const
354  {
355  return sequences_ ? sequences_->getNumberOfSequences() : 0;
356  }
357 
358 
363  {
364  sequences_.reset(new VectorSequenceContainer(sc));
365  }
366 
373  {
374  if (!sequences_)
375  throw NullPointerException("Individual::getSequences: no sequence data.");
376  return *sequences_;
377  }
378 
379 
385  void setGenotype(const MultilocusGenotype& genotype);
386 
393  void initGenotype(size_t lociNumber);
394 
398  const MultilocusGenotype& getGenotype() const;
399 
403  void deleteGenotype();
404 
408  bool hasGenotype() const;
409 
416  void setMonolocusGenotype(size_t locusPosition, const MonolocusGenotypeInterface& monogen);
417 
426  size_t locusPosition,
427  const std::vector<size_t> alleleKeys);
428 
437  size_t locusPosition,
438  const std::vector<std::string> alleleId,
439  const LocusInfo& locusInfo);
440 
447  const MonolocusGenotypeInterface& getMonolocusGenotype(size_t locusPosition);
448 
454  size_t countNonMissingLoci() const;
455 
461  size_t countHomozygousLoci() const;
462 
468  size_t countHeterozygousLoci() const;
469 };
470 } // end of namespace bpp;
471 
472 #endif // _INDIVIDUAL_H_
The Date class.
Definition: Date.h:21
The Individual class.
Definition: Individual.h:40
double getY() const
Get the Y coordinate of the Individual.
Definition: Individual.cpp:223
const MonolocusGenotypeInterface & getMonolocusGenotype(size_t locusPosition)
Get a MonolocusGenotype.
Definition: Individual.cpp:522
bool hasCoord() const
Tell if this Individual has coordinates.
Definition: Individual.cpp:186
std::shared_ptr< const Alphabet > getSequenceAlphabet() const
Return the alphabet of the sequences.
Definition: Individual.cpp:398
size_t getNumberOfSequences() const
Get the number of sequences.
Definition: Individual.h:353
bool hasSequences() const
Tell if the Individual has some sequences.
Definition: Individual.cpp:375
virtual ~Individual()
Destroy an Individual.
Definition: Individual.cpp:74
std::vector< std::string > getSequenceNames() const
Get the sequence names.
Definition: Individual.h:327
const Sequence & sequenceByName(const std::string &sequenceName) const
Get a sequence from its name.
Definition: Individual.cpp:278
Individual()
Build a void new Individual.
Definition: Individual.cpp:12
unsigned short getSex() const
Get the sex of the Individual.
Definition: Individual.h:124
const Locality< double > & locality() const
Get the locality of the Individual.
Definition: Individual.cpp:243
void setSex(const unsigned short sex)
Set the sex of the Individual.
Definition: Individual.cpp:129
std::unique_ptr< Date > date_
Definition: Individual.h:44
size_t getSequencePosition(const std::string &sequenceKey) const
Get the position of a sequence.
Definition: Individual.cpp:359
size_t countNonMissingLoci() const
Count the number of non missing MonolocusGenotype.
Definition: Individual.cpp:538
void addSequence(size_t sequenceKey, std::unique_ptr< Sequence > &sequence)
Add a sequence to the Individual.
Definition: Individual.cpp:254
std::string id_
Definition: Individual.h:42
void setGenotype(const MultilocusGenotype &genotype)
Set a genotype.
Definition: Individual.cpp:418
void setMonolocusGenotype(size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype.
Definition: Individual.cpp:464
void deleteSequenceAtPosition(size_t sequencePosition)
Delete a sequence.
Definition: Individual.cpp:328
const std::string & getId() const
Get the id of the Individual.
Definition: Individual.h:110
std::unique_ptr< VectorSequenceContainer > sequences_
Definition: Individual.h:47
void setCoord(const Point2D< double > &coord)
Set the coordinates of the Individual.
Definition: Individual.cpp:162
void setY(const double y)
Set the Y coordinate of th Individual.
Definition: Individual.cpp:203
std::shared_ptr< const Locality< double > > getLocality() const
Get the locality of the Individual.
Definition: Individual.cpp:233
void setId(const std::string &id)
Set the id of the Individual.
Definition: Individual.cpp:121
void setLocality(std::shared_ptr< const Locality< double >> locality)
Set the locality of the Individual.
Definition: Individual.h:215
bool hasGenotype() const
Tell if the Individual has a MultilocusGenotype.
Definition: Individual.cpp:457
Individual & operator=(const Individual &ind)
The Individual copy operator.
Definition: Individual.cpp:78
void deleteSequenceByName(const std::string &sequenceName)
Delete a sequence.
Definition: Individual.cpp:311
void setMonolocusGenotypeByAlleleKey(size_t locusPosition, const std::vector< size_t > alleleKeys)
Set a MonolocusGenotype.
Definition: Individual.cpp:482
void setDate(const Date &date)
Set the date of the Individual.
Definition: Individual.cpp:137
void initGenotype(size_t lociNumber)
Init the genotype.
Definition: Individual.cpp:425
const MultilocusGenotype & getGenotype() const
Get the genotype.
Definition: Individual.cpp:441
bool hasLocality() const
Tell if this Individual has a locality.
Definition: Individual.h:237
std::vector< size_t > getSequencePositions() const
Get the sequences' positions.
Definition: Individual.cpp:344
bool hasSequenceAtPosition(size_t position) const
Tell if the Individual has a sequence at a given position.
Definition: Individual.cpp:382
size_t countHomozygousLoci() const
Count the number of homozygous MonolocusGenotype.
Definition: Individual.cpp:547
void setX(const double x)
Set the X coordinate of the Individual.
Definition: Individual.cpp:193
const Point2D< double > & coord() const
Get the coordinates of the Induvidual.
Definition: Individual.cpp:176
bool hasDate() const
Tell if this Individual has a date.
Definition: Individual.cpp:154
const SequenceContainerInterface & sequences() const
Get a reference to the sequence container.
Definition: Individual.h:372
std::unique_ptr< Point2D< double > > coord_
Definition: Individual.h:45
const Sequence & sequenceAtPosition(size_t sequencePosition) const
Get a sequence by its position.
Definition: Individual.cpp:295
void deleteGenotype()
Delete the genotype of the individual.
Definition: Individual.cpp:450
std::unique_ptr< MultilocusGenotype > genotype_
Definition: Individual.h:48
std::shared_ptr< const Locality< double > > locality_
Definition: Individual.h:46
unsigned short sex_
Definition: Individual.h:43
void setMonolocusGenotypeByAlleleId(size_t locusPosition, const std::vector< std::string > alleleId, const LocusInfo &locusInfo)
Set a MonolocusGenotype.
Definition: Individual.cpp:502
size_t countHeterozygousLoci() const
Count the number of heterozygous MonolocusGenotype.
Definition: Individual.cpp:556
double getX() const
Get the X coordinate of the Individual.
Definition: Individual.cpp:213
const Date & date() const
Get the date of the Individual.
Definition: Individual.cpp:144
void setSequences(const SequenceContainerInterface &sc)
Set all the sequences with a SequenceContainer. The container will be copied.
Definition: Individual.h:362
const Alphabet & sequenceAlphabet() const
Return the alphabet of the sequences.
Definition: Individual.cpp:407
The Locality class.
Definition: Locality.h:25
The LocusInfo class.
Definition: LocusInfo.h:31
The MonolocusGenotype virtual class.
The MultilocusGenotype class.
TemplateVectorSequenceContainer< Sequence > VectorSequenceContainer