bpp-popgen3  3.0.0
bpp::Individual Class Reference

The Individual class. More...

#include <Bpp/PopGen/DataSet/Individual.h>

+ Collaboration diagram for bpp::Individual:

Public Member Functions

 Individual ()
 Build a void new Individual. More...
 
 Individual (const std::string &id)
 Build a new Individual with an identifier. More...
 
 Individual (const std::string &id, const Date &date, const Point2D< double > &coord, std::shared_ptr< Locality< double >> locality, const unsigned short sex)
 Build a new Individual with parameters. More...
 
 Individual (const Individual &ind)
 The Individual copy constructor. More...
 
virtual ~Individual ()
 Destroy an Individual. More...
 
Individualoperator= (const Individual &ind)
 The Individual copy operator. More...
 
void setId (const std::string &id)
 Set the id of the Individual. More...
 
const std::string & getId () const
 Get the id of the Individual. More...
 
void setSex (const unsigned short sex)
 Set the sex of the Individual. More...
 
unsigned short getSex () const
 Get the sex of the Individual. More...
 
void setDate (const Date &date)
 Set the date of the Individual. More...
 
const Datedate () const
 Get the date of the Individual. More...
 
bool hasDate () const
 Tell if this Individual has a date. More...
 
void setCoord (const Point2D< double > &coord)
 Set the coordinates of the Individual. More...
 
void setCoord (const double x, const double y)
 Set the coordinates of the Individual. More...
 
const Point2D< double > & coord () const
 Get the coordinates of the Induvidual. More...
 
bool hasCoord () const
 Tell if this Individual has coordinates. More...
 
void setX (const double x)
 Set the X coordinate of the Individual. More...
 
void setY (const double y)
 Set the Y coordinate of th Individual. More...
 
double getX () const
 Get the X coordinate of the Individual. More...
 
double getY () const
 Get the Y coordinate of the Individual. More...
 
void setLocality (std::shared_ptr< const Locality< double >> locality)
 Set the locality of the Individual. More...
 
std::shared_ptr< const Locality< double > > getLocality () const
 Get the locality of the Individual. More...
 
const Locality< double > & locality () const
 Get the locality of the Individual. More...
 
bool hasLocality () const
 Tell if this Individual has a locality. More...
 
void addSequence (size_t sequenceKey, std::unique_ptr< Sequence > &sequence)
 Add a sequence to the Individual. More...
 
const SequencesequenceByName (const std::string &sequenceName) const
 Get a sequence from its name. More...
 
const SequencesequenceAtPosition (size_t sequencePosition) const
 Get a sequence by its position. More...
 
void deleteSequenceByName (const std::string &sequenceName)
 Delete a sequence. More...
 
void deleteSequenceAtPosition (size_t sequencePosition)
 Delete a sequence. More...
 
bool hasSequences () const
 Tell if the Individual has some sequences. More...
 
bool hasSequenceAtPosition (size_t position) const
 Tell if the Individual has a sequence at a given position. More...
 
std::shared_ptr< const AlphabetgetSequenceAlphabet () const
 Return the alphabet of the sequences. More...
 
const AlphabetsequenceAlphabet () const
 Return the alphabet of the sequences. More...
 
std::vector< std::string > getSequenceNames () const
 Get the sequence names. More...
 
std::vector< size_t > getSequencePositions () const
 Get the sequences' positions. More...
 
size_t getSequencePosition (const std::string &sequenceKey) const
 Get the position of a sequence. More...
 
size_t getNumberOfSequences () const
 Get the number of sequences. More...
 
void setSequences (const SequenceContainerInterface &sc)
 Set all the sequences with a SequenceContainer. The container will be copied. More...
 
const SequenceContainerInterfacesequences () const
 Get a reference to the sequence container. More...
 
void setGenotype (const MultilocusGenotype &genotype)
 Set a genotype. More...
 
void initGenotype (size_t lociNumber)
 Init the genotype. More...
 
const MultilocusGenotypegetGenotype () const
 Get the genotype. More...
 
