65 const Point2D<double>& coord,
67 const unsigned short sex) :
70 date_(new
Date(date)),
71 coord_(new Point2D<double>(coord)),
125 catch (NullPointerException)
133 catch (NullPointerException)
141 catch (NullPointerException)
149 catch (NullPointerException)
188 throw (NullPointerException(
"Individual::getDate: no date associated to this individual."));
195 return date_.get() != 0;
203 coord_.reset(
new Point2D<double>(coord));
210 coord_.reset(
new Point2D<double>(x, y));
220 throw (NullPointerException(
"Individual::getCoord: no coord associated to this individual."));
237 throw (NullPointerException(
"Individual::setX: no coord associated to this individual."));
247 throw (NullPointerException(
"Individual::setY: no coord associated to this individual."));
257 throw (NullPointerException(
"Individual::getX: no coord associated to this individual."));
267 throw (NullPointerException(
"Individual::getY: no coord associated to this individual."));
285 throw (NullPointerException(
"Individual::getLocality: no locality associated to this individual."));
301 if (sequences_.get() == 0)
302 sequences_.reset(
new MapSequenceContainer(sequence.getAlphabet()));
305 sequences_->addSequence(TextTools::toString(sequence_key), sequence);
307 catch (AlphabetMismatchException& ame)
309 throw (AlphabetMismatchException(
"Individual::addSequence: alphabets don't match.", ame.getAlphabets()[0], ame.getAlphabets()[1]));
313 if (
string(e.what()).find(
"name") < string(e.what()).size())
314 throw (
BadIdentifierException(
"Individual::addSequence: sequence's name already in use.", sequence.getName()));
317 throw (Exception(
"Individual::addSequence: sequence_key already in use:" + TextTools::toString(sequence_key)));
324 const throw (Exception)
326 if (sequences_.get() == 0)
327 throw NullPointerException(
"Individual::getSequenceByName: no sequence data.");
330 return sequences_->getSequence(sequence_name);
332 catch (SequenceNotFoundException& snfe)
334 throw SequenceNotFoundException(
"Individual::getSequenceByName: sequence_name not found.", snfe.getSequenceId());
341 const throw (Exception)
343 if (sequences_.get() == 0)
344 throw NullPointerException(
"Individual::getSequenceAtPosition: no sequence data.");
347 return sequences_->getSequenceByKey(TextTools::toString(sequence_position));
349 catch (SequenceNotFoundException& snfe)
351 throw SequenceNotFoundException(
"Individual::getSequenceAtPosition: sequence_position not found", snfe.getSequenceId());
359 if (sequences_.get() == 0)
360 throw NullPointerException(
"Individual::deleteSequenceByName: no sequence data.");
363 sequences_->deleteSequence(sequence_name);
365 catch (SequenceNotFoundException& snfe)
367 throw SequenceNotFoundException(
"Individual::deleteSequenceByName: sequence_name not found.", snfe.getSequenceId());
375 if (sequences_.get() == 0)
376 throw NullPointerException(
"Individual::deleteSequenceAtPosition: no sequence data.");
379 sequences_->deleteSequenceByKey(TextTools::toString(sequence_position));
381 catch (SequenceNotFoundException& snfe)
383 throw SequenceNotFoundException(
"Individual::deleteSequenceAtPosition: sequence_position not found.", snfe.getSequenceId());
392 throw NullPointerException(
"Individual::getSequencesNames: no sequence data.");
401 throw NullPointerException(
"Individual::getSequencesPositions: no sequence data.");
402 vector<size_t> seqpos;
403 vector<string> seqkeys =
sequences_->getKeys();
404 for (
size_t i = 0; i < seqkeys.size(); i++)
406 seqpos.push_back((
size_t) TextTools::toInt(seqkeys[i]));
415 if (sequences_.get() == 0)
416 throw NullPointerException(
"Individual::getSequencePosition: no sequence data.");
419 return (
size_t) TextTools::toInt(sequences_->getKey(getSequencePosition(sequence_name)));
421 catch (SequenceNotFoundException& snfe)
423 throw SequenceNotFoundException(
"Individual::getSequencePosition: sequence_name not found.", snfe.getSequenceId());
441 for (
size_t i = 0; i < pos.size(); i++)
443 if (pos[i] == position)
455 throw NullPointerException(
"Individual::getSequenceAlphabet: no sequence data.");
472 sequences_.reset(
new MapSequenceContainer(msc));
480 throw NullPointerException(
"Individual::getSequences: no sequence data.");
498 throw Exception(
"Individual::initGenotype: individual already has a genotype.");
503 catch (BadIntegerException& bie)
505 throw BadIntegerException(
"Individual::initGenotype: loci_number must be > 0.", bie.getBadInteger());
514 throw NullPointerException(
"Individual::getGenotype: individual has no genotype.");
537 throw NullPointerException(
"Individual::setMonolocusGenotype: individual has no genotype.");
540 genotype_->setMonolocusGenotype(locus_position, monogen);
542 catch (IndexOutOfBoundsException& ioobe)
544 throw IndexOutOfBoundsException(
"Individual::setMonolocusGenotype: locus_position out of boubds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
553 throw NullPointerException(
"Individual::setMonolocusGenotypeByAlleleKey: individual has no genotype.");
556 genotype_->setMonolocusGenotypeByAlleleKey(locus_position, allele_keys);
558 catch (IndexOutOfBoundsException& ioobe)
560 throw IndexOutOfBoundsException(
"Individual::setMonolocusGenotypeByAlleleKey: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
564 throw Exception(
"Individual::setMonolocusGenotypeByAlleleKey: no key in allele_keys.");
573 throw NullPointerException(
"Individual::setMonolocusGenotypeByAlleleId: individual has no genotype.");
576 genotype_->setMonolocusGenotypeByAlleleId(locus_position, allele_id, locus_info);
578 catch (IndexOutOfBoundsException& ioobe)
580 throw IndexOutOfBoundsException(
"Individual::setMonolocusGenotypeByAlleleId: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
593 throw NullPointerException(
"Individual::getMonolocusGenotype: individual has no genotype.");
596 return genotype_->getMonolocusGenotype(locus_position);
598 catch (IndexOutOfBoundsException& ioobe)
600 throw IndexOutOfBoundsException(
"Individual::getMonolocusGenotype: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
609 throw NullPointerException(
"Individual::countNonMissingLoci: individual has no genotype.");
618 throw NullPointerException(
"Individual::countHomozygousLoci: individual has no genotype.");
627 throw NullPointerException(
"Individual::countHeterozygousLoci: individual has no genotype.");
628 return genotype_->countHeterozygousLoci();
virtual ~Individual()
Destroy an Individual.
size_t getNumberOfSequences() const
Get the number of sequences.
void setSex(const unsigned short sex)
Set the sex of the Individual.
void setDate(const Date &date)
Set the date of the Individual.
const Point2D< double > & getCoord() const
Get the coordinates of the Induvidual.
void initGenotype(size_t loci_number)
Init the genotype.
double getX() const
Get the X coordinate of the Individual.
const Alphabet * getSequenceAlphabet() const
Return the alphabet of the sequences.
bool hasCoord() const
Tell if this Individual has coordinates.
void setX(const double x)
Set the X coordinate of the Individual.
bool hasLocality() const
Tell if this Individual has a locality.
std::vector< std::string > getSequencesNames() const
Get the sequences' names.
void setSequences(const MapSequenceContainer &msc)
Set all the sequences with a MapSequenceContainer.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
const Locality< double > * locality_
const MonolocusGenotype & getMonolocusGenotype(size_t locus_position)
Get a MonolocusGenotype.
Individual()
Build a void new Individual.
The BadIdentifierException class.
void setId(const std::string &id)
Set the id of the Individual.
const Sequence & getSequenceByName(const std::string &sequence_name) const
Get a sequence by its name.
The MultilocusGenotype class.
const Locality< double > * getLocality() const
Get the locality of the Individual.
bool hasGenotype() const
Tell if the Individual has a MultilocusGenotype.
The AlleleNotFoundException class.
std::vector< size_t > getSequencesPositions() const
Get the sequences' positions.
bool hasSequences() const
Tell if the Individual has some sequences.
size_t getSequencePosition(const std::string &sequence_name) const
Get the position of a sequence.
bool hasDate() const
Tell if this Individual has a date.
void setMonolocusGenotypeByAlleleKey(size_t locus_position, const std::vector< size_t > allele_keys)
Set a MonolocusGenotype.
const std::string & getId() const
Get the id of the Individual.
void setMonolocusGenotypeByAlleleId(size_t locus_position, const std::vector< std::string > allele_id, const LocusInfo &locus_info)
Set a MonolocusGenotype.
std::auto_ptr< Point2D< double > > coord_
std::auto_ptr< Date > date_
void setGenotype(const MultilocusGenotype &genotype)
Set a genotype.
size_t countHeterozygousLoci() const
Count the number of heterozygous MonolocusGenotype.
Individual & operator=(const Individual &ind)
The Individual copy operator.
bool hasSequenceAtPosition(size_t position) const
Tell if the Individual has a sequence at a given position.
const Sequence & getSequenceAtPosition(const size_t sequence_position) const
Get a sequence by its position.
size_t countHomozygousLoci() const
Count the number of homozygous MonolocusGenotype.
void deleteGenotype()
Delete the genotype of the individual.
void deleteSequenceByName(const std::string &sequence_name)
Delete a sequence.
std::auto_ptr< MultilocusGenotype > genotype_
const Date & getDate() const
Get the date of the Individual.
The MonolocusGenotype virtual class.
void setCoord(const Point2D< double > &coord)
Set the coodinates of the Individual.
unsigned short getSex() const
Get the sex of the Individual.
void setLocality(const Locality< double > *locality)
Set the locality of the Individual.
const OrderedSequenceContainer & getSequences() const
Get a reference to the sequence container.
const MultilocusGenotype & getGenotype() const
Get the genotype.
void addSequence(size_t sequence_key, const Sequence &sequence)
Add a sequence to the Individual.
void setMonolocusGenotype(size_t locus_position, const MonolocusGenotype &monogen)
Set a MonolocusGenotype.
double getY() const
Get the Y coordinate of the Individual.
void setY(const double y)
Set the Y coordinate of th Individual.
std::auto_ptr< MapSequenceContainer > sequences_
void deleteSequenceAtPosition(size_t sequence_position)
Delete a sequence.
size_t countNonMissingLoci() const
Count the number of non missing MonolocusGenotype.