bpp-popgen  3.0.0
Individual.h
Go to the documentation of this file.
1 //
2 // File Individual.h
3 // Author : Sylvain Gaillard
4 // Last modification : Tuesday August 03 2004
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for population genetics analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _INDIVIDUAL_H_
41 #define _INDIVIDUAL_H_
42 
43 // From STL
44 #include <vector>
45 #include <memory>
46 
47 #include <Bpp/Graphics/Point2D.h>
48 #include <Bpp/Exceptions.h>
49 #include <Bpp/Text/TextTools.h>
50 
51 // From SeqLib
52 #include <Bpp/Seq/Sequence.h>
56 
57 // From PopGenLib
58 #include "Locality.h"
59 #include "Date.h"
60 #include "../MultilocusGenotype.h"
61 #include "../GeneralExceptions.h"
62 
63 namespace bpp
64 {
76 {
77 protected:
78  std::string id_;
79  unsigned short sex_;
80  std::unique_ptr<Date> date_;
81  std::unique_ptr< Point2D<double> > coord_;
83  std::unique_ptr<MapSequenceContainer> sequences_;
84  std::unique_ptr<MultilocusGenotype> genotype_;
85 
86 public:
87  // Constructors and destructor :
91  Individual();
92 
96  Individual(const std::string& id);
97 
108  Individual(const std::string& id,
109  const Date& date,
110  const Point2D<double>& coord,
111  Locality<double>* locality,
112  const unsigned short sex);
113 
117  Individual(const Individual& ind);
118 
122  virtual ~Individual();
123 
124 public:
125  // Methods
132  Individual& operator=(const Individual& ind);
133 
139  void setId(const std::string& id);
140 
146  const std::string& getId() const { return id_; }
147 
153  void setSex(const unsigned short sex);
154 
160  unsigned short getSex() const { return sex_; }
161 
167  void setDate(const Date& date);
168 
175  const Date& getDate() const;
176 
180  bool hasDate() const;
181 
187  void setCoord(const Point2D<double>& coord);
188 
195  void setCoord(const double x, const double y);
196 
203  const Point2D<double>& getCoord() const;
204 
208  bool hasCoord() const;
209 
218  void setX(const double x);
219 
228  void setY(const double y);
229 
236  double getX() const;
237 
244  double getY() const;
245 
251  void setLocality(const Locality<double>* locality);
252 
258  const Locality<double>* getLocality() const;
259 
263  bool hasLocality() const;
264 
277  void addSequence(size_t sequence_key, const Sequence& sequence);
278 
287  const Sequence& getSequenceByName(const std::string& sequence_name) const;
288 
297  const Sequence& getSequenceAtPosition(const size_t sequence_position) const;
298 
306  void deleteSequenceByName(const std::string& sequence_name);
307 
315  void deleteSequenceAtPosition(size_t sequence_position);
316 
323  bool hasSequences() const;
324 
328  bool hasSequenceAtPosition(size_t position) const;
329 
335  const Alphabet* getSequenceAlphabet() const;
336 
343  std::vector<std::string> getSequencesNames() const;
344 
351  std::vector<size_t> getSequencesPositions() const;
352 
359  size_t getSequencePosition(const std::string& sequence_name) const;
360 
364  size_t getNumberOfSequences() const;
365 
369  void setSequences(const MapSequenceContainer& msc);
370 
376  const OrderedSequenceContainer& getSequences() const;
377 
383  void setGenotype(const MultilocusGenotype& genotype);
384 
391  void initGenotype(size_t loci_number);
392 
396  const MultilocusGenotype& getGenotype() const;
397 
401  void deleteGenotype();
402 
406  bool hasGenotype() const;
407 
414  void setMonolocusGenotype(size_t locus_position, const MonolocusGenotype& monogen);
415 
424  size_t locus_position,
425  const std::vector<size_t> allele_keys);
426 
435  size_t locus_position,
436  const std::vector<std::string> allele_id,
437  const LocusInfo& locus_info);
438 
445  const MonolocusGenotype& getMonolocusGenotype(size_t locus_position);
446 
452  size_t countNonMissingLoci() const;
453 
459  size_t countHomozygousLoci() const;
460 
466  size_t countHeterozygousLoci() const;
467 };
468 } // end of namespace bpp;
469 
470 #endif // _INDIVIDUAL_H_
471 
The Date class.
Definition: Date.h:57
The Individual class.
Definition: Individual.h:76
double getY() const
Get the Y coordinate of the Individual.
Definition: Individual.cpp:262
std::unique_ptr< Point2D< double > > coord_
Definition: Individual.h:81
bool hasCoord() const
Tell if this Individual has coordinates.
Definition: Individual.cpp:225
const Sequence & getSequenceAtPosition(const size_t sequence_position) const
Get a sequence by its position.
Definition: Individual.cpp:338
std::vector< size_t > getSequencesPositions() const
Get the sequences' positions.
Definition: Individual.cpp:395
bool hasSequences() const
Tell if the Individual has some sequences.
Definition: Individual.cpp:426
virtual ~Individual()
Destroy an Individual.
Definition: Individual.cpp:113
void setMonolocusGenotypeByAlleleKey(size_t locus_position, const std::vector< size_t > allele_keys)
Set a MonolocusGenotype.
Definition: Individual.cpp:547
Individual()
Build a void new Individual.
Definition: Individual.cpp:47
unsigned short getSex() const
Get the sex of the Individual.
Definition: Individual.h:160
void setSex(const unsigned short sex)
Set the sex of the Individual.
Definition: Individual.cpp:168
std::unique_ptr< Date > date_
Definition: Individual.h:80
std::vector< std::string > getSequencesNames() const
Get the sequences' names.
Definition: Individual.cpp:386
size_t countNonMissingLoci() const
Count the number of non missing MonolocusGenotype.
Definition: Individual.cpp:603
void addSequence(size_t sequence_key, const Sequence &sequence)
Add a sequence to the Individual.
Definition: Individual.cpp:298
std::string id_
Definition: Individual.h:78
void setGenotype(const MultilocusGenotype &genotype)
Set a genotype.
Definition: Individual.cpp:485
void setMonolocusGenotypeByAlleleId(size_t locus_position, const std::vector< std::string > allele_id, const LocusInfo &locus_info)
Set a MonolocusGenotype.
Definition: Individual.cpp:567
std::unique_ptr< MapSequenceContainer > sequences_
Definition: Individual.h:83
void initGenotype(size_t loci_number)
Init the genotype.
Definition: Individual.cpp:492
const std::string & getId() const
Get the id of the Individual.
Definition: Individual.h:146
void setCoord(const Point2D< double > &coord)
Set the coodinates of the Individual.
Definition: Individual.cpp:201
void setY(const double y)
Set the Y coordinate of th Individual.
Definition: Individual.cpp:242
void setId(const std::string &id)
Set the id of the Individual.
Definition: Individual.cpp:160
bool hasGenotype() const
Tell if the Individual has a MultilocusGenotype.
Definition: Individual.cpp:524
Individual & operator=(const Individual &ind)
The Individual copy operator.
Definition: Individual.cpp:117
void deleteSequenceByName(const std::string &sequence_name)
Delete a sequence.
Definition: Individual.cpp:354
const Sequence & getSequenceByName(const std::string &sequence_name) const
Get a sequence by its name.
Definition: Individual.cpp:322
void setDate(const Date &date)
Set the date of the Individual.
Definition: Individual.cpp:176
const MultilocusGenotype & getGenotype() const
Get the genotype.
Definition: Individual.cpp:508
const OrderedSequenceContainer & getSequences() const
Get a reference to the sequence container.
Definition: Individual.cpp:474
const Locality< double > * getLocality() const
Get the locality of the Individual.
Definition: Individual.cpp:280
const Locality< double > * locality_
Definition: Individual.h:82
bool hasSequenceAtPosition(size_t position) const
Tell if the Individual has a sequence at a given position.
Definition: Individual.cpp:433
size_t countHomozygousLoci() const
Count the number of homozygous MonolocusGenotype.
Definition: Individual.cpp:612
void deleteSequenceAtPosition(size_t sequence_position)
Delete a sequence.
Definition: Individual.cpp:370
void setMonolocusGenotype(size_t locus_position, const MonolocusGenotype &monogen)
Set a MonolocusGenotype.
Definition: Individual.cpp:531
void setX(const double x)
Set the X coordinate of the Individual.
Definition: Individual.cpp:232
void setLocality(const Locality< double > *locality)
Set the locality of the Individual.
Definition: Individual.cpp:273
bool hasDate() const
Tell if this Individual has a date.
Definition: Individual.cpp:193
const MonolocusGenotype & getMonolocusGenotype(size_t locus_position)
Get a MonolocusGenotype.
Definition: Individual.cpp:587
void setSequences(const MapSequenceContainer &msc)
Set all the sequences with a MapSequenceContainer.
Definition: Individual.cpp:467
size_t getSequencePosition(const std::string &sequence_name) const
Get the position of a sequence.
Definition: Individual.cpp:410
void deleteGenotype()
Delete the genotype of the individual.
Definition: Individual.cpp:517
std::unique_ptr< MultilocusGenotype > genotype_
Definition: Individual.h:84
unsigned short sex_
Definition: Individual.h:79
size_t countHeterozygousLoci() const
Count the number of heterozygous MonolocusGenotype.
Definition: Individual.cpp:621
double getX() const
Get the X coordinate of the Individual.
Definition: Individual.cpp:252
const Date & getDate() const
Get the date of the Individual.
Definition: Individual.cpp:183
const Alphabet * getSequenceAlphabet() const
Return the alphabet of the sequences.
Definition: Individual.cpp:449
size_t getNumberOfSequences() const
Get the number of sequences.
Definition: Individual.cpp:458
const Point2D< double > & getCoord() const
Get the coordinates of the Induvidual.
Definition: Individual.cpp:215
bool hasLocality() const
Tell if this Individual has a locality.
Definition: Individual.cpp:290
The LocusInfo class.
Definition: LocusInfo.h:64
The MonolocusGenotype virtual class.
The MultilocusGenotype class.