void deleteGenotype ()
 Delete the genotype of the individual. More...
 
bool hasGenotype () const
 Tell if the Individual has a MultilocusGenotype. More...
 
void setMonolocusGenotype (size_t locusPosition, const MonolocusGenotypeInterface &monogen)
 Set a MonolocusGenotype. More...
 
void setMonolocusGenotypeByAlleleKey (size_t locusPosition, const std::vector< size_t > alleleKeys)
 Set a MonolocusGenotype. More...
 
void setMonolocusGenotypeByAlleleId (size_t locusPosition, const std::vector< std::string > alleleId, const LocusInfo &locusInfo)
 Set a MonolocusGenotype. More...
 
const MonolocusGenotypeInterfacegetMonolocusGenotype (size_t locusPosition)
 Get a MonolocusGenotype. More...
 
size_t countNonMissingLoci () const
 Count the number of non missing MonolocusGenotype. More...
 
size_t countHomozygousLoci () const
 Count the number of homozygous MonolocusGenotype. More...
 
size_t countHeterozygousLoci () const
 Count the number of heterozygous MonolocusGenotype. More...
 

Protected Attributes

std::string id_
 
unsigned short sex_
 
std::unique_ptr< Datedate_
 
std::unique_ptr< Point2D< double > > coord_
 
std::shared_ptr< const Locality< double > > locality_
 
std::unique_ptr< VectorSequenceContainersequences_
 
std::unique_ptr< MultilocusGenotypegenotype_
 

Detailed Description

The Individual class.

This class is designed to store data on a single individual. This individual has only one sequence for each locus ... no information about diploid sequence data. See the no more in use MultiSeqIndividual documentation for an alternative.

Author
Sylvain Gaillard

Definition at line 39 of file Individual.h.

Constructor & Destructor Documentation

◆ Individual() [1/4]

Individual::Individual ( )

Build a void new Individual.

Definition at line 12 of file Individual.cpp.

◆ Individual() [2/4]

Individual::Individual ( const std::string &  id)

Build a new Individual with an identifier.

Definition at line 21 of file Individual.cpp.

◆ Individual() [3/4]

Individual::Individual ( const std::string &  id,
const Date date,
const Point2D< double > &  coord,
std::shared_ptr< Locality< double >>  locality,
const unsigned short  sex 
)

Build a new Individual with parameters.

Parameters
idThe id of the Individual as a string.
dateThe date of the Individual as a Date object.
coordThe coordinates of the Individual as a Point2D object.
localityThe locality of the Individual as a pointer to a Locality object.
sexThe sex of the Individual as an unsigned short.

Definition at line 29 of file Individual.cpp.

◆ Individual() [4/4]

Individual::Individual ( const Individual ind)

The Individual copy constructor.

Definition at line 42 of file Individual.cpp.

References coord(), date(), genotype_, getGenotype(), hasGenotype(), sequences(), setCoord(), setDate(), and setSequences().

◆ ~Individual()

Individual::~Individual ( )
virtual

Destroy an Individual.

Definition at line 74 of file Individual.cpp.

Member Function Documentation

◆ addSequence()

void Individual::addSequence ( size_t  sequenceKey,
std::unique_ptr< Sequence > &  sequence 
)

Add a sequence to the Individual.

Creates the sequence container when adding the first sequence. Otherwise add the sequence to the end of the sequence container.

Parameters
sequenceKeythe place where the sequence will be put.
sequenceThe sequence to add.
Exceptions
AlphabetMismatchExceptionif the sequence's alphabet doesn't match the container's alphabet.
BadIdentifierExceptionif sequence's name is already in use.
BadIntegerExceptionif sequence_position is already in use.

Definition at line 254 of file Individual.cpp.

References bpp::AlphabetMismatchException::getFirstAlphabet(), bpp::AlphabetMismatchException::getSecondAlphabet(), sequences_, bpp::TextTools::toString(), and bpp::Exception::what().

Referenced by bpp::PopgenlibIO::parseIndividual_().

◆ coord()

const Point2D< double > & Individual::coord ( ) const

