16 getIndividualPosition(ind.
getId());
21 individuals_.push_back(make_unique<Individual>(ind));
26 for (
size_t i = 0; i < getNumberOfIndividuals(); ++i)
28 if (individuals_[i]->getId() == individualId)
31 individuals_.push_back(make_unique<Individual>(individualId));
36 for (
size_t i = 0; i < getNumberOfIndividuals(); ++i)
38 if (individuals_[i]->getId() == individualId)
48 size_t indPos = getIndividualPosition(individualId);
49 unique_ptr<Individual> ind = std::move(individuals_[indPos]);
50 individuals_.erase(individuals_.begin() +
static_cast<ptrdiff_t
>(indPos));
61 if (individualPosition >= individuals_.size())
63 unique_ptr<Individual> ind = std::move(individuals_[individualPosition]);
64 individuals_.erase(individuals_.begin() +
static_cast<ptrdiff_t
>(individualPosition));
72 removeIndividualById(individualId);
84 removeIndividualAtPosition(individualPosition);
94 for (
size_t i = 0; i < individuals_.size(); ++i)
96 if (individuals_[i]->getId() == individualId)
97 return getIndividualAtPosition(i);
104 if (individualPosition >= individuals_.size())
105 throw IndexOutOfBoundsException(
"Group::getIndividualAtPosition: individualPosition out of bounds.", individualPosition, 0, individuals_.size());
106 return *individuals_[individualPosition];
112 for (
size_t i = 0; i < getNumberOfIndividuals(); ++i)
114 vector<size_t> seqpos = individuals_[i]->getSequencePositions();
115 for (
size_t j = 0; j < seqpos.size(); ++j)
117 if (maxnum < seqpos[j])
128 if (individualPosition >= getNumberOfIndividuals())
129 throw IndexOutOfBoundsException(
"Group::setIndividualSexAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
130 individuals_[individualPosition]->setSex(sex);
135 if (individualPosition >= getNumberOfIndividuals())
136 throw IndexOutOfBoundsException(
"Group::getIndividualSexAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
137 return individuals_[individualPosition]->getSex();
142 if (individualPosition >= getNumberOfIndividuals())
143 throw IndexOutOfBoundsException(
"Group::setIndividualDateAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
144 individuals_[individualPosition]->setDate(date);
149 if (individualPosition >= getNumberOfIndividuals())
150 throw IndexOutOfBoundsException(
"Group::getIndividualDateAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
153 return individuals_[individualPosition]->date();
163 if (individualPosition >= getNumberOfIndividuals())
164 throw IndexOutOfBoundsException(
"Group::setIndividualCoordAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
165 individuals_[individualPosition]->setCoord(coord);
170 if (individualPosition >= getNumberOfIndividuals())
171 throw IndexOutOfBoundsException(
"Group::getIndividualCoordAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
174 return individuals_[individualPosition]->coord();
178 throw NullPointerException(
"Group::getIndividualCoordAtPosition: individual has no coordinates.");
184 if (individualPosition >= getNumberOfIndividuals())
185 throw IndexOutOfBoundsException(
"Group::setIndividualLocalityAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
186 individuals_[individualPosition]->setLocality(locality);
191 if (individualPosition >= getNumberOfIndividuals())
192 throw IndexOutOfBoundsException(
"Group::getIndividualLocalityAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
195 return individuals_[individualPosition]->getLocality();
199 throw NullPointerException(
"Group::getIndividualLocalityAtPosition: individuals has no locality.");
205 if (individualPosition >= getNumberOfIndividuals())
206 throw IndexOutOfBoundsException(
"Group::addIndividualSequenceAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
209 individuals_[individualPosition]->addSequence(sequencePosition, sequence);
221 throw BadIntegerException(
"Group::addIndividualSequenceAtPosition: sequencePosition already in use.", bie.getBadInteger());
227 if (individualPosition >= getNumberOfIndividuals())
228 throw IndexOutOfBoundsException(
"Group::getIndividualSequenceByName: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
231 return individuals_[individualPosition]->sequenceByName(sequenceName);
235 throw NullPointerException(
"Group::getIndividualSequenceByName: no sequence data in individual.");
245 if (individualPosition >= getNumberOfIndividuals())
246 throw IndexOutOfBoundsException(
"Group::getIndividualAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
249 return individuals_[individualPosition]->sequenceAtPosition(sequencePosition);
253 throw NullPointerException(
"Group::getIndividualSequenceAtPosition: no sequence data in individual.");
263 if (individualPosition >= getNumberOfIndividuals())
264 throw IndexOutOfBoundsException(
"Group::deleteIndividualSequenceByName: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
267 individuals_[individualPosition]->deleteSequenceByName(sequence_name);
281 if (individualPosition >= getNumberOfIndividuals())
282 throw IndexOutOfBoundsException(
"Group::deleteIndividualSequenceAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
285 individuals_[individualPosition]->deleteSequenceAtPosition(sequencePosition);
299 if (individualPosition >= getNumberOfIndividuals())
300 throw IndexOutOfBoundsException(
"Group::hasIndividualSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
301 return individuals_[individualPosition]->hasSequences();
306 if (individualPosition >= getNumberOfIndividuals())
307 throw IndexOutOfBoundsException(
"Group::getIndividualSequencesNames: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
310 return individuals_[individualPosition]->getSequenceNames();
320 if (individualPosition >= getNumberOfIndividuals())
321 throw IndexOutOfBoundsException(
"Group::getIndividualSequencePosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
324 return individuals_[individualPosition]->getSequencePosition(sequence_name);
338 if (individualPosition >= getNumberOfIndividuals())
339 throw IndexOutOfBoundsException(
"Group::getIndividualNumberOfSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
342 return individuals_[individualPosition]->getNumberOfSequences();
346 throw NullPointerException(
"Group::getIndividualNumberOfSequences: no sequence data in individual.");
352 if (individualPosition >= getNumberOfIndividuals())
353 throw IndexOutOfBoundsException(
"Group::setIndividualSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
354 individuals_[individualPosition]->setSequences(sc);
359 if (individualPosition >= getNumberOfIndividuals())
360 throw IndexOutOfBoundsException(
"Group::setIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
361 individuals_[individualPosition]->setGenotype(genotype);
366 if (individualPosition >= getNumberOfIndividuals())
367 throw IndexOutOfBoundsException(
"Group::initIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
370 individuals_[individualPosition]->initGenotype(lociNumber);
378 throw Exception(
"Group::initIndividualGenotype: individual already has a genotype.");
384 if (individualPosition >= getNumberOfIndividuals())
385 throw IndexOutOfBoundsException(
"Group::deleteIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
386 individuals_[individualPosition]->deleteGenotype();
391 if (individualPosition >= getNumberOfIndividuals())
392 throw IndexOutOfBoundsException(
"Group::hasIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
393 return individuals_[individualPosition]->hasGenotype();
397 size_t individualPosition,
398 size_t locusPosition,
401 if (individualPosition >= getNumberOfIndividuals())
402 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
405 individuals_[individualPosition]->setMonolocusGenotype(locusPosition, monogen);
409 throw NullPointerException(
"Group::setIndividualMonolocusGenotype: individual has no genotype.");
418 size_t individualPosition,
419 size_t locusPosition,
420 const vector<size_t>& alleleKeys)
422 if (individualPosition >= getNumberOfIndividuals())
423 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleKey: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
426 individuals_[individualPosition]->setMonolocusGenotypeByAlleleKey(locusPosition, alleleKeys);
430 throw NullPointerException(
"Group::setIndividualMonolocusGenotypeByAlleleKey: individual has no genotype.");
438 throw Exception(
"Group::setIndividualMonolocusGenotypeByAlleleKey: no key in allele_keys.");
444 if (individualPosition >= getNumberOfIndividuals())
445 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleId: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
448 individuals_[individualPosition]->setMonolocusGenotypeByAlleleId(locusPosition, allele_id, locus_info);
452 throw NullPointerException(
"Group::setIndividualMonolocusGenotypeByAlleleId: individual has no genotype.");
465 size_t individualPosition,
466 size_t locusPosition)
const
468 if (individualPosition >= getNumberOfIndividuals())
469 throw IndexOutOfBoundsException(
"Group::getIndividualMonolocusGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
472 return individuals_[individualPosition]->getMonolocusGenotype(locusPosition);
476 throw NullPointerException(
"Group::getIndividualMonolocusGenotype: individual has no genotype.");
486 for (
size_t i = 0; i < getNumberOfIndividuals(); ++i)
488 if (hasIndividualSequences(i))
496 for (
size_t i = 0; i < getNumberOfIndividuals(); ++i)
498 if (hasIndividualSequences(i))
499 return individuals_[i]->getSequenceAlphabet();
507 for (
size_t i = 0; i < individuals_.size(); ++i)
509 if (individuals_[i]->hasGenotype() && !individuals_[i]->getGenotype().isMonolocusGenotypeMissing(locusPosition))
518 for (
size_t i = 0; i < individuals_.size(); ++i)
520 if (individuals_[i]->hasSequences())
524 individuals_[i]->sequenceAtPosition(sequencePosition);
The AlleleNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
const Alphabet * getSecondAlphabet() const
const Alphabet * getFirstAlphabet() const
The BadIdentifierException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
int getBadInteger() const
size_t getGroupSizeForSequence(size_t sequencePosition) const
Get the number of individual that have a sequence at the specified position.
const Sequence & getIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition) const
Get a sequence of an Individual.
void deleteIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition)
Delete a sequence of an Individual.
void deleteIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name)
Delete a sequence of an Individual.
void setIndividualSexAtPosition(size_t individualPosition, const unsigned short sex)
Set the sex of an Individual.
std::vector< std::string > getIndividualSequencesNames(size_t individualPosition) const
Get the sequences' names from an Individual.
void deleteIndividualGenotype(size_t individualPosition)
Delete the genotype of an Individual.
size_t getGroupSizeForLocus(size_t locusPosition) const
Get the number of individual that have a data at the specified locus.
const Date & getIndividualDateAtPosition(size_t individualPosition) const
Get the date of an Individual.
void addIndividual(const Individual &ind)
Add an Individual.
const Individual & getIndividualById(const std::string &individualId) const
Get a reference to an Individual.
const Point2D< double > & getIndividualCoordAtPosition(size_t individualPosition) const
Get the coordinates of an Individual.
size_t getIndividualSequencePosition(size_t individualPosition, const std::string &sequence_name) const
Get the position of a sequence in an Individual.
void setIndividualDateAtPosition(size_t individualPosition, const Date &date)
Set the date of an Individual.
bool hasIndividualSequences(size_t individualPosition) const
Tell if the Individual has some sequences.
std::unique_ptr< Individual > removeIndividualById(const std::string &individualId)
Remove an Individual from the Group.
void setIndividualMonolocusGenotypeByAlleleId(size_t individualPosition, size_t locusPosition, const std::vector< std::string > &alleleId, const LocusInfo &locusInfo)
Set a MonolocusGenotype of an Individual.
bool hasSequenceData() const
Tell if at least one individual has at least one sequence.
size_t getIndividualNumberOfSequences(size_t individualPosition) const
Get the number of sequences in an Individual.
std::shared_ptr< const Alphabet > getAlphabet() const
Get the alphabet used for the sequences.
void setIndividualSequences(size_t individualPosition, const SequenceContainerInterface &sc)
Set all the sequences by copying an OrderedSequenceContainer.
void addIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition, std::unique_ptr< Sequence > &sequence)
Add a sequence to an Individual.
void setIndividualCoordAtPosition(size_t individualPosition, const Point2D< double > &coord)
Set the coordinates of an Individual.
size_t getMaxNumberOfSequences() const
Get the maximum number of sequence.
void initIndividualGenotype(size_t individualPosition, size_t loci_number)
Initialize the genotype of an Individual.
unsigned short getIndividualSexAtPosition(size_t individualPosition) const
Get the sex of an Individual.
bool hasIndividualGenotype(size_t individualPosition) const
Tell if an Individual has a genotype.
void setIndividualMonolocusGenotypeByAlleleKey(size_t individualPosition, size_t locusPosition, const std::vector< size_t > &alleleKeys)
Set a MonolocusGenotype of an Individual.
size_t getIndividualPosition(const std::string &individualId) const
Get the position of an Individual.
std::unique_ptr< Individual > removeIndividualAtPosition(size_t individualPosition)
Remove an Individual from the Group.
void deleteIndividualById(const std::string &individualId)
Delete an Individual from the Group.
std::shared_ptr< const Locality< double > > getIndividualLocalityAtPosition(size_t individualPosition) const
Get the locality of an Individual.
const Individual & getIndividualAtPosition(size_t individualPosition) const
Get a reference to an Individual by its position.
void setIndividualLocalityAtPosition(size_t individualPosition, std::shared_ptr< const Locality< double >> locality)
Set the locality of an Individual.
const MonolocusGenotypeInterface & getIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition) const
Get a MonolocusGenotype of an Individual.
void addEmptyIndividual(const std::string &individualId)
Add an empty Individual to the Group.
void setIndividualGenotype(size_t individualPosition, const MultilocusGenotype &genotype)
Set the genotype of an Individual.
const Sequence & getIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name) const
Get a sequence of an Individual.
void setIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype of an Individual.
void deleteIndividualAtPosition(size_t individualPosition)
Delete an Individual from the Group.
std::size_t getBadIndex() const
const std::array< std::size_t, 2 > & getBounds() const
The IndividualNotFoundException class.
const std::string & getId() const
Get the id of the Individual.
The MonolocusGenotype virtual class.
The MultilocusGenotype class.
virtual const std::string getSequenceId() const
std::size_t count(const std::string &s, const std::string &pattern)