52 name_(group.getGroupName()),
63 name_(group.getGroupName()),
102 getIndividualPosition(ind.getId());
112 for (
size_t i = 0; i < getNumberOfIndividuals(); i++)
114 if (individuals_[i]->getId() == individual_id)
117 individuals_.push_back(
new Individual(individual_id));
122 for (
size_t i = 0; i < getNumberOfIndividuals(); i++)
124 if (individuals_[i]->getId() == individual_id)
134 size_t indPos = getIndividualPosition(individual_id);
135 auto_ptr<Individual> ind(individuals_[indPos]);
136 individuals_.erase(individuals_.begin() +
static_cast<ptrdiff_t
>(indPos));
147 if (individual_position >= individuals_.size())
148 throw IndexOutOfBoundsException(
"Group::removeIndividualAtPosition.", individual_position, 0, individuals_.size());
149 auto_ptr<Individual> ind(individuals_[individual_position]);
150 individuals_.erase(individuals_.begin() +
static_cast<ptrdiff_t
>(individual_position));
158 removeIndividualById(individual_id);
170 removeIndividualAtPosition(individual_position);
172 catch (IndexOutOfBoundsException& ioobe)
174 throw IndexOutOfBoundsException(
"Group::deleteIndividualAtPosition.", individual_position, 0, getNumberOfIndividuals());
189 for (
size_t i = 0; i < individuals_.size(); i++)
191 if (individuals_[i]->getId() == individual_id)
192 return getIndividualAtPosition(i);
198 throw (IndexOutOfBoundsException)
200 if (individual_position >= individuals_.size())
201 throw IndexOutOfBoundsException(
"Group::getIndividualAtPosition: individual_position out of bounds.", individual_position, 0, individuals_.size());
202 return *individuals_[individual_position];
215 vector<size_t> seqpos =
individuals_[i]->getSequencesPositions();
216 for (
size_t j = 0; j < seqpos.size(); j++)
218 if (maxnum < seqpos[j])
229 if (individual_position >= getNumberOfIndividuals())
230 throw IndexOutOfBoundsException(
"Group::setIndividualSexAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
231 individuals_[individual_position]->setSex(sex);
236 if (individual_position >= getNumberOfIndividuals())
237 throw IndexOutOfBoundsException(
"Group::getIndividualSexAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
238 return individuals_[individual_position]->getSex();
243 if (individual_position >= getNumberOfIndividuals())
244 throw IndexOutOfBoundsException(
"Group::setIndividualDateAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
245 individuals_[individual_position]->setDate(date);
250 if (individual_position >= getNumberOfIndividuals())
251 throw IndexOutOfBoundsException(
"Group::getIndividualDateAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
254 return individuals_[individual_position]->getDate();
256 catch (NullPointerException& npe)
258 throw NullPointerException(
"Group::getIndividualDateAtPosition: individual has no date.");
264 if (individual_position >= getNumberOfIndividuals())
265 throw IndexOutOfBoundsException(
"Group::setIndividualCoordAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
266 individuals_[individual_position]->setCoord(coord);
271 if (individual_position >= getNumberOfIndividuals())
272 throw IndexOutOfBoundsException(
"Group::getIndividualCoordAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
275 return individuals_[individual_position]->getCoord();
277 catch (NullPointerException& npe)
279 throw NullPointerException(
"Group::getIndividualCoordAtPosition: individual has no coordinates.");
285 if (individual_position >= getNumberOfIndividuals())
286 throw IndexOutOfBoundsException(
"Group::setIndividualLocalityAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
287 individuals_[individual_position]->setLocality(locality);
292 if (individual_position >= getNumberOfIndividuals())
293 throw IndexOutOfBoundsException(
"Group::getIndividualLocalityAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
296 return *individuals_[individual_position]->getLocality();
298 catch (NullPointerException& npe)
300 throw NullPointerException(
"Group::getIndividualLocalityAtPosition: individuals has no locality.");
306 if (individual_position >= getNumberOfIndividuals())
307 throw IndexOutOfBoundsException(
"Group::addIndividualSequenceAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
310 individuals_[individual_position]->addSequence(sequence_position, sequence);
312 catch (AlphabetMismatchException& ame)
314 throw AlphabetMismatchException(
"Group::addIndividualSequenceAtPosition: sequence's alphabet doesn't match.", ame.getAlphabets()[0], ame.getAlphabets()[1]);
320 catch (BadIntegerException& bie)
322 throw BadIntegerException(
"Group::addIndividualSequenceAtPosition: sequence_position already in use.", bie.getBadInteger());
328 if (individual_position >= getNumberOfIndividuals())
329 throw IndexOutOfBoundsException(
"Group::getIndividualSequenceByName: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
332 return individuals_[individual_position]->getSequenceByName(sequence_name);
334 catch (NullPointerException& npe)
336 throw NullPointerException(
"Group::getIndividualSequenceByName: no sequence data in individual.");
338 catch (SequenceNotFoundException& snfe)
340 throw SequenceNotFoundException(
"Group::getIndividualSequenceByName: sequence_name not found.", snfe.getSequenceId());
346 if (individual_position >= getNumberOfIndividuals())
347 throw IndexOutOfBoundsException(
"Group::getIndividualAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
350 return individuals_[individual_position]->getSequenceAtPosition(sequence_position);
352 catch (NullPointerException& npe)
354 throw NullPointerException(
"Group::getIndividualSequenceAtPosition: no sequence data in individual.");
356 catch (SequenceNotFoundException& snfe)
358 throw SequenceNotFoundException(
"Group::getIndividualSequenceAtPosition: sequence_position not found.", snfe.getSequenceId());
364 if (individual_position >= getNumberOfIndividuals())
365 throw IndexOutOfBoundsException(
"Group::deleteIndividualSequenceByName: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
368 individuals_[individual_position]->deleteSequenceByName(sequence_name);
370 catch (NullPointerException& npe)
372 throw NullPointerException(
"Group::deleteSequenceByName: no sequence data in individual.");
374 catch (SequenceNotFoundException& snfe)
376 throw SequenceNotFoundException(
"Group::deleteSequenceByName: sequence_name not found.", snfe.getSequenceId());
382 if (individual_position >= getNumberOfIndividuals())
383 throw IndexOutOfBoundsException(
"Group::deleteIndividualSequenceAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
386 individuals_[individual_position]->deleteSequenceAtPosition(sequence_position);
388 catch (NullPointerException& npe)
390 throw NullPointerException(
"Group::deleteSequenceAtPosition: no sequence data in individual.");
392 catch (SequenceNotFoundException& snfe)
394 throw SequenceNotFoundException(
"Group::deleteSequenceAtPosition: sequence_position not found.", snfe.getSequenceId());
400 if (individual_position >= getNumberOfIndividuals())
401 throw IndexOutOfBoundsException(
"Group::hasIndividualSequences: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
402 return individuals_[individual_position]->hasSequences();
407 if (individual_position >= getNumberOfIndividuals())
408 throw IndexOutOfBoundsException(
"Group::getIndividualSequencesNames: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
411 return individuals_[individual_position]->getSequencesNames();
413 catch (NullPointerException& npe)
415 throw NullPointerException(
"Group::getSequencesNames: no sequence data in individual.");
421 if (individual_position >= getNumberOfIndividuals())
422 throw IndexOutOfBoundsException(
"Group::getIndividualSequencePosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
425 return individuals_[individual_position]->getSequencePosition(sequence_name);
427 catch (NullPointerException& npe)
429 throw NullPointerException(
"Group::getSequencePosition: no sequence data in individual.");
431 catch (SequenceNotFoundException& snfe)
433 throw SequenceNotFoundException(
"Group::getSequencePosition: sequence_name not found.", snfe.getSequenceId());
439 if (individual_position >= getNumberOfIndividuals())
440 throw IndexOutOfBoundsException(
"Group::getIndividualNumberOfSequences: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
443 return individuals_[individual_position]->getNumberOfSequences();
445 catch (NullPointerException& npe)
447 throw NullPointerException(
"Group::getIndividualNumberOfSequences: no sequence data in individual.");
453 if (individual_position >= getNumberOfIndividuals())
454 throw IndexOutOfBoundsException(
"Group::setIndividualSequences: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
455 individuals_[individual_position]->setSequences(msc);
460 if (individual_position >= getNumberOfIndividuals())
461 throw IndexOutOfBoundsException(
"Group::setIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
462 individuals_[individual_position]->setGenotype(genotype);
467 if (individual_position >= getNumberOfIndividuals())
468 throw IndexOutOfBoundsException(
"Group::initIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
471 individuals_[individual_position]->initGenotype(loci_number);
473 catch (BadIntegerException& bie)
475 throw BadIntegerException(
"Group::initIndividualGenotype: loci_number must be > 0.", bie.getBadInteger());
479 throw Exception(
"Group::initIndividualGenotype: individual already has a genotype.");
485 if (individual_position >= getNumberOfIndividuals())
486 throw IndexOutOfBoundsException(
"Group::deleteIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
487 individuals_[individual_position]->deleteGenotype();
492 if (individual_position >= getNumberOfIndividuals())
493 throw IndexOutOfBoundsException(
"Group::hasIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
494 return individuals_[individual_position]->hasGenotype();
499 if (individual_position >= getNumberOfIndividuals())
500 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
503 individuals_[individual_position]->setMonolocusGenotype(locus_position, monogen);
505 catch (NullPointerException& npe)
507 throw NullPointerException(
"Group::setIndividualMonolocusGenotype: individual has no genotype.");
509 catch (IndexOutOfBoundsException& ioobe)
511 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotype: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
517 if (individual_position >= getNumberOfIndividuals())
518 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleKey: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
521 individuals_[individual_position]->setMonolocusGenotypeByAlleleKey(locus_position, allele_keys);
523 catch (NullPointerException& npe)
525 throw NullPointerException(
"Group::setIndividualMonolocusGenotypeByAlleleKey: individual has no genotype.");
527 catch (IndexOutOfBoundsException& ioobe)
529 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleKey: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
533 throw Exception(
"Group::setIndividualMonolocusGenotypeByAlleleKey: no key in allele_keys.");
539 if (individual_position >= getNumberOfIndividuals())
540 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleId: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
543 individuals_[individual_position]->setMonolocusGenotypeByAlleleId(locus_position, allele_id, locus_info);
545 catch (NullPointerException& npe)
547 throw NullPointerException(
"Group::setIndividualMonolocusGenotypeByAlleleId: individual has no genotype.");
549 catch (IndexOutOfBoundsException& ioobe)
551 throw IndexOutOfBoundsException(
"Group::setIndividualMonolocusGenotypeByAlleleId: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
561 if (individual_position >= getNumberOfIndividuals())
562 throw IndexOutOfBoundsException(
"Group::getIndividualMonolocusGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
565 return individuals_[individual_position]->getMonolocusGenotype(locus_position);
567 catch (NullPointerException& npe)
569 throw NullPointerException(
"Group::getIndividualMonolocusGenotype: individual has no genotype.");
571 catch (IndexOutOfBoundsException& ioobe)
573 throw IndexOutOfBoundsException(
"Group::getIndividualMonolocusGenotype: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
594 throw NullPointerException(
"Group::getAlphabet: individual has no sequence data.");
617 individuals_[i]->getSequenceAtPosition(sequence_position);
const MonolocusGenotype & getIndividualMonolocusGenotype(size_t individual_position, size_t locus_position) const
Get a MonolocusGenotype of an Individual.
const Date & getIndividualDateAtPosition(size_t individual_position) const
Get the date of an Individual.
size_t getGroupId() const
Get the id of the Group.
void addIndividual(const Individual &ind)
Add an Individual.
void setIndividualMonolocusGenotype(size_t individual_position, size_t locus_position, const MonolocusGenotype &monogen)
Set a MonolocusGenotype of an Individual.
void setIndividualLocalityAtPosition(size_t individual_position, const Locality< double > *locality)
Set the locality of an Individual.
Group & operator=(const Group &group)
The assignation operator =.
std::vector< std::string > getIndividualSequencesNames(size_t individual_position) const
Get the sequences' names from an Individual.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
size_t getNumberOfIndividuals() const
Get the number of Individual in the Group.
bool hasSequenceData() const
Tell if at least one individual has at least one sequence.
std::vector< Individual * > individuals_
const Individual & getIndividualAtPosition(size_t individual_position) const
Get a reference to an Individual by its position.
void setIndividualDateAtPosition(size_t individual_position, const Date &date)
Set the date of an Individual.
The BadIdentifierException class.
bool hasIndividualGenotype(size_t individual_position) const
Tell if an Individual has a genotype.
size_t getIndividualSequencePosition(size_t individual_position, const std::string &sequence_name) const
Get the position of a sequence in an Individual.
void deleteIndividualGenotype(size_t individual_position)
Delete the genotype of an Individual.
Group(size_t group_id)
Build a void new Group.
void setIndividualMonolocusGenotypeByAlleleKey(size_t individual_position, size_t locus_position, const std::vector< size_t > &allele_keys)
Set a MonolocusGenotype of an Individual.
void addEmptyIndividual(const std::string &individual_id)
Add an empty Individual to the Group.
void setGroupName(const std::string &group_name)
Set the name of the Group.
const Locality< double > & getIndividualLocalityAtPosition(size_t individual_position) const
Get the locality of an Individual.
The MultilocusGenotype class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
const Point2D< double > & getIndividualCoordAtPosition(size_t individual_position) const
Get the coordinates of an Individual.
void deleteIndividualAtPosition(size_t individual_position)
Delete an Individual from the Group.
std::auto_ptr< Individual > removeIndividualAtPosition(size_t individual_position)
Remove an Individual from the Group.
unsigned short getIndividualSexAtPosition(size_t individual_position) const
Get the sex of an Individual.
const Sequence & getIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position) const
Get a sequence of an Individual.
void setIndividualMonolocusGenotypeByAlleleId(size_t individual_position, size_t locus_position, const std::vector< std::string > &allele_id, const LocusInfo &locus_info)
Set a MonolocusGenotype of an Individual.
void setIndividualSequences(size_t individual_position, const MapSequenceContainer &msc)
Set all the sequences by copying an OrderedSequenceContainer.
void initIndividualGenotype(size_t individual_position, size_t loci_number)
Initialyze the genotype of an Individual.
The AlleleNotFoundException class.
void deleteIndividualSequenceByName(size_t individual_position, const std::string &sequence_name)
Delete a sequence of an Individual.
bool hasIndividualSequences(size_t individual_position) const
Tell if the Individual has some sequences.
size_t getIndividualNumberOfSequences(size_t individual_position) const
Get the number of sequences in an Individual.
const Individual & getIndividualById(const std::string &individual_id) const
Get a reference to an Individual.
The IndividualNotFoundException class.
std::auto_ptr< Individual > removeIndividualById(const std::string &individual_id)
Remove an Individual from the Group.
size_t getGroupSizeForSequence(size_t sequence_position) const
Get the number of individual that have a sequence at the specified position.
~Group()
Destroy an Group.
void setIndividualCoordAtPosition(size_t individual_position, const Point2D< double > &coord)
Set the coordinates of an Individual.
size_t getIndividualPosition(const std::string &individual_id) const
Get the position of an Individual.
size_t getMaxNumberOfSequences() const
Get the maximum number of sequence.
void deleteIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position)
Delete a sequence of an Individual.
void deleteIndividualById(const std::string &individual_id)
Delete an Individual from the Group.
The MonolocusGenotype virtual class.
void clear()
Clear the Group.
void setGroupId(size_t group_id)
Set the id of the Group.
size_t getGroupSizeForLocus(size_t locus_position) const
Get the number of individual that have a data at the specified locus.
void addIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position, const Sequence &sequence)
Add a sequence to an Individual.
void setIndividualGenotype(size_t individual_position, const MultilocusGenotype &genotype)
Set the genotype of an Individual.
void setIndividualSexAtPosition(size_t individual_position, const unsigned short sex)
Set the sex of an Individual.
const Alphabet * getAlphabet() const
Get the alphabet used for the sequences.
const Sequence & getIndividualSequenceByName(size_t individual_position, const std::string &sequence_name) const
Get a sequence of an Individual.