Get the coordinates of the Induvidual.

Returns
A pointer toward a Point2D object if the Individual has coordinates. Otherwise throw a NullPointerException.

Definition at line 176 of file Individual.cpp.

References coord_, and hasCoord().

Referenced by Individual(), operator=(), and setCoord().

◆ countHeterozygousLoci()

size_t Individual::countHeterozygousLoci ( ) const

Count the number of heterozygous MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.

Definition at line 556 of file Individual.cpp.

References genotype_, and hasGenotype().

◆ countHomozygousLoci()

size_t Individual::countHomozygousLoci ( ) const

Count the number of homozygous MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.

Definition at line 547 of file Individual.cpp.

References genotype_, and hasGenotype().

◆ countNonMissingLoci()

size_t Individual::countNonMissingLoci ( ) const

Count the number of non missing MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.

Definition at line 538 of file Individual.cpp.

References genotype_, and hasGenotype().

◆ date()

const Date & Individual::date ( ) const

Get the date of the Individual.

Returns
A reference toward a Date object if the Individual has a date. Otherwise throw a NullPointerException.

Definition at line 144 of file Individual.cpp.

References date_, and hasDate().

Referenced by Individual(), operator=(), and setDate().

◆ deleteGenotype()

void Individual::deleteGenotype ( )

Delete the genotype of the individual.

Definition at line 450 of file Individual.cpp.

References genotype_.

◆ deleteSequenceAtPosition()

void Individual::deleteSequenceAtPosition ( size_t  sequencePosition)

Delete a sequence.

Parameters
sequencePositionThe position of the sequence.
Exceptions
NullPointerExceptionif there is no sequence container defined.
SequenceNotFoundExceptionif sequence_postion is not found.

Definition at line 328 of file Individual.cpp.

References bpp::SequenceNotFoundException::getSequenceId(), sequences_, and bpp::TextTools::toString().

◆ deleteSequenceByName()

void Individual::deleteSequenceByName ( const std::string &  sequenceName)

Delete a sequence.

Parameters
sequenceNameThe name of the sequence.
Exceptions
NullPointerExceptionif there is no sequence container defined.
SequenceNotFoundExceptionif sequence_name is not found.

Definition at line 311 of file Individual.cpp.

References bpp::SequenceNotFoundException::getSequenceId(), sequences_, and bpp::VectorTools::which().

◆ getGenotype()

const MultilocusGenotype & Individual::getGenotype ( ) const

Get the genotype.

Definition at line 441 of file Individual.cpp.

References genotype_, and hasGenotype().

Referenced by Individual(), operator=(), and bpp::DarwinVarSingle::write().

◆ getId()

const std::string& bpp::Individual::getId ( ) const
inline

Get the id of the Individual.

Returns
The id of the Individual as a string.

Definition at line 110 of file Individual.h.

References id_.

Referenced by bpp::Group::addIndividual(), operator=(), bpp::PopgenlibIO::parseIndividual_(), bpp::DarwinDon::write(), and bpp::PopgenlibIO::write().

◆ getLocality()

shared_ptr< const Locality< double > > Individual::getLocality ( ) const

Get the locality of the Individual.

Returns
A pointer to the Locality of the Individual.

Definition at line 233 of file Individual.cpp.

References hasLocality(), and locality_.

Referenced by operator=().

◆ getMonolocusGenotype()

const MonolocusGenotypeInterface & Individual::getMonolocusGenotype ( size_t  locusPosition)

Get a MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.
IndexOutOfBoundsExceptionif locusPosition exceeds the number of loci.

Definition at line 522 of file Individual.cpp.

References genotype_, bpp::IndexOutOfBoundsException::getBadIndex(), bpp::IndexOutOfBoundsException::getBounds(), and hasGenotype().

◆ getNumberOfSequences()

size_t bpp::Individual::getNumberOfSequences ( ) const
inline

Get the number of sequences.

Definition at line 353 of file Individual.h.

References sequences_.

Referenced by hasSequences().

◆ getSequenceAlphabet()

