bpp-popgen  2.2.0
Group.cpp
Go to the documentation of this file.
1 //
2 // File Group.cpp
3 // Author : Sylvain Gaillard
4 // Last modification : Thursday July 29 2004
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10 
11  This software is a computer program whose purpose is to provide classes
12  for population genetics analysis.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39  */
40 
41 #include "Group.h"
42 
43 using namespace bpp;
44 using namespace std;
45 
46 // ** Class constructors: ******************************************************/
47 Group::Group(size_t group_id) : id_(group_id),
48  name_(""),
49  individuals_(vector<Individual*>()) {}
50 
51 Group::Group(const Group& group) : id_(group.getGroupId()),
52  name_(group.getGroupName()),
53  // individuals_(vector<Individuals*>(group.getNumberOfIndividuals()))
54  individuals_(vector<Individual*>())
55 {
56  for (size_t i = 0; i < group.getNumberOfIndividuals(); i++)
57  {
59  }
60 }
61 
62 Group::Group(const Group& group, size_t group_id) : id_(group_id),
63  name_(group.getGroupName()),
64  individuals_(vector<Individual*>())
65 {
66  for (size_t i = 0; i < group.getNumberOfIndividuals(); i++)
67  {
69  }
70 }
71 
72 // ** Class destructor: ********************************************************/
73 
75 
76 // ** Other methodes: **********************************************************/
77 
79 {
80  setGroupId(group.getGroupId());
81  for (size_t i = 0; i < group.getNumberOfIndividuals(); i++)
82  {
84  }
85  return *this;
86 }
87 
88 void Group::setGroupId(size_t group_id)
89 {
90  id_ = group_id;
91 }
92 
93 void Group::setGroupName(const std::string& group_name)
94 {
95  name_ = group_name;
96 }
97 
99 {
100  try
101  {
102  getIndividualPosition(ind.getId());
103  throw BadIdentifierException("Group::addIndividual: individual id already used.", ind.getId());
104  }
105  catch (BadIdentifierException& bie)
106  {}
107  individuals_.push_back(new Individual(ind));
108 }
109 
110 void Group::addEmptyIndividual(const std::string& individual_id) throw (BadIdentifierException)
111 {
112  for (size_t i = 0; i < getNumberOfIndividuals(); i++)
113  {
114  if (individuals_[i]->getId() == individual_id)
115  throw BadIdentifierException("Group::addEmptyIndividual: individual_id already in use.", individual_id);
116  }
117  individuals_.push_back(new Individual(individual_id));
118 }
119 
120 size_t Group::getIndividualPosition(const std::string& individual_id) const throw (IndividualNotFoundException)
121 {
122  for (size_t i = 0; i < getNumberOfIndividuals(); i++)
123  {
124  if (individuals_[i]->getId() == individual_id)
125  return i;
126  }
127  throw IndividualNotFoundException("Group::getIndividualPosition: individual_id not found.", individual_id);
128 }
129 
130 std::auto_ptr<Individual> Group::removeIndividualById(const std::string& individual_id) throw (IndividualNotFoundException)
131 {
132  try
133  {
134  size_t indPos = getIndividualPosition(individual_id);
135  auto_ptr<Individual> ind(individuals_[indPos]);
136  individuals_.erase(individuals_.begin() + static_cast<ptrdiff_t>(indPos));
137  return ind;
138  }
139  catch (IndividualNotFoundException& infe)
140  {
141  throw IndividualNotFoundException("Group::removeIndividualById: individual_id not found.", individual_id);
142  }
143 }
144 
145 std::auto_ptr<Individual> Group::removeIndividualAtPosition(size_t individual_position) throw (IndexOutOfBoundsException)
146 {
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));
151  return ind;
152 }
153 
154 void Group::deleteIndividualById(const std::string& individual_id) throw (IndividualNotFoundException)
155 {
156  try
157  {
158  removeIndividualById(individual_id);
159  }
160  catch (IndividualNotFoundException& infe)
161  {
162  throw IndividualNotFoundException("Group::deleteIndividualById: individual_id not found.", individual_id);
163  }
164 }
165 
166 void Group::deleteIndividualAtPosition(size_t individual_position) throw (IndexOutOfBoundsException)
167 {
168  try
169  {
170  removeIndividualAtPosition(individual_position);
171  }
172  catch (IndexOutOfBoundsException& ioobe)
173  {
174  throw IndexOutOfBoundsException("Group::deleteIndividualAtPosition.", individual_position, 0, getNumberOfIndividuals());
175  }
176 }
177 
179 {
180  for (size_t i = 0; i < individuals_.size(); i++)
181  {
182  delete (individuals_[i]);
183  }
184  individuals_.clear();
185 }
186 
187 const Individual& Group::getIndividualById(const std::string& individual_id) const throw (IndividualNotFoundException)
188 {
189  for (size_t i = 0; i < individuals_.size(); i++)
190  {
191  if (individuals_[i]->getId() == individual_id)
192  return getIndividualAtPosition(i);
193  }
194  throw IndividualNotFoundException("Group::getIndividualById: individual_id not found.", individual_id);
195 }
196 
197 const Individual& Group::getIndividualAtPosition(size_t individual_position) const
198 throw (IndexOutOfBoundsException)
199 {
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];
203 }
204 
206 {
207  return individuals_.size();
208 }
209 
211 {
212  size_t maxnum = 0;
213  for (size_t i = 0; i < getNumberOfIndividuals(); i++)
214  {
215  vector<size_t> seqpos = individuals_[i]->getSequencesPositions();
216  for (size_t j = 0; j < seqpos.size(); j++)
217  {
218  if (maxnum < seqpos[j])
219  maxnum = seqpos[j];
220  }
221  }
222  return maxnum + 1;
223 }
224 
225 // -- Dealing with individual's properties -----------------
226 
227 void Group::setIndividualSexAtPosition(size_t individual_position, const unsigned short sex) throw (IndexOutOfBoundsException)
228 {
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);
232 }
233 
234 unsigned short Group::getIndividualSexAtPosition(size_t individual_position) const throw (IndexOutOfBoundsException)
235 {
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();
239 }
240 
241 void Group::setIndividualDateAtPosition(size_t individual_position, const Date& date) throw (IndexOutOfBoundsException)
242 {
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);
246 }
247 
248 const Date& Group::getIndividualDateAtPosition(size_t individual_position) const throw (Exception)
249 {
250  if (individual_position >= getNumberOfIndividuals())
251  throw IndexOutOfBoundsException("Group::getIndividualDateAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
252  try
253  {
254  return individuals_[individual_position]->getDate();
255  }
256  catch (NullPointerException& npe)
257  {
258  throw NullPointerException("Group::getIndividualDateAtPosition: individual has no date.");
259  }
260 }
261 
262 void Group::setIndividualCoordAtPosition(size_t individual_position, const Point2D<double>& coord) throw (IndexOutOfBoundsException)
263 {
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);
267 }
268 
269 const Point2D<double>& Group::getIndividualCoordAtPosition(size_t individual_position) const throw (Exception)
270 {
271  if (individual_position >= getNumberOfIndividuals())
272  throw IndexOutOfBoundsException("Group::getIndividualCoordAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
273  try
274  {
275  return individuals_[individual_position]->getCoord();
276  }
277  catch (NullPointerException& npe)
278  {
279  throw NullPointerException("Group::getIndividualCoordAtPosition: individual has no coordinates.");
280  }
281 }
282 
283 void Group::setIndividualLocalityAtPosition(size_t individual_position, const Locality<double>* locality) throw (IndexOutOfBoundsException)
284 {
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);
288 }
289 
290 const Locality<double>& Group::getIndividualLocalityAtPosition(size_t individual_position) const throw (Exception)
291 {
292  if (individual_position >= getNumberOfIndividuals())
293  throw IndexOutOfBoundsException("Group::getIndividualLocalityAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
294  try
295  {
296  return *individuals_[individual_position]->getLocality();
297  }
298  catch (NullPointerException& npe)
299  {
300  throw NullPointerException("Group::getIndividualLocalityAtPosition: individuals has no locality.");
301  }
302 }
303 
304 void Group::addIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position, const Sequence& sequence) throw (Exception)
305 {
306  if (individual_position >= getNumberOfIndividuals())
307  throw IndexOutOfBoundsException("Group::addIndividualSequenceAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
308  try
309  {
310  individuals_[individual_position]->addSequence(sequence_position, sequence);
311  }
312  catch (AlphabetMismatchException& ame)
313  {
314  throw AlphabetMismatchException("Group::addIndividualSequenceAtPosition: sequence's alphabet doesn't match.", ame.getAlphabets()[0], ame.getAlphabets()[1]);
315  }
316  catch (BadIdentifierException& bie)
317  {
318  throw BadIdentifierException("Group::addIndividualSequenceAtPosition: sequence's name already in use.", bie.getIdentifier());
319  }
320  catch (BadIntegerException& bie)
321  {
322  throw BadIntegerException("Group::addIndividualSequenceAtPosition: sequence_position already in use.", bie.getBadInteger());
323  }
324 }
325 
326 const Sequence& Group::getIndividualSequenceByName(size_t individual_position, const string& sequence_name) const throw (Exception)
327 {
328  if (individual_position >= getNumberOfIndividuals())
329  throw IndexOutOfBoundsException("Group::getIndividualSequenceByName: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
330  try
331  {
332  return individuals_[individual_position]->getSequenceByName(sequence_name);
333  }
334  catch (NullPointerException& npe)
335  {
336  throw NullPointerException("Group::getIndividualSequenceByName: no sequence data in individual.");
337  }
338  catch (SequenceNotFoundException& snfe)
339  {
340  throw SequenceNotFoundException("Group::getIndividualSequenceByName: sequence_name not found.", snfe.getSequenceId());
341  }
342 }
343 
344 const Sequence& Group::getIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position) const throw (Exception)
345 {
346  if (individual_position >= getNumberOfIndividuals())
347  throw IndexOutOfBoundsException("Group::getIndividualAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
348  try
349  {
350  return individuals_[individual_position]->getSequenceAtPosition(sequence_position);
351  }
352  catch (NullPointerException& npe)
353  {
354  throw NullPointerException("Group::getIndividualSequenceAtPosition: no sequence data in individual.");
355  }
356  catch (SequenceNotFoundException& snfe)
357  {
358  throw SequenceNotFoundException("Group::getIndividualSequenceAtPosition: sequence_position not found.", snfe.getSequenceId());
359  }
360 }
361 
362 void Group::deleteIndividualSequenceByName(size_t individual_position, const string& sequence_name) throw (Exception)
363 {
364  if (individual_position >= getNumberOfIndividuals())
365  throw IndexOutOfBoundsException("Group::deleteIndividualSequenceByName: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
366  try
367  {
368  individuals_[individual_position]->deleteSequenceByName(sequence_name);
369  }
370  catch (NullPointerException& npe)
371  {
372  throw NullPointerException("Group::deleteSequenceByName: no sequence data in individual.");
373  }
374  catch (SequenceNotFoundException& snfe)
375  {
376  throw SequenceNotFoundException("Group::deleteSequenceByName: sequence_name not found.", snfe.getSequenceId());
377  }
378 }
379 
380 void Group::deleteIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position) throw (Exception)
381 {
382  if (individual_position >= getNumberOfIndividuals())
383  throw IndexOutOfBoundsException("Group::deleteIndividualSequenceAtPosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
384  try
385  {
386  individuals_[individual_position]->deleteSequenceAtPosition(sequence_position);
387  }
388  catch (NullPointerException& npe)
389  {
390  throw NullPointerException("Group::deleteSequenceAtPosition: no sequence data in individual.");
391  }
392  catch (SequenceNotFoundException& snfe)
393  {
394  throw SequenceNotFoundException("Group::deleteSequenceAtPosition: sequence_position not found.", snfe.getSequenceId());
395  }
396 }
397 
398 bool Group::hasIndividualSequences(size_t individual_position) const throw (IndexOutOfBoundsException)
399 {
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();
403 }
404 
405 vector<string> Group::getIndividualSequencesNames(size_t individual_position) const throw (Exception)
406 {
407  if (individual_position >= getNumberOfIndividuals())
408  throw IndexOutOfBoundsException("Group::getIndividualSequencesNames: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
409  try
410  {
411  return individuals_[individual_position]->getSequencesNames();
412  }
413  catch (NullPointerException& npe)
414  {
415  throw NullPointerException("Group::getSequencesNames: no sequence data in individual.");
416  }
417 }
418 
419 size_t Group::getIndividualSequencePosition(size_t individual_position, const string& sequence_name) const throw (Exception)
420 {
421  if (individual_position >= getNumberOfIndividuals())
422  throw IndexOutOfBoundsException("Group::getIndividualSequencePosition: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
423  try
424  {
425  return individuals_[individual_position]->getSequencePosition(sequence_name);
426  }
427  catch (NullPointerException& npe)
428  {
429  throw NullPointerException("Group::getSequencePosition: no sequence data in individual.");
430  }
431  catch (SequenceNotFoundException& snfe)
432  {
433  throw SequenceNotFoundException("Group::getSequencePosition: sequence_name not found.", snfe.getSequenceId());
434  }
435 }
436 
437 size_t Group::getIndividualNumberOfSequences(size_t individual_position) const throw (Exception)
438 {
439  if (individual_position >= getNumberOfIndividuals())
440  throw IndexOutOfBoundsException("Group::getIndividualNumberOfSequences: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
441  try
442  {
443  return individuals_[individual_position]->getNumberOfSequences();
444  }
445  catch (NullPointerException& npe)
446  {
447  throw NullPointerException("Group::getIndividualNumberOfSequences: no sequence data in individual.");
448  }
449 }
450 
451 void Group::setIndividualSequences(size_t individual_position, const MapSequenceContainer& msc) throw (IndexOutOfBoundsException)
452 {
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);
456 }
457 
458 void Group::setIndividualGenotype(size_t individual_position, const MultilocusGenotype& genotype) throw (IndexOutOfBoundsException)
459 {
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);
463 }
464 
465 void Group::initIndividualGenotype(size_t individual_position, size_t loci_number) throw (Exception)
466 {
467  if (individual_position >= getNumberOfIndividuals())
468  throw IndexOutOfBoundsException("Group::initIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
469  try
470  {
471  individuals_[individual_position]->initGenotype(loci_number);
472  }
473  catch (BadIntegerException& bie)
474  {
475  throw BadIntegerException("Group::initIndividualGenotype: loci_number must be > 0.", bie.getBadInteger());
476  }
477  catch (Exception)
478  {
479  throw Exception("Group::initIndividualGenotype: individual already has a genotype.");
480  }
481 }
482 
483 void Group::deleteIndividualGenotype(size_t individual_position) throw (IndexOutOfBoundsException)
484 {
485  if (individual_position >= getNumberOfIndividuals())
486  throw IndexOutOfBoundsException("Group::deleteIndividualGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
487  individuals_[individual_position]->deleteGenotype();
488 }
489 
490 bool Group::hasIndividualGenotype(size_t individual_position) const throw (IndexOutOfBoundsException)
491 {
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();
495 }
496 
497 void Group::setIndividualMonolocusGenotype(size_t individual_position, size_t locus_position, const MonolocusGenotype& monogen) throw (Exception)
498 {
499  if (individual_position >= getNumberOfIndividuals())
500  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
501  try
502  {
503  individuals_[individual_position]->setMonolocusGenotype(locus_position, monogen);
504  }
505  catch (NullPointerException& npe)
506  {
507  throw NullPointerException("Group::setIndividualMonolocusGenotype: individual has no genotype.");
508  }
509  catch (IndexOutOfBoundsException& ioobe)
510  {
511  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotype: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
512  }
513 }
514 
515 void Group::setIndividualMonolocusGenotypeByAlleleKey(size_t individual_position, size_t locus_position, const std::vector<size_t>& allele_keys) throw (Exception)
516 {
517  if (individual_position >= getNumberOfIndividuals())
518  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleKey: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
519  try
520  {
521  individuals_[individual_position]->setMonolocusGenotypeByAlleleKey(locus_position, allele_keys);
522  }
523  catch (NullPointerException& npe)
524  {
525  throw NullPointerException("Group::setIndividualMonolocusGenotypeByAlleleKey: individual has no genotype.");
526  }
527  catch (IndexOutOfBoundsException& ioobe)
528  {
529  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleKey: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
530  }
531  catch (Exception)
532  {
533  throw Exception("Group::setIndividualMonolocusGenotypeByAlleleKey: no key in allele_keys.");
534  }
535 }
536 
537 void Group::setIndividualMonolocusGenotypeByAlleleId(size_t individual_position, size_t locus_position, const std::vector<std::string>& allele_id, const LocusInfo& locus_info) throw (Exception)
538 {
539  if (individual_position >= getNumberOfIndividuals())
540  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleId: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
541  try
542  {
543  individuals_[individual_position]->setMonolocusGenotypeByAlleleId(locus_position, allele_id, locus_info);
544  }
545  catch (NullPointerException& npe)
546  {
547  throw NullPointerException("Group::setIndividualMonolocusGenotypeByAlleleId: individual has no genotype.");
548  }
549  catch (IndexOutOfBoundsException& ioobe)
550  {
551  throw IndexOutOfBoundsException("Group::setIndividualMonolocusGenotypeByAlleleId: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
552  }
553  catch (AlleleNotFoundException& anfe)
554  {
555  throw AlleleNotFoundException("Group::setIndividualMonolocusGenotypeByAlleleId: id not found.", anfe.getIdentifier());
556  }
557 }
558 
559 const MonolocusGenotype& Group::getIndividualMonolocusGenotype(size_t individual_position, size_t locus_position) const throw (Exception)
560 {
561  if (individual_position >= getNumberOfIndividuals())
562  throw IndexOutOfBoundsException("Group::getIndividualMonolocusGenotype: individual_position out of bounds.", individual_position, 0, getNumberOfIndividuals());
563  try
564  {
565  return individuals_[individual_position]->getMonolocusGenotype(locus_position);
566  }
567  catch (NullPointerException& npe)
568  {
569  throw NullPointerException("Group::getIndividualMonolocusGenotype: individual has no genotype.");
570  }
571  catch (IndexOutOfBoundsException& ioobe)
572  {
573  throw IndexOutOfBoundsException("Group::getIndividualMonolocusGenotype: locus_position excedes the number of locus.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
574  }
575 }
576 
578 {
579  for (size_t i = 0; i < getNumberOfIndividuals(); i++)
580  {
581  if (hasIndividualSequences(i))
582  return true;
583  }
584  return false;
585 }
586 
587 const Alphabet* Group::getAlphabet() const throw (NullPointerException)
588 {
589  for (size_t i = 0; i < getNumberOfIndividuals(); i++)
590  {
591  if (hasIndividualSequences(i))
592  return individuals_[i]->getSequenceAlphabet();
593  }
594  throw NullPointerException("Group::getAlphabet: individual has no sequence data.");
595 }
596 
597 size_t Group::getGroupSizeForLocus(size_t locus_position) const
598 {
599  size_t count = 0;
600  for (size_t i = 0; i < individuals_.size(); i++)
601  {
602  if (individuals_[i]->hasGenotype() && !individuals_[i]->getGenotype().isMonolocusGenotypeMissing(locus_position))
603  count++;
604  }
605  return count;
606 }
607 
608 size_t Group::getGroupSizeForSequence(size_t sequence_position) const
609 {
610  size_t count = 0;
611  for (size_t i = 0; i < individuals_.size(); i++)
612  {
613  if (individuals_[i]->hasSequences())
614  {
615  try
616  {
617  individuals_[i]->getSequenceAtPosition(sequence_position);
618  count++;
619  }
620  catch (...)
621  {}
622  }
623  }
624  return count;
625 }
626 
const MonolocusGenotype & getIndividualMonolocusGenotype(size_t individual_position, size_t locus_position) const
Get a MonolocusGenotype of an Individual.
Definition: Group.cpp:559
const Date & getIndividualDateAtPosition(size_t individual_position) const
Get the date of an Individual.
Definition: Group.cpp:248
size_t getGroupId() const
Get the id of the Group.
Definition: Group.h:134
void addIndividual(const Individual &ind)
Add an Individual.
Definition: Group.cpp:98
void setIndividualMonolocusGenotype(size_t individual_position, size_t locus_position, const MonolocusGenotype &monogen)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:497
void setIndividualLocalityAtPosition(size_t individual_position, const Locality< double > *locality)
Set the locality of an Individual.
Definition: Group.cpp:283
Group & operator=(const Group &group)
The assignation operator =.
Definition: Group.cpp:78
std::vector< std::string > getIndividualSequencesNames(size_t individual_position) const
Get the sequences&#39; names from an Individual.
Definition: Group.cpp:405
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.
Definition: Group.cpp:205
bool hasSequenceData() const
Tell if at least one individual has at least one sequence.
Definition: Group.cpp:577
std::vector< Individual * > individuals_
Definition: Group.h:75
const Individual & getIndividualAtPosition(size_t individual_position) const
Get a reference to an Individual by its position.
Definition: Group.cpp:197
void setIndividualDateAtPosition(size_t individual_position, const Date &date)
Set the date of an Individual.
Definition: Group.cpp:241
The BadIdentifierException class.
STL namespace.
bool hasIndividualGenotype(size_t individual_position) const
Tell if an Individual has a genotype.
Definition: Group.cpp:490
size_t getIndividualSequencePosition(size_t individual_position, const std::string &sequence_name) const
Get the position of a sequence in an Individual.
Definition: Group.cpp:419
void deleteIndividualGenotype(size_t individual_position)
Delete the genotype of an Individual.
Definition: Group.cpp:483
Group(size_t group_id)
Build a void new Group.
Definition: Group.cpp:47
void setIndividualMonolocusGenotypeByAlleleKey(size_t individual_position, size_t locus_position, const std::vector< size_t > &allele_keys)
Set a MonolocusGenotype of an Individual.
Definition: Group.cpp:515
void addEmptyIndividual(const std::string &individual_id)
Add an empty Individual to the Group.
Definition: Group.cpp:110
void setGroupName(const std::string &group_name)
Set the name of the Group.
Definition: Group.cpp:93
The Individual class.
Definition: Individual.h:75
const Locality< double > & getIndividualLocalityAtPosition(size_t individual_position) const
Get the locality of an Individual.
Definition: Group.cpp:290
The MultilocusGenotype class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The Date class.
Definition: Date.h:56
const Point2D< double > & getIndividualCoordAtPosition(size_t individual_position) const
Get the coordinates of an Individual.
Definition: Group.cpp:269
void deleteIndividualAtPosition(size_t individual_position)
Delete an Individual from the Group.
Definition: Group.cpp:166
std::auto_ptr< Individual > removeIndividualAtPosition(size_t individual_position)
Remove an Individual from the Group.
Definition: Group.cpp:145
unsigned short getIndividualSexAtPosition(size_t individual_position) const
Get the sex of an Individual.
Definition: Group.cpp:234
const Sequence & getIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position) const
Get a sequence of an Individual.
Definition: Group.cpp:344
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.
Definition: Group.cpp:537
void setIndividualSequences(size_t individual_position, const MapSequenceContainer &msc)
Set all the sequences by copying an OrderedSequenceContainer.
Definition: Group.cpp:451
void initIndividualGenotype(size_t individual_position, size_t loci_number)
Initialyze the genotype of an Individual.
Definition: Group.cpp:465
The AlleleNotFoundException class.
void deleteIndividualSequenceByName(size_t individual_position, const std::string &sequence_name)
Delete a sequence of an Individual.
Definition: Group.cpp:362
bool hasIndividualSequences(size_t individual_position) const
Tell if the Individual has some sequences.
Definition: Group.cpp:398
size_t id_
Definition: Group.h:73
size_t getIndividualNumberOfSequences(size_t individual_position) const
Get the number of sequences in an Individual.
Definition: Group.cpp:437
const Individual & getIndividualById(const std::string &individual_id) const
Get a reference to an Individual.
Definition: Group.cpp:187
std::string name_
Definition: Group.h:74
The IndividualNotFoundException class.
std::auto_ptr< Individual > removeIndividualById(const std::string &individual_id)
Remove an Individual from the Group.
Definition: Group.cpp:130
size_t getGroupSizeForSequence(size_t sequence_position) const
Get the number of individual that have a sequence at the specified position.
Definition: Group.cpp:608
~Group()
Destroy an Group.
Definition: Group.cpp:74
void setIndividualCoordAtPosition(size_t individual_position, const Point2D< double > &coord)
Set the coordinates of an Individual.
Definition: Group.cpp:262
size_t getIndividualPosition(const std::string &individual_id) const
Get the position of an Individual.
Definition: Group.cpp:120
size_t getMaxNumberOfSequences() const
Get the maximum number of sequence.
Definition: Group.cpp:210
void deleteIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position)
Delete a sequence of an Individual.
Definition: Group.cpp:380
void deleteIndividualById(const std::string &individual_id)
Delete an Individual from the Group.
Definition: Group.cpp:154
The Group class.
Definition: Group.h:70
The MonolocusGenotype virtual class.
void clear()
Clear the Group.
Definition: Group.cpp:178
The LocusInfo class.
Definition: LocusInfo.h:63
void setGroupId(size_t group_id)
Set the id of the Group.
Definition: Group.cpp:88
size_t getGroupSizeForLocus(size_t locus_position) const
Get the number of individual that have a data at the specified locus.
Definition: Group.cpp:597
void addIndividualSequenceAtPosition(size_t individual_position, size_t sequence_position, const Sequence &sequence)
Add a sequence to an Individual.
Definition: Group.cpp:304
void setIndividualGenotype(size_t individual_position, const MultilocusGenotype &genotype)
Set the genotype of an Individual.
Definition: Group.cpp:458
void setIndividualSexAtPosition(size_t individual_position, const unsigned short sex)
Set the sex of an Individual.
Definition: Group.cpp:227
const Alphabet * getAlphabet() const
Get the alphabet used for the sequences.
Definition: Group.cpp:587
const Sequence & getIndividualSequenceByName(size_t individual_position, const std::string &sequence_name) const
Get a sequence of an Individual.
Definition: Group.cpp:326