bpp-popgen3  3.0.0
Group.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "Group.h"
6 
7 using namespace bpp;
8 using namespace std;
9 
10 // ** Other methods: **********************************************************/
11 
13 {
14  try
15  {
16  getIndividualPosition(ind.getId());
17  throw BadIdentifierException("Group::addIndividual: individual id already used.", ind.getId());
18  }
19  catch (BadIdentifierException& bie)
20  {}
21  individuals_.push_back(make_unique<Individual>(ind));
22 }
23 
24 void Group::addEmptyIndividual(const std::string& individualId)
25 {
26  for (size_t i = 0; i < getNumberOfIndividuals(); ++i)
27  {
28  if (individuals_[i]->getId() == individualId)
29  throw BadIdentifierException("Group::addEmptyIndividual: individualId already in use.", individualId);
30  }
31  individuals_.push_back(make_unique<Individual>(individualId));
32 }
33 
34 size_t Group::getIndividualPosition(const std::string& individualId) const
35 {
36  for (size_t i = 0; i < getNumberOfIndividuals(); ++i)
37  {
38  if (individuals_[i]->getId() == individualId)
39  return i;
40  }
41  throw IndividualNotFoundException("Group::getIndividualPosition: individualId not found.", individualId);
42 }
43 
44 unique_ptr<Individual> Group::removeIndividualById(const std::string& individualId)
45 {
46  try
47  {
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));
51  return ind;
52  }
53  catch (IndividualNotFoundException& infe)
54  {
55  throw IndividualNotFoundException("Group::removeIndividualById: individualId not found.", individualId);
56  }
57 }
58 
59 std::unique_ptr<Individual> Group::removeIndividualAtPosition(size_t individualPosition)
60 {
61  if (individualPosition >= individuals_.size())
62  throw IndexOutOfBoundsException("Group::removeIndividualAtPosition.", individualPosition, 0, individuals_.size());
63  unique_ptr<Individual> ind = std::move(individuals_[individualPosition]);
64  individuals_.erase(individuals_.begin() + static_cast<ptrdiff_t>(individualPosition));
65  return ind;
66 }
67 
68 void Group::deleteIndividualById(const std::string& individualId)
69 {
70  try
71  {
72  removeIndividualById(individualId);
73  }
74  catch (IndividualNotFoundException& infe)
75  {
76  throw IndividualNotFoundException("Group::deleteIndividualById: individualId not found.", individualId);
77  }
78 }
79 
80 void Group::deleteIndividualAtPosition(size_t individualPosition)
81 {
82  try
83  {
84  removeIndividualAtPosition(individualPosition);
85  }
86  catch (IndexOutOfBoundsException& ioobe)
87  {
88  throw IndexOutOfBoundsException("Group::deleteIndividualAtPosition.", individualPosition, 0, getNumberOfIndividuals());
89  }
90 }
91 
92 const Individual& Group::getIndividualById(const std::string& individualId) const
93 {
94  for (size_t i = 0; i < individuals_.size(); ++i)
95  {
96  if (individuals_[i]->getId() == individualId)
97  return getIndividualAtPosition(i);
98  }
99  throw IndividualNotFoundException("Group::getIndividualById: individualId not found.", individualId);
100 }
101 
102 const Individual& Group::getIndividualAtPosition(size_t individualPosition) const
103 {
104  if (individualPosition >= individuals_.size())
105  throw IndexOutOfBoundsException("Group::getIndividualAtPosition: individualPosition out of bounds.", individualPosition, 0, individuals_.size());
106  return *individuals_[individualPosition];
107 }
108 
110 {
111  size_t maxnum = 0;
112  for (size_t i = 0; i < getNumberOfIndividuals(); ++i)
113  {
114  vector<size_t> seqpos = individuals_[i]->getSequencePositions();
115  for (size_t j = 0; j < seqpos.size(); ++j)
116  {
117  if (maxnum < seqpos[j])
118  maxnum = seqpos[j];
119  }
120  }
121  return maxnum + 1;
122 }
123 
124 // -- Dealing with individual's properties -----------------
125 
126 void Group::setIndividualSexAtPosition(size_t individualPosition, const unsigned short sex)
127 {
128  if (individualPosition >= getNumberOfIndividuals())
129  throw IndexOutOfBoundsException("Group::setIndividualSexAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
130  individuals_[individualPosition]->setSex(sex);
131 }
132 
133 unsigned short Group::getIndividualSexAtPosition(size_t individualPosition) const
134 {
135  if (individualPosition >= getNumberOfIndividuals())
136  throw IndexOutOfBoundsException("Group::getIndividualSexAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
137  return individuals_[individualPosition]->getSex();
138 }
139 
140 void Group::setIndividualDateAtPosition(size_t individualPosition, const Date& date)
141 {
142  if (individualPosition >= getNumberOfIndividuals())
143  throw IndexOutOfBoundsException("Group::setIndividualDateAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
144  individuals_[individualPosition]->setDate(date);
145 }
146 
147 const Date& Group::getIndividualDateAtPosition(size_t individualPosition) const
148 {
149  if (individualPosition >= getNumberOfIndividuals())
150  throw IndexOutOfBoundsException("Group::getIndividualDateAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
151  try
152  {
153  return individuals_[individualPosition]->date();
154  }
155  catch (NullPointerException& npe)
156  {
157  throw NullPointerException("Group::getIndividualDateAtPosition: individual has no date.");
158  }
159 }
160 
161 void Group::setIndividualCoordAtPosition(size_t individualPosition, const Point2D<double>& coord)
162 {
163  if (individualPosition >= getNumberOfIndividuals())
164  throw IndexOutOfBoundsException("Group::setIndividualCoordAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
165  individuals_[individualPosition]->setCoord(coord);
166 }
167 
168 const Point2D<double>& Group::getIndividualCoordAtPosition(size_t individualPosition) const
169 {
170  if (individualPosition >= getNumberOfIndividuals())
171  throw IndexOutOfBoundsException("Group::getIndividualCoordAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
172  try
173  {
174  return individuals_[individualPosition]->coord();
175  }
176  catch (NullPointerException& npe)
177  {
178  throw NullPointerException("Group::getIndividualCoordAtPosition: individual has no coordinates.");
179  }
180 }
181 
182 void Group::setIndividualLocalityAtPosition(size_t individualPosition, shared_ptr<const Locality<double>> locality)
183 {
184  if (individualPosition >= getNumberOfIndividuals())
185  throw IndexOutOfBoundsException("Group::setIndividualLocalityAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
186  individuals_[individualPosition]->setLocality(locality);
187 }
188 
189 std::shared_ptr<const Locality<double>> Group::getIndividualLocalityAtPosition(size_t individualPosition) const
190 {
191  if (individualPosition >= getNumberOfIndividuals())
192  throw IndexOutOfBoundsException("Group::getIndividualLocalityAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
193  try
194  {
195  return individuals_[individualPosition]->getLocality();
196  }
197  catch (NullPointerException& npe)
198  {
199  throw NullPointerException("Group::getIndividualLocalityAtPosition: individuals has no locality.");
200  }
201 }
202 
203 void Group::addIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition, unique_ptr<Sequence>& sequence)
204 {
205  if (individualPosition >= getNumberOfIndividuals())
206  throw IndexOutOfBoundsException("Group::addIndividualSequenceAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
207  try
208  {
209  individuals_[individualPosition]->addSequence(sequencePosition, sequence);
210  }
211  catch (AlphabetMismatchException& ame)
212  {
213  throw AlphabetMismatchException("Group::addIndividualSequenceAtPosition: sequence's alphabet doesn't match.", ame.getFirstAlphabet(), ame.getSecondAlphabet());
214  }
215  catch (BadIdentifierException& bie)
216  {
217  throw BadIdentifierException("Group::addIndividualSequenceAtPosition: sequence's name already in use.", bie.getIdentifier());
218  }
219  catch (BadIntegerException& bie)
220  {
221  throw BadIntegerException("Group::addIndividualSequenceAtPosition: sequencePosition already in use.", bie.getBadInteger());
222  }
223 }
224 
225 const Sequence& Group::getIndividualSequenceByName(size_t individualPosition, const string& sequenceName) const
226 {
227  if (individualPosition >= getNumberOfIndividuals())
228  throw IndexOutOfBoundsException("Group::getIndividualSequenceByName: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
229  try
230  {
231  return individuals_[individualPosition]->sequenceByName(sequenceName);
232  }
233  catch (NullPointerException& npe)
234  {
235  throw NullPointerException("Group::getIndividualSequenceByName: no sequence data in individual.");
236  }
237  catch (SequenceNotFoundException& snfe)
238  {
239  throw SequenceNotFoundException("Group::getIndividualSequenceByName: sequence_name not found.", snfe.getSequenceId());
240  }
241 }
242 
243 const Sequence& Group::getIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition) const
244 {
245  if (individualPosition >= getNumberOfIndividuals())
246  throw IndexOutOfBoundsException("Group::getIndividualAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
247  try
248  {
249  return individuals_[individualPosition]->sequenceAtPosition(sequencePosition);
250  }
251  catch (NullPointerException& npe)
252  {
253  throw NullPointerException("Group::getIndividualSequenceAtPosition: no sequence data in individual.");
254  }
255  catch (SequenceNotFoundException& snfe)
256  {
257  throw SequenceNotFoundException("Group::getIndividualSequenceAtPosition: sequencePosition not found.", snfe.getSequenceId());
258  }
259 }
260 
261 void Group::deleteIndividualSequenceByName(size_t individualPosition, const string& sequence_name)
262 {
263  if (individualPosition >= getNumberOfIndividuals())
264  throw IndexOutOfBoundsException("Group::deleteIndividualSequenceByName: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
265  try
266  {
267  individuals_[individualPosition]->deleteSequenceByName(sequence_name);
268  }
269  catch (NullPointerException& npe)
270  {
271  throw NullPointerException("Group::deleteSequenceByName: no sequence data in individual.");
272  }
273  catch (SequenceNotFoundException& snfe)
274  {
275  throw SequenceNotFoundException("Group::deleteSequenceByName: sequence_name not found.", snfe.getSequenceId());
276  }
277 }
278 
279 void Group::deleteIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition)
280 {
281  if (individualPosition >= getNumberOfIndividuals())
282  throw IndexOutOfBoundsException("Group::deleteIndividualSequenceAtPosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
283  try
284  {
285  individuals_[individualPosition]->deleteSequenceAtPosition(sequencePosition);
286  }
287  catch (NullPointerException& npe)
288  {
289  throw NullPointerException("Group::deleteSequenceAtPosition: no sequence data in individual.");
290  }
291  catch (SequenceNotFoundException& snfe)
292  {
293  throw SequenceNotFoundException("Group::deleteSequenceAtPosition: sequencePosition not found.", snfe.getSequenceId());
294  }
295 }
296 
297 bool Group::hasIndividualSequences(size_t individualPosition) const
298 {
299  if (individualPosition >= getNumberOfIndividuals())
300  throw IndexOutOfBoundsException("Group::hasIndividualSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
301  return individuals_[individualPosition]->hasSequences();
302 }
303 
304 vector<string> Group::getIndividualSequencesNames(size_t individualPosition) const
305 {
306  if (individualPosition >= getNumberOfIndividuals())
307  throw IndexOutOfBoundsException("Group::getIndividualSequencesNames: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
308  try
309  {
310  return individuals_[individualPosition]->getSequenceNames();
311  }
312  catch (NullPointerException& npe)
313  {
314  throw NullPointerException("Group::getSequencesNames: no sequence data in individual.");
315  }
316 }
317 
318 size_t Group::getIndividualSequencePosition(size_t individualPosition, const string& sequence_name) const
319 {
320  if (individualPosition >= getNumberOfIndividuals())
321  throw IndexOutOfBoundsException("Group::getIndividualSequencePosition: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
322  try
323  {
324  return individuals_[individualPosition]->getSequencePosition(sequence_name);
325  }
326  catch (NullPointerException& npe)
327  {
328  throw NullPointerException("Group::getSequencePosition: no sequence data in individual.");
329  }
330  catch (SequenceNotFoundException& snfe)
331  {
332  throw SequenceNotFoundException("Group::getSequencePosition: sequence_name not found.", snfe.getSequenceId());
333  }
334 }
335 
336 size_t Group::getIndividualNumberOfSequences(size_t individualPosition) const
337 {
338  if (individualPosition >= getNumberOfIndividuals())
339  throw IndexOutOfBoundsException("Group::getIndividualNumberOfSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
340  try
341  {
342  return individuals_[individualPosition]->getNumberOfSequences();
343  }
344  catch (NullPointerException& npe)
345  {
346  throw NullPointerException("Group::getIndividualNumberOfSequences: no sequence data in individual.");
347  }
348 }
349 
350 void Group::setIndividualSequences(size_t individualPosition, const SequenceContainerInterface& sc)
351 {
352  if (individualPosition >= getNumberOfIndividuals())
353  throw IndexOutOfBoundsException("Group::setIndividualSequences: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
354  individuals_[individualPosition]->setSequences(sc);
355 }
356 
357 void Group::setIndividualGenotype(size_t individualPosition, const MultilocusGenotype& genotype)
358 {
359  if (individualPosition >= getNumberOfIndividuals())
360  throw IndexOutOfBoundsException("Group::setIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
361  individuals_[individualPosition]->setGenotype(genotype);
362 }
363 
364 void Group::initIndividualGenotype(size_t individualPosition, size_t lociNumber)
365 {
366  if (individualPosition >= getNumberOfIndividuals())
367  throw IndexOutOfBoundsException("Group::initIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
368  try
369  {
370  individuals_[individualPosition]->initGenotype(lociNumber);
371  }
372  catch (BadIntegerException& bie)
373  {
374  throw BadIntegerException("Group::initIndividualGenotype: lociNumber must be > 0.", bie.getBadInteger());
375  }
376  catch (Exception&)
377  {
378  throw Exception("Group::initIndividualGenotype: individual already has a genotype.");
379  }
380 }
381 
382 void Group::deleteIndividualGenotype(size_t individualPosition)
383 {
384  if (individualPosition >= getNumberOfIndividuals())
385  throw IndexOutOfBoundsException("Group::deleteIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
386  individuals_[individualPosition]->deleteGenotype();
387 }
388 
389 bool Group::hasIndividualGenotype(size_t individualPosition) const
390 {
391  if (individualPosition >= getNumberOfIndividuals())
392  throw IndexOutOfBoundsException("Group::hasIndividualGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
393  return individuals_[individualPosition]->hasGenotype();
394 }
395 
397  size_t individualPosition,
398  size_t locusPosition,
399  const MonolocusGenotypeInterface& monogen)
400 {
401  if (individualPosition >= getNumberOfIndividuals())
402  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
403  try
404  {
405  individuals_[individualPosition]->setMonolocusGenotype(locusPosition, monogen);
406  }
407  catch (NullPointerException& npe)
408  {
409  throw NullPointerException("Group::setIndividualMonolocusGenotype: individual has no genotype.");
410  }
411  catch (IndexOutOfBoundsException& ioobe)
412  {
413  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotype: locusPosition exceeds the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
414  }
415 }
416 
418  size_t individualPosition,
419  size_t locusPosition,
420  const vector<size_t>& alleleKeys)
421 {
422  if (individualPosition >= getNumberOfIndividuals())
423  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleKey: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
424  try
425  {
426  individuals_[individualPosition]->setMonolocusGenotypeByAlleleKey(locusPosition, alleleKeys);
427  }
428  catch (NullPointerException& npe)
429  {
430  throw NullPointerException("Group::setIndividualMonolocusGenotypeByAlleleKey: individual has no genotype.");
431  }
432  catch (IndexOutOfBoundsException& ioobe)
433  {
434  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleKey: locusPosition exceeds the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
435  }
436  catch (Exception&)
437  {
438  throw Exception("Group::setIndividualMonolocusGenotypeByAlleleKey: no key in allele_keys.");
439  }
440 }
441 
442 void Group::setIndividualMonolocusGenotypeByAlleleId(size_t individualPosition, size_t locusPosition, const std::vector<std::string>& allele_id, const LocusInfo& locus_info)
443 {
444  if (individualPosition >= getNumberOfIndividuals())
445  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleId: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
446  try
447  {
448  individuals_[individualPosition]->setMonolocusGenotypeByAlleleId(locusPosition, allele_id, locus_info);
449  }
450  catch (NullPointerException& npe)
451  {
452  throw NullPointerException("Group::setIndividualMonolocusGenotypeByAlleleId: individual has no genotype.");
453  }
454  catch (IndexOutOfBoundsException& ioobe)
455  {
456  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleId: locusPosition exceeds the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
457  }
458  catch (AlleleNotFoundException& anfe)
459  {
460  throw AlleleNotFoundException("Group::setIndividualMonolocusGenotypeByAlleleId: id not found.", anfe.getIdentifier());
461  }
462 }
463 
465  size_t individualPosition,
466  size_t locusPosition) const
467 {
468  if (individualPosition >= getNumberOfIndividuals())
469  throw IndexOutOfBoundsException("Group::getIndividualMonolocusGenotype: individualPosition out of bounds.", individualPosition, 0, getNumberOfIndividuals());
470  try
471  {
472  return individuals_[individualPosition]->getMonolocusGenotype(locusPosition);
473  }
474  catch (NullPointerException& npe)
475  {
476  throw NullPointerException("Group::getIndividualMonolocusGenotype: individual has no genotype.");
477  }
478  catch (IndexOutOfBoundsException& ioobe)
479  {
480  throw IndexOutOfBoundsException("Group::getIndividualMonolocusGenotype: locusPosition exceeds the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
481  }
482 }
483 
485 {
486  for (size_t i = 0; i < getNumberOfIndividuals(); ++i)
487  {
488  if (hasIndividualSequences(i))
489  return true;
490  }
491  return false;
492 }
493 
494 shared_ptr<const Alphabet> Group::getAlphabet() const
495 {
496  for (size_t i = 0; i < getNumberOfIndividuals(); ++i)
497  {
498  if (hasIndividualSequences(i))
499  return individuals_[i]->getSequenceAlphabet();
500  }
501  throw NullPointerException("Group::getAlphabet: individual has no sequence data.");
502 }
503 
504 size_t Group::getGroupSizeForLocus(size_t locusPosition) const
505 {
506  size_t count = 0;
507  for (size_t i = 0; i < individuals_.size(); ++i)
508  {
509  if (individuals_[i]->hasGenotype() && !individuals_[i]->getGenotype().isMonolocusGenotypeMissing(locusPosition))
510  count++;
511  }
512  return count;
513 }
514 
515 size_t Group::getGroupSizeForSequence(size_t sequencePosition) const
516 {
517  size_t count = 0;
518  for (size_t i = 0; i < individuals_.size(); ++i)
519  {
520  if (individuals_[i]->hasSequences())
521  {
522  try
523  {
524  individuals_[i]->sequenceAtPosition(sequencePosition);
525  count++;
526  }
527  catch (...)
528  {}
529  }
530  }
531  return count;
532 }
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.
The Date class.
Definition: Date.h:21
size_t getGroupSizeForSequence(size_t sequencePosition) const
Get the number of individual that have a sequence at the specified position.
Definition: Group.cpp:515
const Sequence & getIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition) const
Get a sequence of an Individual.
Definition: Group.cpp:243
void deleteIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition)
Delete a sequence of an Individual.
Definition: Group.cpp:279
void deleteIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name)
Delete a sequence of an Individual.
Definition: Group.cpp:261
void setIndividualSexAtPosition(size_t individualPosition, const unsigned short sex)
Set the sex of an Individual.
Definition: Group.cpp:126
std::vector< std::string > getIndividualSequencesNames(size_t individualPosition) const
Get the sequences' names from an Individual.
Definition: Group.cpp:304
void deleteIndividualGenotype(size_t individualPosition)
Delete the genotype of an Individual.
Definition: Group.cpp:382
size_t getGroupSizeForLocus(size_t locusPosition) const
Get the number of individual that have a data at the specified locus.
Definition: Group.cpp:504
const Date & getIndividualDateAtPosition(size_t individualPosition) const
Get the date of an Individual.
Definition: Group.cpp:147
void addIndividual(const Individual &ind)
Add an Individual.
Definition: Group.cpp:12
const Individual & getIndividualById(const std::string &individualId) const
Get a reference to an Individual.
Definition: Group.cpp:92
const Point2D< double > & getIndividualCoordAtPosition(size_t individualPosition) const
Get the coordinates of an Individual.
Definition: Group.cpp:168
size_t getIndividualSequencePosition(size_t individualPosition, const std::string &sequence_name) const
Get the position of a sequence in an Individual.
Definition: Group.cpp:318
void setIndividualDateAtPosition(size_t individualPosition, const Date &date)
Set the date of an Individual.
Definition: Group.cpp:140
bool hasIndividualSequences(size_t individualPosition) const
Tell if the Individual has some sequences.
Definition: Group.cpp:297
std::unique_ptr< Individual > removeIndividualById(const std::string &individualId)
Remove an Individual from the Group.
Definition: Group.cpp:44
void setIndividualMonolocusGenotypeByAlleleId(size_t individualPosition, size_t locusPosition, const std::vector< std::string > &alleleId, const LocusInfo &locusInfo)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:442
bool hasSequenceData() const
Tell if at least one individual has at least one sequence.
Definition: Group.cpp:484
size_t getIndividualNumberOfSequences(size_t individualPosition) const
Get the number of sequences in an Individual.
Definition: Group.cpp:336
std::shared_ptr< const Alphabet > getAlphabet() const
Get the alphabet used for the sequences.
Definition: Group.cpp:494
void setIndividualSequences(size_t individualPosition, const SequenceContainerInterface &sc)
Set all the sequences by copying an OrderedSequenceContainer.
Definition: Group.cpp:350
void addIndividualSequenceAtPosition(size_t individualPosition, size_t sequencePosition, std::unique_ptr< Sequence > &sequence)
Add a sequence to an Individual.
Definition: Group.cpp:203
void setIndividualCoordAtPosition(size_t individualPosition, const Point2D< double > &coord)
Set the coordinates of an Individual.
Definition: Group.cpp:161
size_t getMaxNumberOfSequences() const
Get the maximum number of sequence.
Definition: Group.cpp:109
void initIndividualGenotype(size_t individualPosition, size_t loci_number)
Initialize the genotype of an Individual.
Definition: Group.cpp:364
unsigned short getIndividualSexAtPosition(size_t individualPosition) const
Get the sex of an Individual.
Definition: Group.cpp:133
bool hasIndividualGenotype(size_t individualPosition) const
Tell if an Individual has a genotype.
Definition: Group.cpp:389
void setIndividualMonolocusGenotypeByAlleleKey(size_t individualPosition, size_t locusPosition, const std::vector< size_t > &alleleKeys)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:417
size_t getIndividualPosition(const std::string &individualId) const
Get the position of an Individual.
Definition: Group.cpp:34
std::unique_ptr< Individual > removeIndividualAtPosition(size_t individualPosition)
Remove an Individual from the Group.
Definition: Group.cpp:59
void deleteIndividualById(const std::string &individualId)
Delete an Individual from the Group.
Definition: Group.cpp:68
std::shared_ptr< const Locality< double > > getIndividualLocalityAtPosition(size_t individualPosition) const
Get the locality of an Individual.
Definition: Group.cpp:189
const Individual & getIndividualAtPosition(size_t individualPosition) const
Get a reference to an Individual by its position.
Definition: Group.cpp:102
void setIndividualLocalityAtPosition(size_t individualPosition, std::shared_ptr< const Locality< double >> locality)
Set the locality of an Individual.
Definition: Group.cpp:182
const MonolocusGenotypeInterface & getIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition) const
Get a MonolocusGenotype of an Individual.
Definition: Group.cpp:464
void addEmptyIndividual(const std::string &individualId)
Add an empty Individual to the Group.
Definition: Group.cpp:24
void setIndividualGenotype(size_t individualPosition, const MultilocusGenotype &genotype)
Set the genotype of an Individual.
Definition: Group.cpp:357
const Sequence & getIndividualSequenceByName(size_t individualPosition, const std::string &sequence_name) const
Get a sequence of an Individual.
Definition: Group.cpp:225
void setIndividualMonolocusGenotype(size_t individualPosition, size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:396
void deleteIndividualAtPosition(size_t individualPosition)
Delete an Individual from the Group.
Definition: Group.cpp:80
std::size_t getBadIndex() const
const std::array< std::size_t, 2 > & getBounds() const
The IndividualNotFoundException class.
The Individual class.
Definition: Individual.h:40
const std::string & getId() const
Get the id of the Individual.
Definition: Individual.h:110
The Locality class.
Definition: Locality.h:25
The LocusInfo class.
Definition: LocusInfo.h:31
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)