shared_ptr< const Alphabet > Individual::getSequenceAlphabet ( ) const

Return the alphabet of the sequences.

Exceptions
NullPointerExceptionif there is no sequence container defined.

Definition at line 398 of file Individual.cpp.

References sequences_.

Referenced by bpp::DataSet::addIndividualToGroup().

◆ getSequenceNames()

std::vector<std::string> bpp::Individual::getSequenceNames ( ) const
inline

Get the sequence names.

Returns
All the sequences' names of the individual in a vector of string.
Exceptions
NullPointerExceptionif there is no sequence container defined.

Definition at line 327 of file Individual.h.

References sequences_.

◆ getSequencePosition()

size_t Individual::getSequencePosition ( const std::string &  sequenceKey) const

Get the position of a sequence.

Exceptions
NullPointerExceptionif there is no sequence container defined.
SequenceNotFoundExceptionif sequence_name is not found.

Definition at line 359 of file Individual.cpp.

References bpp::SequenceNotFoundException::getSequenceId(), and sequences_.

◆ getSequencePositions()

std::vector< size_t > Individual::getSequencePositions ( ) const

Get the sequences' positions.

Returns
All the positions where a sequence is found.
Exceptions
NullPointerExceptionif there is no sequence container defined.

Definition at line 344 of file Individual.cpp.

References sequences_, and bpp::TextTools::toInt().

Referenced by hasSequenceAtPosition().

◆ getSex()

unsigned short bpp::Individual::getSex ( ) const
inline

Get the sex of the Individual.

Returns
The sex of the Individual as an unsigned short.

Definition at line 124 of file Individual.h.

References sex_.

Referenced by operator=().

◆ getX()

double Individual::getX ( ) const

Get the X coordinate of the Individual.

Returns
The X coordinate as a double if the Individual has coordinates. Otherwise throw a NullPointerException.

Definition at line 213 of file Individual.cpp.

References coord_, and hasCoord().

◆ getY()

double Individual::getY ( ) const

Get the Y coordinate of the Individual.

Returns
The Y coordinate as a double if the Individual has coordinates. Otherwise throw a NullPointerException.

Definition at line 223 of file Individual.cpp.

References coord_, and hasCoord().

◆ hasCoord()

bool Individual::hasCoord ( ) const

Tell if this Individual has coordinates.

Definition at line 186 of file Individual.cpp.

References coord_.

Referenced by coord(), getX(), getY(), setX(), and setY().

◆ hasDate()

bool Individual::hasDate ( ) const

Tell if this Individual has a date.

Definition at line 154 of file Individual.cpp.

References date_.

Referenced by date().

◆ hasGenotype()

◆ hasLocality()

bool bpp::Individual::hasLocality ( ) const
inline

Tell if this Individual has a locality.

Definition at line 237 of file Individual.h.

References locality_.

Referenced by getLocality(), and locality().

◆ hasSequenceAtPosition()

bool Individual::hasSequenceAtPosition ( size_t  position) const

Tell if the Individual has a sequence at a given position.

Definition at line 382 of file Individual.cpp.

References getSequencePositions(), and hasSequences().

◆ hasSequences()

bool Individual::hasSequences ( ) const

Tell if the Individual has some sequences.

Returns
TRUE if the individual has at least one sequence.
FALSE if the container is empty or undifined.

Definition at line 375 of file Individual.cpp.

References getNumberOfSequences().

Referenced by bpp::DataSet::addIndividualToGroup(), and hasSequenceAtPosition().

◆ initGenotype()

void Individual::initGenotype ( size_t  lociNumber)

Init the genotype.

Exceptions
Exceptionif the Individual already has a Genotype.
BadIntegerExceptionif loci_number < 1.

Definition at line 425 of file Individual.cpp.

References genotype_, bpp::BadIntegerException::getBadInteger(), and hasGenotype().

Referenced by bpp::PopgenlibIO::parseIndividual_().

◆ locality()

const Locality< double > & Individual::locality ( ) const

Get the locality of the Individual.

Returns
A pointer to the Locality of the Individual.

Definition at line 243 of file Individual.cpp.

