bpp-popgen3  3.0.0
DataSet.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 #include "DataSet.h"
7 
8 using namespace bpp;
9 using namespace std;
10 
11 /******************************************************************************/
12 
14  analyzedLoci_(nullptr),
15  sequenceAlphabet_(ds.sequenceAlphabet_),
16  localities_(),
17  groups_()
18 {
19  if (ds.analyzedLoci_)
20  analyzedLoci_.reset(ds.analyzedLoci_->clone());
21  for (const auto& locality : ds.localities_)
22  {
23  localities_.push_back(unique_ptr<Locality<double>>(locality->clone()));
24  }
25  for (const auto& group : ds.groups_)
26  {
27  groups_.push_back(unique_ptr<Group>(group->clone()));
28  }
29 }
30 
31 /******************************************************************************/
32 
34 {
35  if (ds.analyzedLoci_)
36  analyzedLoci_.reset(ds.analyzedLoci_->clone());
37  else
38  analyzedLoci_.reset(nullptr);
39 
41 
42  localities_.clear();
43  for (const auto& locality : ds.localities_)
44  {
45  localities_.push_back(unique_ptr<Locality<double>>(locality->clone()));
46  }
47 
48  groups_.clear();
49  for (const auto& group : ds.groups_)
50  {
51  groups_.push_back(unique_ptr<Group>(group->clone()));
52  }
53 
54  return *this;
55 }
56 
57 // ** Other methods: *********************************************************/
58 
59 // Dealing with Localities ---------------------------------
61 {
62  for (const auto& existingLocality : localities_)
63  {
64  if (existingLocality->getName() == locality.getName())
65  throw BadIdentifierException("DataSet::addLocality: locality name already in use.", locality.getName());
66  }
67  localities_.push_back(make_unique<Locality<double>>(locality));
68 }
69 
70 /******************************************************************************/
71 
72 size_t DataSet::getLocalityPosition(const std::string& name) const
73 {
74  for (size_t i = 0; i < localities_.size(); ++i)
75  {
76  if (localities_[i]->getName() == name)
77  return i;
78  }
79  throw LocalityNotFoundException("DataSet::getLocalityPosition: Locality not found.", name);
80 }
81 
82 /******************************************************************************/
83 
84 shared_ptr<const Locality<double>> DataSet::getLocalityAtPosition(size_t localityPosition) const
85 {
86  if (localityPosition >= localities_.size())
87  throw IndexOutOfBoundsException("DataSet::getLocalityAtPosition: localityPosition out of bounds.", localityPosition, 0, localities_.size());
88  return localities_[localityPosition];
89 }
90 
91 /******************************************************************************/
92 
93 const Locality<double>& DataSet::localityAtPosition(size_t localityPosition) const
94 {
95  if (localityPosition >= localities_.size())
96  throw IndexOutOfBoundsException("DataSet::getLocalityAtPosition: localityPosition out of bounds.", localityPosition, 0, localities_.size());
97  return *localities_[localityPosition];
98 }
99 
100 /******************************************************************************/
101 
102 shared_ptr<const Locality<double>> DataSet::getLocalityByName(const std::string& name) const
103 {
104  try
105  {
107  }
108  catch (LocalityNotFoundException& lnfe)
109  {
110  throw LocalityNotFoundException("DataSet::getLocalityByName: Locality not found.", name);
111  }
112 }
113 
114 /******************************************************************************/
115 
116 const Locality<double>& DataSet::localityByName(const std::string& name) const
117 {
118  try
119  {
121  }
122  catch (LocalityNotFoundException& lnfe)
123  {
124  throw LocalityNotFoundException("DataSet::getLocalityByName: Locality not found.", name);
125  }
126 }
127 
128 /******************************************************************************/
129 
130 void DataSet::deleteLocalityAtPosition(size_t localityPosition)
131 {
132  if (localityPosition >= localities_.size())
133  throw IndexOutOfBoundsException("DataSet::deleteLocalityAtPosition: localityPosition out of bounds.", localityPosition, 0, localities_.size());
134  localities_.erase(localities_.begin() + static_cast<ptrdiff_t>(localityPosition));
135 }
136 
137 /******************************************************************************/
138 
139 void DataSet::deleteLocalityByName(const std::string& name)
140 {
141  try
142  {
144  }
145  catch (LocalityNotFoundException& lnfe)
146  {
147  throw LocalityNotFoundException("DataSet::deleteLocalityByName: Locality not found.", name);
148  }
149 }
150 
151 /******************************************************************************/
152 
153 // Dealing with groups -------------------------------------
154 void DataSet::addGroup(const Group& group)
155 {
156  for (const auto& existingGroup : groups_)
157  {
158  if (group.getGroupId() == existingGroup->getGroupId())
159  throw BadIdentifierException("DataSet::addGroup: group id already in use.", group.getGroupId());
160  }
161  groups_.push_back(make_unique<Group>(group));
162 }
163 
164 /******************************************************************************/
165 
166 void DataSet::addEmptyGroup(size_t groupId)
167 {
168  for (const auto& existingGroup : groups_)
169  {
170  if (groupId == existingGroup->getGroupId())
171  throw BadIdentifierException("DataSet::addEmptyGroup: groupId already in use.", groupId);
172  }
173  groups_.push_back(make_unique<Group>(groupId));
174 }
175 
176 /******************************************************************************/
177 
178 const Group& DataSet::getGroupById(size_t groupId) const
179 {
180  for (size_t i = 0; i < groups_.size(); i++)
181  {
182  for (const auto& group : groups_)
183  {
184  if (groupId == group->getGroupId())
185  return *group;
186  }
187  }
188  throw GroupNotFoundException("DataSet::getGroupById: groupId not found.", groupId);
189 }
190 
191 /******************************************************************************/
192 
193 string DataSet::getGroupName(size_t groupId) const
194 {
195  string name;
196  name = getGroupById(groupId).getGroupName();
197  if (!name.empty() )
198  return name;
199  else
200  return TextTools::toString(groupId);
201  throw GroupNotFoundException("DataSet::getGroupName: groupId not found.", groupId);
202 }
203 
204 /******************************************************************************/
205 
206 void DataSet::setGroupName(size_t groupId, const std::string& group_name) const
207 {
208  for (size_t i = 0; i < groups_.size(); i++)
209  {
210  if (groupId == groups_[i]->getGroupId())
211  {
212  groups_[i]->setGroupName(group_name);
213  return;
214  }
215  }
216  throw GroupNotFoundException("DataSet::setGroupName: groupId not found.", groupId);
217 }
218 
219 /******************************************************************************/
220 
221 size_t DataSet::getGroupPosition(size_t groupId) const
222 {
223  for (size_t i = 0; i < groups_.size(); i++)
224  {
225  if (groupId == groups_[i]->getGroupId())
226  return i;
227  }
228  throw GroupNotFoundException("DataSet::getGroupPosition: groupId not found.", groupId);
229 }
230 
231 /******************************************************************************/
232 
233 const Group& DataSet::getGroupAtPosition(size_t groupPosition) const
234 {
235  if (groupPosition >= groups_.size())
236  throw IndexOutOfBoundsException("DataSet::getGroup.", groupPosition, 0, groups_.size());
237  return *(groups_[groupPosition]);
238 }
239 
240 /******************************************************************************/
241 
242 void DataSet::deleteGroupAtPosition(size_t groupPosition)
243 {
244  if (groupPosition >= groups_.size())
245  throw IndexOutOfBoundsException("DataSet::deleteGroup.", groupPosition, 0, groups_.size());
246  groups_.erase(groups_.begin() + static_cast<ptrdiff_t>(groupPosition));
247 }
248 
249 /******************************************************************************/
250 
252 {
253  return groups_.size();
254 }
255 
256 /******************************************************************************/
257 
258 void DataSet::mergeTwoGroups(size_t source_id, size_t target_id)
259 {
260  // Test the existence of the two groups.
261  try
262  {
263  getGroupById(source_id);
264  }
265  catch (GroupNotFoundException& e)
266  {
267  throw GroupNotFoundException("DataSet::mergeTwoGroups: source_id not found.", source_id);
268  }
269  try
270  {
271  getGroupById(target_id);
272  }
273  catch (GroupNotFoundException& e)
274  {
275  throw GroupNotFoundException("DataSet::mergeTwoGroups: target_id not found.", target_id);
276  }
277  // Emptie the source into the target
278  size_t source_pos = getGroupPosition(source_id);
279  size_t target_pos = getGroupPosition(target_id);
280  for (size_t i = 0; i < groups_[source_pos]->getNumberOfIndividuals(); i++)
281  {
282  groups_[target_pos]->addIndividual(groups_[source_pos]->getIndividualAtPosition(i));
283  }
284  deleteGroupAtPosition(source_pos);
285 }
286 
287 /******************************************************************************/
288 
289 void DataSet::mergeGroups(std::vector<size_t>& groupIds)
290 {
291  // Test if all group id exists in the DataSet
292  for (size_t i = 0; i < groupIds.size(); i++)
293  {
294  try
295  {
296  getGroupById(groupIds[i]);
297  }
298  catch (GroupNotFoundException& e)
299  {
300  throw GroupNotFoundException("DataSet::mergeGroups: group not found.", groupIds[i]);
301  }
302  }
303  // Sort the group id
304  sort(groupIds.begin(), groupIds.end());
305  // Merge all the groups in the first
306  size_t pos_first = getGroupPosition(groupIds[0]);
307  for (size_t i = 1; i < groupIds.size(); i++)
308  {
309  size_t pos_current = getGroupPosition(groupIds[i]);
310  for (size_t j = 0; j < getGroupAtPosition(pos_current).getNumberOfIndividuals(); j++)
311  {
312  groups_[pos_first]->addIndividual(getGroupAtPosition(pos_current).getIndividualAtPosition(j));
313  }
314  deleteGroupAtPosition(pos_current);
315  }
316 }
317 
318 /******************************************************************************/
319 
320 void DataSet::splitGroup(size_t groupId, vector<size_t> individualSelection)
321 {
322  size_t sourcePos;
323  try
324  {
325  sourcePos = getGroupPosition(groupId);
326  }
327  catch (GroupNotFoundException& gnfe)
328  {
329  throw GroupNotFoundException("DataSet::splitGroup: groupId not found.", gnfe.getIdentifier());
330  }
331  size_t newGroupId = 0;
332  for (size_t i = 0; i < groups_.size(); i++)
333  {
334  if (groups_[i]->getGroupId() > newGroupId)
335  newGroupId = groups_[i]->getGroupId();
336  }
337  newGroupId++;
338  Group newGroup(newGroupId);
339  for (size_t i = 0; i < individualSelection.size(); i++)
340  {
341  if (individualSelection[i] >= groups_[sourcePos]->getNumberOfIndividuals())
342  throw IndexOutOfBoundsException("DataSet::splitGroup: individuals_selection exceeds the number of individual in the group.", individualSelection[i], 0, groups_[sourcePos]->getNumberOfIndividuals());
343  }
344  for (size_t i = 0; i < individualSelection.size(); i++)
345  {
346  newGroup.addIndividual(*groups_[sourcePos]->removeIndividualAtPosition(individualSelection[i]));
347  groups_[sourcePos]->deleteIndividualAtPosition(individualSelection[i]);
348  }
349  addGroup(newGroup);
350 }
351 
352 /******************************************************************************/
353 
354 // Dealing with individuals -------------------------------
355 
356 void DataSet::addIndividualToGroup(size_t group, const Individual& individual)
357 {
358  if (group >= getNumberOfGroups())
359  throw IndexOutOfBoundsException("DataSet::addIndividualToGroup: group out of bounds.", group, 0, getNumberOfGroups());
360  try
361  {
362  groups_[group]->addIndividual(individual);
363  if (individual.hasSequences())
364  setAlphabet(individual.getSequenceAlphabet());
365  }
366  catch (BadIdentifierException& bie)
367  {
368  throw BadIdentifierException("DataSet::addIndividualToGroup: individual's id already in use in this group.", bie.getIdentifier());
369  }
370 }
371 
372 /******************************************************************************/
373 
374 void DataSet::addEmptyIndividualToGroup(size_t group, const std::string& individual_id)
375 {
376  if (group >= getNumberOfGroups())
377  throw IndexOutOfBoundsException("DataSet::addEmptyIndividual: group out of bounds.", group, 0, getNumberOfGroups());
378  try
379  {
380  groups_[group]->addEmptyIndividual(individual_id);
381  }
382  catch (BadIdentifierException& bie)
383  {
384  throw BadIdentifierException("DataSet::addEmptyIndividual: individual_id already in use.", bie.getIdentifier());
385  }
386 }
387 
388 /******************************************************************************/
389 
390 size_t DataSet::getNumberOfIndividualsInGroup(size_t groupPosition) const
391 {
392  if (groupPosition >= getNumberOfGroups())
393  throw IndexOutOfBoundsException("DataSet::getNumberOfIndividualsInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
394  return groups_[groupPosition]->getNumberOfIndividuals();
395 }
396 
397 /******************************************************************************/
398 
399 size_t DataSet::getIndividualPositionInGroup(size_t groupPosition, const std::string& individual_id) const
400 {
401  if (groupPosition >= getNumberOfGroups())
402  throw IndexOutOfBoundsException("DataSet::getIndividualPositionFromGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
403  try
404  {
405  return groups_[groupPosition]->getIndividualPosition(individual_id);
406  }
407  catch (IndividualNotFoundException& infe)
408  {
409  throw IndividualNotFoundException("DataSet::getIndividualPositionFromGroup: individual_id not found.", infe.getIdentifier());
410  }
411 }
412 
413 /******************************************************************************/
414 
415 const Individual& DataSet::getIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition) const
416 {
417  if (groupPosition >= getNumberOfGroups())
418  throw IndexOutOfBoundsException("DataSet::getIndividualAtPositionFromGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
419  try
420  {
421  return groups_[groupPosition]->getIndividualAtPosition(individualPosition);
422  }
423  catch (IndexOutOfBoundsException& ioobe)
424  {
425  throw IndexOutOfBoundsException("DataSet::getIndividualAtPositionFromGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
426  }
427 }
428 
429 /******************************************************************************/
430 
431 const Individual& DataSet::getIndividualByIdFromGroup(size_t groupPosition, const std::string& individualId) const
432 {
433  if (groupPosition >= getNumberOfGroups())
434  throw IndexOutOfBoundsException("DataSet::getIndividualByIdFromGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
435  try
436  {
437  return groups_[groupPosition]->getIndividualById(individualId);
438  }
439  catch (IndividualNotFoundException& infe)
440  {
441  throw IndividualNotFoundException("DataSet::getIndividualByIdFromGroup: individualId not found.", infe.getIdentifier());
442  }
443 }
444 
445 /******************************************************************************/
446 
447 void DataSet::deleteIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition)
448 {
449  if (groupPosition >= getNumberOfGroups())
450  throw IndexOutOfBoundsException("DataSet::deleteIndividualAtPositionFromGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
451  try
452  {
453  groups_[groupPosition]->deleteIndividualAtPosition(individualPosition);
454  }
455  catch (IndexOutOfBoundsException& ioobe)
456  {
457  throw IndexOutOfBoundsException("DataSet::deleteIndividualAtPositionFromGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
458  }
459 }
460 
461 /******************************************************************************/
462 
463 void DataSet::deleteIndividualByIdFromGroup(size_t groupPosition, const std::string& individual_id)
464 {
465  if (groupPosition >= getNumberOfGroups())
466  throw IndexOutOfBoundsException("DataSet::deleteIndividualByIdFromGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
467  try
468  {
469  groups_[groupPosition]->deleteIndividualById(individual_id);
470  }
471  catch (IndividualNotFoundException& infe)
472  {
473  throw IndividualNotFoundException("DataSet::deleteIndividualByIdFromGroup: individual_id not found.", infe.getIdentifier());
474  }
475 }
476 
477 /******************************************************************************/
478 
479 void DataSet::setIndividualSexInGroup(size_t groupPosition, size_t individualPosition, const unsigned short sex)
480 {
481  if (groupPosition >= getNumberOfGroups())
482  throw IndexOutOfBoundsException("DataSet::setIndividualSexInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
483  try
484  {
485  groups_[groupPosition]->setIndividualSexAtPosition(individualPosition, sex);
486  }
487  catch (IndexOutOfBoundsException& ioobe)
488  {
489  throw IndexOutOfBoundsException("DataSet::setIndividualSexInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
490  }
491 }
492 
493 /******************************************************************************/
494 
495 unsigned short DataSet::getIndividualSexInGroup(size_t groupPosition, size_t individualPosition) const
496 {
497  if (groupPosition >= getNumberOfGroups())
498  throw IndexOutOfBoundsException("DataSet::getIndividualSexInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
499  try
500  {
501  return groups_[groupPosition]->getIndividualSexAtPosition(individualPosition);
502  }
503  catch (IndexOutOfBoundsException& ioobe)
504  {
505  throw IndexOutOfBoundsException("DataSet::getIndividualSexInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
506  }
507 }
508 
509 /******************************************************************************/
510 
511 void DataSet::setIndividualDateInGroup(size_t groupPosition, size_t individualPosition, const Date& date)
512 {
513  if (groupPosition >= getNumberOfGroups())
514  throw IndexOutOfBoundsException("DataSet::setIndividualDateInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
515  try
516  {
517  groups_[groupPosition]->setIndividualDateAtPosition(individualPosition, date);
518  }
519  catch (IndexOutOfBoundsException& ioobe)
520  {
521  throw IndexOutOfBoundsException("DataSet::setIndividualDateInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
522  }
523 }
524 
525 /******************************************************************************/
526 
527 const Date& DataSet::individualDateInGroup(size_t groupPosition, size_t individualPosition) const
528 {
529  if (groupPosition >= getNumberOfGroups())
530  throw IndexOutOfBoundsException("DataSet::getIndividualDateInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
531  try
532  {
533  return groups_[groupPosition]->getIndividualDateAtPosition(individualPosition);
534  }
535  catch (IndexOutOfBoundsException& ioobe)
536  {
537  throw IndexOutOfBoundsException("DataSet::getIndividualDateInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
538  }
539  catch (NullPointerException&)
540  {
541  throw NullPointerException("DataSet::getIndividualDateInGroup: individual has no date.");
542  }
543 }
544 
545 /******************************************************************************/
546 
547 void DataSet::setIndividualCoordInGroup(size_t groupPosition, size_t individualPosition, const Point2D<double>& coord)
548 {
549  if (groupPosition >= getNumberOfGroups())
550  throw IndexOutOfBoundsException("DataSet::setIndividualCoordInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
551  try
552  {
553  groups_[groupPosition]->setIndividualCoordAtPosition(individualPosition, coord);
554  }
555  catch (IndexOutOfBoundsException& ioobe)
556  {
557  throw IndexOutOfBoundsException("DataSet::setIndividualCoordInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
558  }
559 }
560 
561 /******************************************************************************/
562 
563 const Point2D<double>& DataSet::individualCoordInGroup(size_t groupPosition, size_t individualPosition) const
564 {
565  if (groupPosition >= getNumberOfGroups())
566  throw IndexOutOfBoundsException("DataSet::getIndividualCoordInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
567  try
568  {
569  return groups_[groupPosition]->getIndividualCoordAtPosition(individualPosition);
570  }
571  catch (IndexOutOfBoundsException& ioobe)
572  {
573  throw IndexOutOfBoundsException("DataSet::getIndividualCoordAtPosition: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
574  }
575  catch (NullPointerException&)
576  {
577  throw NullPointerException("DataSet::getIndividualCoordInGroup: individual has no coordinate.");
578  }
579 }
580 
581 /******************************************************************************/
582 
583 void DataSet::setIndividualLocalityInGroupByName(size_t groupPosition, size_t individualPosition, const std::string& locality_name)
584 {
585  if (groupPosition >= getNumberOfGroups())
586  throw IndexOutOfBoundsException("DataSet::setIndividualLocalityInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
587  try
588  {
589  groups_[groupPosition]->setIndividualLocalityAtPosition(individualPosition, getLocalityByName(locality_name));
590  }
591  catch (IndexOutOfBoundsException& ioobe)
592  {
593  throw IndexOutOfBoundsException("DataSet::setIndividualLocalityInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
594  }
595  catch (LocalityNotFoundException& lnfe)
596  {
597  throw LocalityNotFoundException("DataSet::setIndividualLocalityInGroup: locality_name not found.", lnfe.getIdentifier());
598  }
599 }
600 
601 /******************************************************************************/
602 
603 shared_ptr<const Locality<double>> DataSet::getIndividualLocalityInGroup(size_t groupPosition, size_t individualPosition) const
604 {
605  if (groupPosition >= getNumberOfGroups())
606  throw IndexOutOfBoundsException("DataSet::getIndividualLocalityInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
607  try
608  {
609  return groups_[groupPosition]->getIndividualLocalityAtPosition(individualPosition);
610  }
611  catch (IndexOutOfBoundsException& ioobe)
612  {
613  throw IndexOutOfBoundsException("DataSet::getIndividualLocalityInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
614  }
615  catch (NullPointerException&)
616  {
617  throw NullPointerException("DataSet::getIndividualLocalityInGroup: individual has no locality.");
618  }
619 }
620 
621 /******************************************************************************/
622 
623 void DataSet::addIndividualSequenceInGroup(size_t groupPosition, size_t individualPosition, size_t sequence_position, unique_ptr<Sequence>& sequence)
624 {
625  if (groupPosition >= getNumberOfGroups())
626  throw IndexOutOfBoundsException("DataSet::addIndividualSequenceInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
627  try
628  {
629  groups_[groupPosition]->addIndividualSequenceAtPosition(individualPosition, sequence_position, sequence);
630  setAlphabet(sequence->getAlphabet());
631  }
632  catch (IndexOutOfBoundsException& ioobe)
633  {
634  throw IndexOutOfBoundsException("DataSet::addIndividualSequenceInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
635  }
636  catch (AlphabetMismatchException& ame)
637  {
638  throw AlphabetMismatchException("DataSet::addIndividualSequenceInGroup: sequence's alphabet doesn't match.", ame.getFirstAlphabet(), ame.getSecondAlphabet());
639  }
640  catch (BadIdentifierException& bie)
641  {
642  throw BadIdentifierException("DataSet::addIndividualSequenceInGroup: sequence's name already in use.", bie.getIdentifier());
643  }
644  catch (BadIntegerException& bie)
645  {
646  throw BadIntegerException("DataSet::addIndividualSequenceInGroup: sequence_position already in use.", bie.getBadInteger());
647  }
648 }
649 
650 /******************************************************************************/
651 
652 const Sequence& DataSet::getIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string& sequence_name) const
653 {
654  if (groupPosition >= getNumberOfGroups())
655  throw IndexOutOfBoundsException("DataSet::getIndividualSequenceByNameInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
656  try
657  {
658  return groups_[groupPosition]->getIndividualSequenceByName(individualPosition, sequence_name);
659  }
660  catch (IndexOutOfBoundsException& ioobe)
661  {
662  throw IndexOutOfBoundsException("DataSet::getIndividualSequenceByNameInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
663  }
664  catch (NullPointerException&)
665  {
666  throw NullPointerException("DataSet::getIndividualSequenceByNameInGroup: individual has no sequences.");
667  }
668  catch (SequenceNotFoundException& snfe)
669  {
670  throw SequenceNotFoundException("DataSet::getIndividualSequenceByNameInGroup: sequence_name not found.", snfe.getSequenceId());
671  }
672 }
673 
674 /******************************************************************************/
675 
676 const Sequence& DataSet::getIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequence_position) const
677 {
678  if (groupPosition >= getNumberOfGroups())
679  throw IndexOutOfBoundsException("DataSet::getIndividualSequenceAtPositionInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
680  try
681  {
682  return groups_[groupPosition]->getIndividualSequenceAtPosition(individualPosition, sequence_position);
683  }
684  catch (IndexOutOfBoundsException& ioobe)
685  {
686  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
687  throw IndexOutOfBoundsException("DataSet::getIndividualSequenceAtPositionInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
688  // if (string(ioobe.what()).find("sequence_position") < string(ioobe.what()).size())
689  else
690  throw IndexOutOfBoundsException("DataSet::getIndividualSequenceAtPositionInGroup: sequence_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
691  }
692  catch (NullPointerException&)
693  {
694  throw NullPointerException("DataSet::getIndividualSequenceAtPositionInGroup: individual has no sequences.");
695  }
696 }
697 
698 /******************************************************************************/
699 
700 void DataSet::deleteIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string& sequence_name)
701 {
702  if (groupPosition >= getNumberOfGroups())
703  throw IndexOutOfBoundsException("DataSet::deleteIndividualSequenceByNameInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
704  try
705  {
706  groups_[groupPosition]->deleteIndividualSequenceByName(individualPosition, sequence_name);
707  }
708  catch (IndexOutOfBoundsException& ioobe)
709  {
710  throw IndexOutOfBoundsException("DataSet::deleteIndividualSequenceByNameInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
711  }
712  catch (NullPointerException&)
713  {
714  throw NullPointerException("DataSet::deleteIndividualSequenceByNameInGroup: individual has no sequences.");
715  }
716  catch (SequenceNotFoundException& snfe)
717  {
718  throw SequenceNotFoundException("DataSet::deleteIndividualSequenceByNameInGroup: sequence_name not found.", snfe.getSequenceId());
719  }
720 }
721 
722 /******************************************************************************/
723 
724 void DataSet::deleteIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequence_position)
725 {
726  if (groupPosition >= getNumberOfGroups())
727  throw IndexOutOfBoundsException("DataSet::deleteIndividualSequenceAtPositionInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
728  try
729  {
730  groups_[groupPosition]->deleteIndividualSequenceAtPosition(individualPosition, sequence_position);
731  }
732  catch (IndexOutOfBoundsException& ioobe)
733  {
734  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
735  throw IndexOutOfBoundsException("DataSet::deleteIndividualSequenceAtPositionInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
736  // if (string(ioobe.what()).find("sequence_position") < string(ioobe.what()).size())
737  else
738  throw IndexOutOfBoundsException("DataSet::deleteIndividualSequenceAtPositionInGroup: sequence_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
739  }
740  catch (NullPointerException&)
741  {
742  throw NullPointerException("DataSet::deleteIndividualSequenceAtPositionInGroup: individual has no sequences.");
743  }
744 }
745 
746 /******************************************************************************/
747 
748 std::vector<std::string> DataSet::getIndividualSequencesNamesInGroup(size_t groupPosition, size_t individualPosition) const
749 {
750  if (groupPosition >= getNumberOfGroups())
751  throw IndexOutOfBoundsException("DataSet::getIndividualSequencesNamesInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
752  try
753  {
754  return groups_[groupPosition]->getIndividualSequencesNames(individualPosition);
755  }
756  catch (IndexOutOfBoundsException& ioobe)
757  {
758  throw IndexOutOfBoundsException("DataSet::getIndividualSequencesNamesInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
759  }
760  catch (NullPointerException&)
761  {
762  throw NullPointerException("DataSet::getIndividualSequencesNamesInGroup: individual has no sequences.");
763  }
764 }
765 
766 /******************************************************************************/
767 
768 size_t DataSet::getIndividualSequencePositionInGroup(size_t groupPosition, size_t individualPosition, const std::string& sequence_name) const
769 {
770  if (groupPosition >= getNumberOfGroups())
771  throw IndexOutOfBoundsException("DataSet::getIndividualSequencePositionInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
772  try
773  {
774  return groups_[groupPosition]->getIndividualSequencePosition(individualPosition, sequence_name);
775  }
776  catch (IndexOutOfBoundsException& ioobe)
777  {
778  throw IndexOutOfBoundsException("DataSet::getIndividualSequencePositionInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
779  }
780  catch (NullPointerException&)
781  {
782  throw NullPointerException("DataSet::getIndividualSequencePositionInGroup: individual has no sequences.");
783  }
784  catch (SequenceNotFoundException& snfe)
785  {
786  throw SequenceNotFoundException("DataSet::getIndividualSequencePositionInGroup: sequence_name not found.", snfe.getSequenceId());
787  }
788 }
789 
790 /******************************************************************************/
791 
792 size_t DataSet::getIndividualNumberOfSequencesInGroup(size_t groupPosition, size_t individualPosition) const
793 {
794  if (groupPosition >= getNumberOfGroups())
795  throw IndexOutOfBoundsException("DataSet::getIndividualNumberOfSequencesInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
796  try
797  {
798  return groups_[groupPosition]->getIndividualNumberOfSequences(individualPosition);
799  }
800  catch (IndexOutOfBoundsException& ioobe)
801  {
802  throw IndexOutOfBoundsException("DataSet::getIndividualNumberOfSequencesInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
803  }
804  catch (NullPointerException&)
805  {
806  throw NullPointerException("DataSet::getIndividualNumberOfSequencesInGroup: individual has no sequences.");
807  }
808 }
809 
810 /******************************************************************************/
811 
812 void DataSet::setIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition, const MultilocusGenotype& genotype)
813 {
814  if (groupPosition >= getNumberOfGroups())
815  throw IndexOutOfBoundsException("DataSet::setIndividualGenotypeInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
816  try
817  {
818  groups_[groupPosition]->setIndividualGenotype(individualPosition, genotype);
819  }
820  catch (IndexOutOfBoundsException& ioobe)
821  {
822  throw IndexOutOfBoundsException("DataSet::setIndividualGenotypeInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
823  }
824 }
825 
826 /******************************************************************************/
827 
828 void DataSet::initIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
829 {
830  if (groupPosition >= getNumberOfGroups())
831  throw IndexOutOfBoundsException("DataSet::initIndividualGenotypeInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
832  try
833  {
834  groups_[groupPosition]->initIndividualGenotype(individualPosition, getNumberOfLoci());
835  }
836  catch (IndexOutOfBoundsException& ioobe)
837  {
838  throw IndexOutOfBoundsException("DataSet::initIndividualGenotypeInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
839  }
840  catch (BadIntegerException& bie)
841  {
842  throw BadIntegerException("DataSet::initIndividualGenotypeInGroup: number of loci must be > 0.", bie.getBadInteger());
843  }
844  catch (NullPointerException&)
845  {
846  throw NullPointerException("DataSet::initIndividualGenotypeInGroup: analyzed_loci is NULL.");
847  }
848  catch (Exception&)
849  {
850  throw Exception("DataSet::initIndividualGenotypeInGroup: individual already has a genotype.");
851  }
852 }
853 
854 /******************************************************************************/
855 
856 void DataSet::deleteIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
857 {
858  if (groupPosition >= getNumberOfGroups())
859  throw IndexOutOfBoundsException("DataSet::deleteIndividualGenotypeInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
860  try
861  {
862  groups_[groupPosition]->deleteIndividualGenotype(individualPosition);
863  }
864  catch (IndexOutOfBoundsException& ioobe)
865  {
866  throw IndexOutOfBoundsException("DataSet::deleteIndividualGenotypeInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
867  }
868 }
869 
870 /******************************************************************************/
871 
873  size_t groupPosition,
874  size_t individualPosition,
875  size_t locusPosition,
876  const MonolocusGenotypeInterface& monogen)
877 {
878  if (groupPosition >= getNumberOfGroups())
879  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
880  try
881  {
882  groups_[groupPosition]->setIndividualMonolocusGenotype(individualPosition, locusPosition, monogen);
883  }
884  catch (IndexOutOfBoundsException& ioobe)
885  {
886  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
887  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
888  // if (string(ioobe.what()).find("locus_position") < string(ioobe.what()).size())
889  else
890  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeInGroup: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
891  }
892  catch (NullPointerException&)
893  {
894  throw NullPointerException("DataSet::setIndividualMonolocusGenotypeInGroup: individual has no genotype.");
895  }
896 }
897 
898 /******************************************************************************/
899 
900 void DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup(size_t groupPosition, size_t individualPosition, size_t locus_position, const std::vector<size_t> allele_keys)
901 {
902  if (groupPosition >= getNumberOfGroups())
903  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
904  try
905  {
906  groups_[groupPosition]->setIndividualMonolocusGenotypeByAlleleKey(individualPosition, locus_position, allele_keys);
907  }
908  catch (IndexOutOfBoundsException& ioobe)
909  {
910  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
911  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
912  // if (string(ioobe.what()).find("locus_position") < string(ioobe.what()).size())
913  else
914  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
915  }
916  catch (NullPointerException&)
917  {
918  throw NullPointerException("DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: individual has no genotype.");
919  }
920  catch (Exception&)
921  {
922  throw Exception("DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: no key in allele_keys.");
923  }
924 }
925 
926 /******************************************************************************/
927 
928 void DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup(size_t groupPosition, size_t individualPosition, size_t locus_position, const std::vector<std::string> allele_id)
929 {
930  if (groupPosition >= getNumberOfGroups())
931  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
932  const LocusInfo& locus_info = getLocusInfoAtPosition(locus_position);
933  try
934  {
935  groups_[groupPosition]->setIndividualMonolocusGenotypeByAlleleId(individualPosition, locus_position, allele_id, locus_info);
936  }
937  catch (IndexOutOfBoundsException& ioobe)
938  {
939  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
940  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
941  // if (string(ioobe.what()).find("locus_position") < string(ioobe.what()).size())
942  else
943  throw IndexOutOfBoundsException("DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
944  }
945  catch (NullPointerException&)
946  {
947  throw NullPointerException("DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: individual has no genotype.");
948  }
949  catch (AlleleNotFoundException& anfe)
950  {
951  throw AlleleNotFoundException("DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: id not found.", anfe.getIdentifier());
952  }
953 }
954 
955 /******************************************************************************/
956 
958  size_t groupPosition,
959  size_t individualPosition,
960  size_t locusPosition) const
961 {
962  if (groupPosition >= getNumberOfGroups())
963  throw IndexOutOfBoundsException("DataSet::getIndividualMonolocusGenotypeInGroup: groupPosition out of bounds.", groupPosition, 0, getNumberOfGroups());
964  try
965  {
966  return groups_[groupPosition]->getIndividualMonolocusGenotype(individualPosition, locusPosition);
967  }
968  catch (IndexOutOfBoundsException& ioobe)
969  {
970  if (string(ioobe.what()).find("individualPosition") < string(ioobe.what()).size())
971  throw IndexOutOfBoundsException("DataSet::getIndividualMonolocusGenotypeInGroup: individualPosition out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
972  // if (string(ioobe.what()).find("locus_position") < string(ioobe.what()).size())
973  else
974  throw IndexOutOfBoundsException("DataSet::getIndividualMonolocusGenotypeInGroup: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
975  }
976  catch (NullPointerException&)
977  {
978  throw NullPointerException("DataSet::getIndividualMonolocusGenotypeInGroup: individual has no genotype.");
979  }
980 }
981 
982 /******************************************************************************/
983 
984 void DataSet::setAlphabet(const std::string& alphaType)
985 {
986  if (alphaType != string("DNA") && alphaType != string("RNA") && alphaType != string("PROTEIN"))
987  throw Exception(string("DataSet::setAlphabet: bad alphabet type. (") + alphaType + string(")."));
988  if (alphaType == string("DNA"))
990  if (alphaType == string("RNA"))
992  if (alphaType == string("PROTEIN"))
994 }
995 
996 /******************************************************************************/
997 
998 void DataSet::setLocusInfo(size_t locus_position, const LocusInfo& locus)
999 {
1000  if (analyzedLoci_ == 0)
1001  throw NullPointerException("DataSet::setLocusInfo: there's no AnalyzedLoci to setup.");
1002  try
1003  {
1004  analyzedLoci_->setLocusInfo(locus_position, locus);
1005  }
1006  catch (IndexOutOfBoundsException& ioobe)
1007  {
1008  throw IndexOutOfBoundsException("DataSet::setLocusInfo: locus_position out of bounds.", locus_position, 0, analyzedLoci_->getNumberOfLoci());
1009  }
1010 }
1011 
1012 /******************************************************************************/
1013 
1014 const LocusInfo& DataSet::getLocusInfoByName(const std::string& locus_name) const
1015 {
1016  if (analyzedLoci_ == 0)
1017  throw NullPointerException("DataSet::getLocusInfoByName: there's no AnalyzedLoci.");
1018  try
1019  {
1020  return analyzedLoci_->getLocusInfoByName(locus_name);
1021  }
1022  catch (LocusNotFoundException& lnfe)
1023  {
1024  throw LocusNotFoundException("DataSet::getLocusInfoByName: locus_name not found", locus_name);
1025  }
1026 }
1027 
1028 /******************************************************************************/
1029 
1030 const LocusInfo& DataSet::getLocusInfoAtPosition(size_t locus_position) const
1031 {
1032  if (analyzedLoci_ == 0)
1033  throw NullPointerException("DataSet::getLocusInfoAtPosition: there's no AnalyzedLoci.");
1034  try
1035  {
1036  return analyzedLoci_->getLocusInfoAtPosition(locus_position);
1037  }
1038  catch (IndexOutOfBoundsException& ioobe)
1039  {
1040  throw IndexOutOfBoundsException("DataSet::getLocusInfoAtPosition: locus_position out of bounds.", locus_position, ioobe.getBounds()[0], ioobe.getBounds()[1]);
1041  }
1042  catch (NullPointerException& npe)
1043  {
1044  throw NullPointerException("DataSet::getLocusInfoAtPosition: no locus defined here");
1045  }
1046 }
1047 
1048 /******************************************************************************/
1049 
1050 void DataSet::addAlleleInfoByLocusName(const std::string& locus_name, const AlleleInfo& allele)
1051 {
1052  if (analyzedLoci_ == 0)
1053  throw NullPointerException("DataSet::addAlleleInfoByLocusName: there's no AnalyzedLoci.");
1054  try
1055  {
1056  analyzedLoci_->addAlleleInfoByLocusName(locus_name, allele);
1057  }
1058  catch (LocusNotFoundException& lnfe)
1059  {
1060  throw LocusNotFoundException("DataSet::addAlleleInfoByLocusName: locus_name not found.", lnfe.getIdentifier());
1061  }
1062  catch (BadIdentifierException& bie)
1063  {
1064  throw BadIdentifierException("DataSet::addAlleleInfoByLocusName: allele's id already in use.", bie.getIdentifier());
1065  }
1066 }
1067 
1068 /******************************************************************************/
1069 
1070 void DataSet::addAlleleInfoByLocusPosition(size_t locus_position, const AlleleInfo& allele)
1071 {
1072  if (analyzedLoci_ == 0)
1073  throw NullPointerException("DataSet::addAlleleInfoByLocusPosition: there's no AnalyzedLoci.");
1074  try
1075  {
1076  analyzedLoci_->addAlleleInfoByLocusPosition(locus_position, allele);
1077  }
1078  catch (IndexOutOfBoundsException& ioobe)
1079  {
1080  throw IndexOutOfBoundsException("DataSet::addAlleleInfoByLocusPosition: locus_position out of bounds.", locus_position, ioobe.getBounds()[0], ioobe.getBounds()[1]);
1081  }
1082  catch (BadIdentifierException& bie)
1083  {
1084  throw BadIdentifierException("DataSet::addAlleleInfoByLocusPosition: allele'e id already in use.", bie.getIdentifier());
1085  }
1086 }
1087 
1088 /******************************************************************************/
1089 
1091 {
1092  if (analyzedLoci_ == 0)
1093  throw NullPointerException("DataSet::getNumberOfLoci: there's no AnalyzedLoci.");
1094  return analyzedLoci_->getNumberOfLoci();
1095 }
1096 
1097 /******************************************************************************/
1098 
1099 size_t DataSet::getPloidyByLocusName(const std::string& locus_name) const
1100 {
1101  if (analyzedLoci_ == 0)
1102  throw NullPointerException("DataSet::getPloidyByLocusName: there's no AnalyzedLoci.");
1103  try
1104  {
1105  return analyzedLoci_->getPloidyByLocusName(locus_name);
1106  }
1107  catch (LocusNotFoundException& lnfe)
1108  {
1109  throw LocusNotFoundException("DataSet::getPloidyByLocusName: locus_name not found.", lnfe.getIdentifier());
1110  }
1111 }
1112 
1113 /******************************************************************************/
1114 
1115 size_t DataSet::getPloidyByLocusPosition(size_t locus_position) const
1116 {
1117  if (analyzedLoci_ == 0)
1118  throw NullPointerException("DataSet::getPloidyByLocusPosition: there's no AnalyzedLoci.");
1119  try
1120  {
1121  return analyzedLoci_->getPloidyByLocusPosition(locus_position);
1122  }
1123  catch (IndexOutOfBoundsException& ioobe)
1124  {
1125  throw IndexOutOfBoundsException("DataSet::getPloidyByLocusPosition: locus_position out of bounds.", ioobe.getBadIndex(), ioobe.getBounds()[0], ioobe.getBounds()[1]);
1126  }
1127 }
1128 
1129 /******************************************************************************/
1130 
1131 unique_ptr<PolymorphismMultiGContainer> DataSet::getPolymorphismMultiGContainer() const
1132 {
1133  auto pmgc = make_unique<PolymorphismMultiGContainer>();
1134  for (size_t i = 0; i < getNumberOfGroups(); i++)
1135  {
1136  string name = groups_[i]->getGroupName();
1137  pmgc->addGroupName(i, name);
1138  for (size_t j = 0; j < getNumberOfIndividualsInGroup(i); ++j)
1139  {
1140  const auto& tmpInd = getIndividualAtPositionFromGroup(i, j);
1141  if (tmpInd.hasGenotype())
1142  {
1143  auto tmpMg = unique_ptr<MultilocusGenotype>(tmpInd.getGenotype().clone());
1144  pmgc->addMultilocusGenotype(tmpMg, i);
1145  }
1146  }
1147  }
1148  return pmgc;
1149 }
1150 
1151 /******************************************************************************/
1152 
1153 unique_ptr<PolymorphismMultiGContainer> DataSet::getPolymorphismMultiGContainer(const std::map<size_t, std::vector<size_t>>& selection) const
1154 {
1155  auto pmgc = make_unique<PolymorphismMultiGContainer>();
1156  for (const auto& it : selection)
1157  {
1158  size_t i;
1159  try
1160  {
1161  i = getGroupPosition(it.first);
1162  }
1163  catch (GroupNotFoundException& gnfe)
1164  {
1165  throw gnfe;
1166  }
1167  string name = groups_[i]->getGroupName();
1168  pmgc->addGroupName(i, name);
1169  for (size_t j = 0; j < it.second.size(); j++)
1170  {
1171  try
1172  {
1173  const auto& tmpInd = getIndividualAtPositionFromGroup(i, j);
1174  if (tmpInd.hasGenotype())
1175  {
1176  auto tmpMg = unique_ptr<MultilocusGenotype>(tmpInd.getGenotype().clone());
1177  pmgc->addMultilocusGenotype(tmpMg, i);
1178  }
1179  }
1180  catch (IndexOutOfBoundsException& ioobe)
1181  {
1182  throw ioobe;
1183  }
1184  }
1185  }
1186  return pmgc;
1187 }
1188 
1189 /******************************************************************************/
1190 
1191 unique_ptr<PolymorphismSequenceContainer> DataSet::getPolymorphismSequenceContainer(
1192  const std::map<size_t, std::vector<size_t>>& selection,
1193  size_t sequencePosition) const
1194 {
1195  auto psc = make_unique<PolymorphismSequenceContainer>(getAlphabet());
1196  for (auto& it : selection)
1197  {
1198  size_t i;
1199  try
1200  {
1201  i = getGroupPosition(it.first);
1202  }
1203  catch (GroupNotFoundException& gnfe)
1204  {
1205  throw gnfe;
1206  }
1207  for (size_t j = 0; j < it.second.size(); ++j)
1208  {
1209  try
1210  {
1211  const auto& tmpInd = getIndividualAtPositionFromGroup(i, j);
1212  if (tmpInd.hasSequenceAtPosition(sequencePosition))
1213  {
1214  auto tmpSeq = unique_ptr<Sequence>(tmpInd.sequenceAtPosition(sequencePosition).clone());
1215  psc->addSequenceWithFrequency(tmpSeq->getName(), tmpSeq, 1);
1216  psc->setGroupId(tmpSeq->getName(), it.first);
1217  }
1218  }
1219  catch (IndexOutOfBoundsException& ioobe)
1220  {
1221  throw ioobe;
1222  }
1223  }
1224  }
1225  return psc;
1226 }
1227 
1228 /******************************************************************************/
The AlleleInfo interface.
Definition: AlleleInfo.h:25
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
static std::shared_ptr< const ProteicAlphabet > PROTEIN_ALPHABET
static std::shared_ptr< const DNA > DNA_ALPHABET
static std::shared_ptr< const RNA > RNA_ALPHABET
The BadIdentifierException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The DataSet class.
Definition: DataSet.h:37
const Group & getGroupAtPosition(size_t groupPosition) const
Get a group by position.
Definition: DataSet.cpp:233
void deleteLocalityAtPosition(size_t localityPosition)
Delete a Locality from the DataSet.
Definition: DataSet.cpp:130
size_t getIndividualSequencePositionInGroup(size_t groupPosition, size_t individualPosition, const std::string &sequenceName) const
Get the position of a Sequence in an Individual of a Group.
Definition: DataSet.cpp:768
size_t getNumberOfGroups() const
Get the number of Groups.
Definition: DataSet.cpp:251
std::unique_ptr< PolymorphismSequenceContainer > getPolymorphismSequenceContainer(const std::map< size_t, std::vector< size_t >> &selection, size_t sequence_position) const
Get a PolymorphismSequenceContainer from a selection of groups and individuals.
Definition: DataSet.cpp:1191
const Group & getGroupById(size_t group_id) const
Get a group by identifier.
Definition: DataSet.cpp:178
void deleteIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
Delete the MultilocusGenotype of an Individual from a Group.
Definition: DataSet.cpp:856
std::unique_ptr< PolymorphismMultiGContainer > getPolymorphismMultiGContainer() const
Get a PolymorphismMultiGContainer with all allelic data of the DataSet.
Definition: DataSet.cpp:1131
void addAlleleInfoByLocusName(const std::string &locus_name, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo.
Definition: DataSet.cpp:1050
void setIndividualMonolocusGenotypeByAlleleKeyInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition, const std::vector< size_t > alleleKeys)
Set a MonolocusGenotype of an Individual from a group.
Definition: DataSet.cpp:900
void addAlleleInfoByLocusPosition(size_t locus_position, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo.
Definition: DataSet.cpp:1070
std::shared_ptr< const Locality< double > > getIndividualLocalityInGroup(size_t groupPosition, size_t individualPosition) const
Get the Locality of an Individual in a Group.
Definition: DataSet.cpp:603
void deleteGroupAtPosition(size_t groupPosition)
Delete a Group from the DataSet.
Definition: DataSet.cpp:242
size_t getPloidyByLocusPosition(size_t locus_position) const
Get the ploidy of a locus.
Definition: DataSet.cpp:1115
void mergeTwoGroups(size_t source_id, size_t target_id)
Merge two groups.
Definition: DataSet.cpp:258
const Sequence & getIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string &sequenceName) const
Get a Sequence from an Individual of a Group.
Definition: DataSet.cpp:652
size_t getIndividualPositionInGroup(size_t groupPosition, const std::string &individual_id) const
Get the position of an Individual in a Group.
Definition: DataSet.cpp:399
void mergeGroups(std::vector< size_t > &group_ids)
Merge some Groups in one.
Definition: DataSet.cpp:289
unsigned short getIndividualSexInGroup(size_t groupPosition, size_t individualPosition) const
Get the sex of an Individual in a Group.
Definition: DataSet.cpp:495
std::shared_ptr< const Alphabet > getAlphabet() const
Get a pointer toward the alphabet if there is sequence data.
Definition: DataSet.h:561
void deleteLocalityByName(const std::string &name)
Delete a Locality from the DataSet.
Definition: DataSet.cpp:139
const Individual & getIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition) const
Get an Individual from a Group.
Definition: DataSet.cpp:415
void setIndividualCoordInGroup(size_t groupPosition, size_t individualPosition, const Point2D< double > &coord)
Set the coordinates of an Individual in a Group.
Definition: DataSet.cpp:547
void setGroupName(size_t group_id, const std::string &group_name) const
set the name of a Group.
Definition: DataSet.cpp:206
std::vector< std::unique_ptr< Group > > groups_
Definition: DataSet.h:42
void deleteIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequencePosition)
Delete a Sequence of an Individual of a Group.
Definition: DataSet.cpp:724
void deleteIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition)
Delete an Individual from a group.
Definition: DataSet.cpp:447
size_t getGroupPosition(size_t group_id) const
Get the position of a Group.
Definition: DataSet.cpp:221
const Individual & getIndividualByIdFromGroup(size_t groupPosition, const std::string &individualId) const
Get an Individual from a Group.
Definition: DataSet.cpp:431
std::string getGroupName(size_t group_id) const
Get the name of a Group. If the name is an empty string it just returns the group_id.
Definition: DataSet.cpp:193
DataSet & operator=(const DataSet &ds)
Definition: DataSet.cpp:33
void addGroup(const Group &group)
Add a Group to the DataSet.
Definition: DataSet.cpp:154
const MonolocusGenotypeInterface & getIndividualMonolocusGenotypeInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition) const
Get a MonolocusGenotype from an Individual of a Group.
Definition: DataSet.cpp:957
void setLocusInfo(size_t locus_position, const LocusInfo &locus)
Set a LocusInfo.
Definition: DataSet.cpp:998
size_t getNumberOfIndividualsInGroup(size_t groupPosition) const
Get the number of Individuals in a Group.
Definition: DataSet.cpp:390
void addIndividualSequenceInGroup(size_t groupPosition, size_t individualPosition, size_t sequencePosition, std::unique_ptr< Sequence > &sequence)
Add a Sequence to an Individual in a Group.
Definition: DataSet.cpp:623
void deleteIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string &sequenceName)
Delete a Sequence of an Individual of a Group.
Definition: DataSet.cpp:700
void setIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition, const MultilocusGenotype &genotype)
Set the MultilocusGenotype of an Individual in a Group.
Definition: DataSet.cpp:812
size_t getIndividualNumberOfSequencesInGroup(size_t groupPosition, size_t individualPosition) const
Get the number of Sequences in an Individual of a Group.
Definition: DataSet.cpp:792
void setIndividualSexInGroup(size_t groupPosition, size_t individualPosition, const unsigned short sex)
Set the sex of an Individual in a Group.
Definition: DataSet.cpp:479
void setAlphabet(std::shared_ptr< const Alphabet > alpha)
Set the alphabet of the AnalyzedSequences.
Definition: DataSet.h:549
std::vector< std::shared_ptr< Locality< double > > > localities_
Definition: DataSet.h:41
void setIndividualMonolocusGenotypeByAlleleIdInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition, const std::vector< std::string > alleleId)
Set a MonolocusGenotype of an Individual from a group.
Definition: DataSet.cpp:928
const Date & individualDateInGroup(size_t groupPosition, size_t individualPosition) const
Get the Date of an Individual in a Group.
Definition: DataSet.cpp:527
const Point2D< double > & individualCoordInGroup(size_t groupPosition, size_t individualPosition) const
Get the coordinate of an Individual in a Group.
Definition: DataSet.cpp:563
void deleteIndividualByIdFromGroup(size_t groupPosition, const std::string &individualId)
Delete an Individual from a group.
Definition: DataSet.cpp:463
const LocusInfo & getLocusInfoByName(const std::string &locus_name) const
Get a LocusInfo by its name.
Definition: DataSet.cpp:1014
size_t getPloidyByLocusName(const std::string &locus_name) const
Get the ploidy of a locus.
Definition: DataSet.cpp:1099
const Locality< double > & localityByName(const std::string &name) const
Get a Locality by name.
Definition: DataSet.cpp:116
size_t getLocalityPosition(const std::string &name) const
Get the position of a locality in the container.
Definition: DataSet.cpp:72
const Locality< double > & localityAtPosition(size_t localityPosition) const
Get a Locality by localityPosition.
Definition: DataSet.cpp:93
void addEmptyIndividualToGroup(size_t groupPosition, const std::string &individual_id)
Add an empty Individual to a Group.
Definition: DataSet.cpp:374
std::shared_ptr< const Locality< double > > getLocalityByName(const std::string &name) const
Get a Locality by name.
Definition: DataSet.cpp:102
const LocusInfo & getLocusInfoAtPosition(size_t locus_position) const
Get a LocusInfo by its position.
Definition: DataSet.cpp:1030
size_t getNumberOfLoci() const
Get the number of loci.
Definition: DataSet.cpp:1090
void setIndividualLocalityInGroupByName(size_t groupPosition, size_t individualPosition, const std::string &localityName)
Set the Locality of an Individual in a Group.
Definition: DataSet.cpp:583
void addIndividualToGroup(size_t groupPosition, const Individual &individual)
Add an Individual to a Group.
Definition: DataSet.cpp:356
std::shared_ptr< const Alphabet > sequenceAlphabet_
Definition: DataSet.h:40
std::vector< std::string > getIndividualSequencesNamesInGroup(size_t groupPosition, size_t individualPosition) const
Get the Sequences' names from an Individual of a Group.
Definition: DataSet.cpp:748
void setIndividualMonolocusGenotypeInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype of an Individual from a group.
Definition: DataSet.cpp:872
const Sequence & getIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequencePosition) const
Get a Sequence from an Individual of a Group.
Definition: DataSet.cpp:676
std::unique_ptr< AnalyzedLoci > analyzedLoci_
Definition: DataSet.h:39
void initIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
Initialize the genotype of an Individual in a Group.
Definition: DataSet.cpp:828
std::shared_ptr< const Locality< double > > getLocalityAtPosition(size_t localityPosition) const
Get a Locality by localityPosition.
Definition: DataSet.cpp:84
void setIndividualDateInGroup(size_t groupPosition, size_t individualPosition, const Date &date)
Set the Date of an Individual in a Group.
Definition: DataSet.cpp:511
void addEmptyGroup(size_t group_id)
Add an empty Group to the DataSet.
Definition: DataSet.cpp:166
void splitGroup(size_t group_id, std::vector< size_t > individuals_selection)
Split a group in two.
Definition: DataSet.cpp:320
DataSet()
Build a new void DataSet.
Definition: DataSet.h:49
void addLocality(const Locality< double > &locality)
Add a locality to the DataSet.
Definition: DataSet.cpp:60
The Date class.
Definition: Date.h:21
const char * what() const noexcept override
The GroupNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The Group class.
Definition: Group.h:36
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:12
size_t getNumberOfIndividuals() const
Get the number of Individual in the Group.
Definition: Group.h:158
const Individual & getIndividualAtPosition(size_t individualPosition) const
Get a reference to an Individual by its position.
Definition: Group.cpp:102
const std::string & getGroupName() const
Get the name of the Group.
Definition: Group.h:120
std::size_t getBadIndex() const
const std::array< std::size_t, 2 > & getBounds() const
The IndividualNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The Individual class.
Definition: Individual.h:40
std::shared_ptr< const Alphabet > getSequenceAlphabet() const
Return the alphabet of the sequences.
Definition: Individual.cpp:398
bool hasSequences() const
Tell if the Individual has some sequences.
Definition: Individual.cpp:375
The LocalityNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The Locality class.
Definition: Locality.h:25
const std::string & getName() const
Get the name of the locality.
Definition: Locality.h:90
The LocusInfo class.
Definition: LocusInfo.h:31
The LocusNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
The MonolocusGenotype virtual class.
The MultilocusGenotype class.
virtual const std::string getSequenceId() const
std::string toString(T t)