References hasLocality(), and locality_.

Referenced by setLocality().

◆ operator=()

Individual & Individual::operator= ( const Individual ind)

The Individual copy operator.

Returns
A ref toward the assigned Individual. Make a copy of each attribute of the Individual.

Definition at line 78 of file Individual.cpp.

References coord(), coord_, date(), date_, genotype_, getGenotype(), getId(), getLocality(), getSex(), hasGenotype(), locality_, sequences(), sequences_, setCoord(), setDate(), setId(), setLocality(), setSequences(), and setSex().

◆ sequenceAlphabet()

const Alphabet & Individual::sequenceAlphabet ( ) const

Return the alphabet of the sequences.

Exceptions
NullPointerExceptionif there is no sequence container defined.

Definition at line 407 of file Individual.cpp.

References sequences_.

◆ sequenceAtPosition()

const Sequence & Individual::sequenceAtPosition ( size_t  sequencePosition) const

Get a sequence by its position.

Parameters
sequencePositionThe position of the sequence in the sequence set.
Returns
A reference to the sequence.
Exceptions
NullPointerExceptionif there is no sequence container defined.
SequenceNotFoundExceptionif sequence_position is not found (i.e. missing data or not used).

Definition at line 295 of file Individual.cpp.

References bpp::SequenceNotFoundException::getSequenceId(), sequences_, and bpp::TextTools::toString().

◆ sequenceByName()

const Sequence & Individual::sequenceByName ( const std::string &  sequenceName) const

Get a sequence from its name.

Parameters
sequenceNameThe name of the sequence.
Returns
A reference to the sequence.
Exceptions
NullPointerExceptionif there is no sequence container defined.
SequenceNotFoundExceptionif sequence_name is not found.

Definition at line 278 of file Individual.cpp.

References bpp::SequenceNotFoundException::getSequenceId(), sequences_, and bpp::VectorTools::which().

◆ sequences()

const SequenceContainerInterface& bpp::Individual::sequences ( ) const
inline

Get a reference to the sequence container.

Exceptions
NullPointerExceptionif there is no sequence container defined.

Definition at line 372 of file Individual.h.

References sequences_.

Referenced by Individual(), operator=(), and bpp::PopgenlibIO::write().

◆ setCoord() [1/2]

void Individual::setCoord ( const double  x,
const double  y 
)

Set the coordinates of the Individual.

Parameters
xThe X coordinate as a double.
yThe Y coordinate as a double.

Definition at line 169 of file Individual.cpp.

References coord_.

◆ setCoord() [2/2]

void Individual::setCoord ( const Point2D< double > &  coord)

Set the coordinates of the Individual.

Parameters
coordA Point2D object.

Definition at line 162 of file Individual.cpp.

References coord(), and coord_.

Referenced by Individual(), operator=(), and bpp::PopgenlibIO::parseIndividual_().

◆ setDate()

void Individual::setDate ( const Date date)

Set the date of the Individual.

Parameters
dateThe date as a Date object.

Definition at line 137 of file Individual.cpp.

References date(), and date_.

Referenced by Individual(), operator=(), and bpp::PopgenlibIO::parseIndividual_().

◆ setGenotype()

void Individual::setGenotype ( const MultilocusGenotype genotype)

Set a genotype.

Parameters
genotypeThe MultilocusGenotype which will be copied.

Definition at line 418 of file Individual.cpp.

References genotype_.

◆ setId()

void Individual::setId ( const std::string &  id)

Set the id of the Individual.

Parameters
idThe id of the Individual as a string.

Definition at line 121 of file Individual.cpp.

References id_.

Referenced by operator=(), and bpp::PopgenlibIO::parseIndividual_().

◆ setLocality()

void bpp::Individual::setLocality ( std::shared_ptr< const Locality< double >>  locality)
inline

Set the locality of the Individual.

Parameters
localityA pointer to a Locality object.

Definition at line 215 of file Individual.h.

References locality(), and locality_.

Referenced by operator=(), and bpp::PopgenlibIO::parseIndividual_().

◆ setMonolocusGenotype()

void Individual::setMonolocusGenotype ( size_t  locusPosition,
const MonolocusGenotypeInterface monogen 
)

Set a MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.
IndexOutOfBoundsExceptionif locusPosition exceeds the number of loci.

Definition at line 464 of file Individual.cpp.

References genotype_, bpp::IndexOutOfBoundsException::getBadIndex(), bpp::IndexOutOfBoundsException::getBounds(), and hasGenotype().

◆ setMonolocusGenotypeByAlleleId()

void Individual::setMonolocusGenotypeByAlleleId ( size_t  locusPosition,
const std::vector< std::string >  alleleId,
const LocusInfo locusInfo 
)

Set a MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.
IndexOutOfBoundsExceptionif locusPosition exceeds the number of loci.
AlleleNotFoundExceptionif at least one the id is not found in the LocusInfo.

Definition at line 502 of file Individual.cpp.

References genotype_, bpp::IndexOutOfBoundsException::getBadIndex(), bpp::IndexOutOfBoundsException::getBounds(), bpp::AlleleNotFoundException::getIdentifier(), and hasGenotype().

Referenced by bpp::PopgenlibIO::parseIndividual_().

◆ setMonolocusGenotypeByAlleleKey()

void Individual::setMonolocusGenotypeByAlleleKey ( size_t  locusPosition,
const std::vector< size_t >  alleleKeys 
)

Set a MonolocusGenotype.

Exceptions
NullPointerExceptionif there is no genotype defined.
IndexOutOfBoundsExceptionif locusPosition exceeds the number of loci.
Exceptionif there is no key in alleleKeys.

Definition at line 482 of file Individual.cpp.

References genotype_, bpp::IndexOutOfBoundsException::getBadIndex(), bpp::IndexOutOfBoundsException::getBounds(), and hasGenotype().

◆ setSequences()

void bpp::Individual::setSequences ( const SequenceContainerInterface sc)
inline

Set all the sequences with a SequenceContainer. The container will be copied.

Definition at line 362 of file Individual.h.

References sequences_.

Referenced by Individual(), and operator=().

◆ setSex()

void Individual::setSex ( const unsigned short  sex)

Set the sex of the Individual.

Parameters
sexAn unsigned short coding for the sex.

Definition at line 129 of file Individual.cpp.

References sex_.

Referenced by operator=().

◆ setX()

void Individual::setX ( const double  x)

Set the X coordinate of the Individual.

Parameters
xThe X coordinate as a double.

Set the X coordinate if the Individual has coordinates. Otherwise throw a NullPointerException.

Definition at line 193 of file Individual.cpp.

References coord_, and hasCoord().

◆ setY()

void Individual::setY ( const double  y)

Set the Y coordinate of th Individual.

Parameters
yThe Y coordinate as a double.

Set the Y coordinate if the Individual has coordinates. Otherwise throw a NullPointerException.

Definition at line 203 of file Individual.cpp.

References coord_, and hasCoord().

Member Data Documentation

◆ coord_

std::unique_ptr<Point2D<double> > bpp::Individual::coord_
protected

Definition at line 45 of file Individual.h.

Referenced by coord(), getX(), getY(), hasCoord(), operator=(), setCoord(), setX(), and setY().

◆ date_

std::unique_ptr<Date> bpp::Individual::date_
protected

Definition at line 44 of file Individual.h.

Referenced by date(), hasDate(), operator=(), and setDate().

◆ genotype_

◆ id_

std::string bpp::Individual::id_
protected

Definition at line 42 of file Individual.h.

Referenced by getId(), and setId().

◆ locality_

std::shared_ptr<const Locality<double> > bpp::Individual::locality_
protected

Definition at line 46 of file Individual.h.

Referenced by getLocality(), hasLocality(), locality(), operator=(), and setLocality().

◆ sequences_

◆ sex_

unsigned short bpp::Individual::sex_
protected

Definition at line 43 of file Individual.h.

Referenced by getSex(), and setSex().


The documentation for this class was generated from the following files: