14 analyzedLoci_(nullptr),
15 sequenceAlphabet_(ds.sequenceAlphabet_),
25 for (
const auto& group : ds.
groups_)
27 groups_.push_back(unique_ptr<Group>(group->clone()));
49 for (
const auto& group : ds.
groups_)
51 groups_.push_back(unique_ptr<Group>(group->clone()));
64 if (existingLocality->getName() == locality.
getName())
156 for (
const auto& existingGroup :
groups_)
158 if (group.
getGroupId() == existingGroup->getGroupId())
161 groups_.push_back(make_unique<Group>(group));
168 for (
const auto& existingGroup :
groups_)
170 if (groupId == existingGroup->getGroupId())
173 groups_.push_back(make_unique<Group>(groupId));
180 for (
size_t i = 0; i <
groups_.size(); i++)
182 for (
const auto& group :
groups_)
184 if (groupId == group->getGroupId())
208 for (
size_t i = 0; i <
groups_.size(); i++)
210 if (groupId ==
groups_[i]->getGroupId())
212 groups_[i]->setGroupName(group_name);
223 for (
size_t i = 0; i <
groups_.size(); i++)
225 if (groupId ==
groups_[i]->getGroupId())
235 if (groupPosition >=
groups_.size())
237 return *(
groups_[groupPosition]);
244 if (groupPosition >=
groups_.size())
246 groups_.erase(
groups_.begin() +
static_cast<ptrdiff_t
>(groupPosition));
280 for (
size_t i = 0; i <
groups_[source_pos]->getNumberOfIndividuals(); i++)
282 groups_[target_pos]->addIndividual(
groups_[source_pos]->getIndividualAtPosition(i));
292 for (
size_t i = 0; i < groupIds.size(); i++)
304 sort(groupIds.begin(), groupIds.end());
307 for (
size_t i = 1; i < groupIds.size(); i++)
331 size_t newGroupId = 0;
332 for (
size_t i = 0; i <
groups_.size(); i++)
334 if (
groups_[i]->getGroupId() > newGroupId)
335 newGroupId =
groups_[i]->getGroupId();
338 Group newGroup(newGroupId);
339 for (
size_t i = 0; i < individualSelection.size(); i++)
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());
344 for (
size_t i = 0; i < individualSelection.size(); i++)
346 newGroup.
addIndividual(*
groups_[sourcePos]->removeIndividualAtPosition(individualSelection[i]));
347 groups_[sourcePos]->deleteIndividualAtPosition(individualSelection[i]);
362 groups_[group]->addIndividual(individual);
380 groups_[group]->addEmptyIndividual(individual_id);
394 return groups_[groupPosition]->getNumberOfIndividuals();
405 return groups_[groupPosition]->getIndividualPosition(individual_id);
421 return groups_[groupPosition]->getIndividualAtPosition(individualPosition);
437 return groups_[groupPosition]->getIndividualById(individualId);
453 groups_[groupPosition]->deleteIndividualAtPosition(individualPosition);
469 groups_[groupPosition]->deleteIndividualById(individual_id);
485 groups_[groupPosition]->setIndividualSexAtPosition(individualPosition, sex);
501 return groups_[groupPosition]->getIndividualSexAtPosition(individualPosition);
517 groups_[groupPosition]->setIndividualDateAtPosition(individualPosition, date);
533 return groups_[groupPosition]->getIndividualDateAtPosition(individualPosition);
553 groups_[groupPosition]->setIndividualCoordAtPosition(individualPosition, coord);
569 return groups_[groupPosition]->getIndividualCoordAtPosition(individualPosition);
577 throw NullPointerException(
"DataSet::getIndividualCoordInGroup: individual has no coordinate.");
609 return groups_[groupPosition]->getIndividualLocalityAtPosition(individualPosition);
617 throw NullPointerException(
"DataSet::getIndividualLocalityInGroup: individual has no locality.");
629 groups_[groupPosition]->addIndividualSequenceAtPosition(individualPosition, sequence_position, sequence);
646 throw BadIntegerException(
"DataSet::addIndividualSequenceInGroup: sequence_position already in use.", bie.getBadInteger());
658 return groups_[groupPosition]->getIndividualSequenceByName(individualPosition, sequence_name);
666 throw NullPointerException(
"DataSet::getIndividualSequenceByNameInGroup: individual has no sequences.");
682 return groups_[groupPosition]->getIndividualSequenceAtPosition(individualPosition, sequence_position);
686 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
694 throw NullPointerException(
"DataSet::getIndividualSequenceAtPositionInGroup: individual has no sequences.");
706 groups_[groupPosition]->deleteIndividualSequenceByName(individualPosition, sequence_name);
714 throw NullPointerException(
"DataSet::deleteIndividualSequenceByNameInGroup: individual has no sequences.");
730 groups_[groupPosition]->deleteIndividualSequenceAtPosition(individualPosition, sequence_position);
734 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
742 throw NullPointerException(
"DataSet::deleteIndividualSequenceAtPositionInGroup: individual has no sequences.");
754 return groups_[groupPosition]->getIndividualSequencesNames(individualPosition);
762 throw NullPointerException(
"DataSet::getIndividualSequencesNamesInGroup: individual has no sequences.");
774 return groups_[groupPosition]->getIndividualSequencePosition(individualPosition, sequence_name);
782 throw NullPointerException(
"DataSet::getIndividualSequencePositionInGroup: individual has no sequences.");
798 return groups_[groupPosition]->getIndividualNumberOfSequences(individualPosition);
806 throw NullPointerException(
"DataSet::getIndividualNumberOfSequencesInGroup: individual has no sequences.");
818 groups_[groupPosition]->setIndividualGenotype(individualPosition, genotype);
850 throw Exception(
"DataSet::initIndividualGenotypeInGroup: individual already has a genotype.");
862 groups_[groupPosition]->deleteIndividualGenotype(individualPosition);
873 size_t groupPosition,
874 size_t individualPosition,
875 size_t locusPosition,
882 groups_[groupPosition]->setIndividualMonolocusGenotype(individualPosition, locusPosition, monogen);
886 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
894 throw NullPointerException(
"DataSet::setIndividualMonolocusGenotypeInGroup: individual has no genotype.");
906 groups_[groupPosition]->setIndividualMonolocusGenotypeByAlleleKey(individualPosition, locus_position, allele_keys);
910 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
918 throw NullPointerException(
"DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: individual has no genotype.");
922 throw Exception(
"DataSet::setIndividualMonolocusGenotypeByAlleleKeyInGroup: no key in allele_keys.");
935 groups_[groupPosition]->setIndividualMonolocusGenotypeByAlleleId(individualPosition, locus_position, allele_id, locus_info);
939 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
947 throw NullPointerException(
"DataSet::setIndividualMonolocusGenotypeByAlleleIdInGroup: individual has no genotype.");
958 size_t groupPosition,
959 size_t individualPosition,
960 size_t locusPosition)
const
966 return groups_[groupPosition]->getIndividualMonolocusGenotype(individualPosition, locusPosition);
970 if (
string(ioobe.
what()).find(
"individualPosition") <
string(ioobe.
what()).size())
978 throw NullPointerException(
"DataSet::getIndividualMonolocusGenotypeInGroup: individual has no genotype.");
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"))
1036 return analyzedLoci_->getLocusInfoAtPosition(locus_position);
1056 analyzedLoci_->addAlleleInfoByLocusName(locus_name, allele);
1076 analyzedLoci_->addAlleleInfoByLocusPosition(locus_position, allele);
1121 return analyzedLoci_->getPloidyByLocusPosition(locus_position);
1133 auto pmgc = make_unique<PolymorphismMultiGContainer>();
1136 string name =
groups_[i]->getGroupName();
1137 pmgc->addGroupName(i, name);
1141 if (tmpInd.hasGenotype())
1143 auto tmpMg = unique_ptr<MultilocusGenotype>(tmpInd.getGenotype().clone());
1144 pmgc->addMultilocusGenotype(tmpMg, i);
1155 auto pmgc = make_unique<PolymorphismMultiGContainer>();
1156 for (
const auto& it : selection)
1167 string name =
groups_[i]->getGroupName();
1168 pmgc->addGroupName(i, name);
1169 for (
size_t j = 0; j < it.second.size(); j++)
1174 if (tmpInd.hasGenotype())
1176 auto tmpMg = unique_ptr<MultilocusGenotype>(tmpInd.getGenotype().clone());
1177 pmgc->addMultilocusGenotype(tmpMg, i);
1192 const std::map<
size_t, std::vector<size_t>>& selection,
1193 size_t sequencePosition)
const
1195 auto psc = make_unique<PolymorphismSequenceContainer>(
getAlphabet());
1196 for (
auto& it : selection)
1207 for (
size_t j = 0; j < it.second.size(); ++j)
1212 if (tmpInd.hasSequenceAtPosition(sequencePosition))
1214 auto tmpSeq = unique_ptr<Sequence>(tmpInd.sequenceAtPosition(sequencePosition).clone());
1215 psc->addSequenceWithFrequency(tmpSeq->getName(), tmpSeq, 1);
1216 psc->setGroupId(tmpSeq->getName(), it.first);
The AlleleInfo interface.
The AlleleNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
const Alphabet * getSecondAlphabet() const
const Alphabet * getFirstAlphabet() const
The BadIdentifierException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
int getBadInteger() const
const Group & getGroupAtPosition(size_t groupPosition) const
Get a group by position.
void deleteLocalityAtPosition(size_t localityPosition)
Delete a Locality from the DataSet.
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.
size_t getNumberOfGroups() const
Get the number of Groups.
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.
const Group & getGroupById(size_t group_id) const
Get a group by identifier.
void deleteIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
Delete the MultilocusGenotype of an Individual from a Group.
std::unique_ptr< PolymorphismMultiGContainer > getPolymorphismMultiGContainer() const
Get a PolymorphismMultiGContainer with all allelic data of the DataSet.
void addAlleleInfoByLocusName(const std::string &locus_name, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo.
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.
void addAlleleInfoByLocusPosition(size_t locus_position, const AlleleInfo &allele)
Add an AlleleInfo to a LocusInfo.
std::shared_ptr< const Locality< double > > getIndividualLocalityInGroup(size_t groupPosition, size_t individualPosition) const
Get the Locality of an Individual in a Group.
void deleteGroupAtPosition(size_t groupPosition)
Delete a Group from the DataSet.
size_t getPloidyByLocusPosition(size_t locus_position) const
Get the ploidy of a locus.
void mergeTwoGroups(size_t source_id, size_t target_id)
Merge two groups.
const Sequence & getIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string &sequenceName) const
Get a Sequence from an Individual of a Group.
size_t getIndividualPositionInGroup(size_t groupPosition, const std::string &individual_id) const
Get the position of an Individual in a Group.
void mergeGroups(std::vector< size_t > &group_ids)
Merge some Groups in one.
unsigned short getIndividualSexInGroup(size_t groupPosition, size_t individualPosition) const
Get the sex of an Individual in a Group.
std::shared_ptr< const Alphabet > getAlphabet() const
Get a pointer toward the alphabet if there is sequence data.
void deleteLocalityByName(const std::string &name)
Delete a Locality from the DataSet.
const Individual & getIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition) const
Get an Individual from a Group.
void setIndividualCoordInGroup(size_t groupPosition, size_t individualPosition, const Point2D< double > &coord)
Set the coordinates of an Individual in a Group.
void setGroupName(size_t group_id, const std::string &group_name) const
set the name of a Group.
std::vector< std::unique_ptr< Group > > groups_
void deleteIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequencePosition)
Delete a Sequence of an Individual of a Group.
void deleteIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition)
Delete an Individual from a group.
size_t getGroupPosition(size_t group_id) const
Get the position of a Group.
const Individual & getIndividualByIdFromGroup(size_t groupPosition, const std::string &individualId) const
Get an Individual from a Group.
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.
DataSet & operator=(const DataSet &ds)
void addGroup(const Group &group)
Add a Group to the DataSet.
const MonolocusGenotypeInterface & getIndividualMonolocusGenotypeInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition) const
Get a MonolocusGenotype from an Individual of a Group.
void setLocusInfo(size_t locus_position, const LocusInfo &locus)
Set a LocusInfo.
size_t getNumberOfIndividualsInGroup(size_t groupPosition) const
Get the number of Individuals in a Group.
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.
void deleteIndividualSequenceByNameInGroup(size_t groupPosition, size_t individualPosition, const std::string &sequenceName)
Delete a Sequence of an Individual of a Group.
void setIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition, const MultilocusGenotype &genotype)
Set the MultilocusGenotype of an Individual in a Group.
size_t getIndividualNumberOfSequencesInGroup(size_t groupPosition, size_t individualPosition) const
Get the number of Sequences in an Individual of a Group.
void setIndividualSexInGroup(size_t groupPosition, size_t individualPosition, const unsigned short sex)
Set the sex of an Individual in a Group.
void setAlphabet(std::shared_ptr< const Alphabet > alpha)
Set the alphabet of the AnalyzedSequences.
std::vector< std::shared_ptr< Locality< double > > > localities_
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.
const Date & individualDateInGroup(size_t groupPosition, size_t individualPosition) const
Get the Date of an Individual in a Group.
const Point2D< double > & individualCoordInGroup(size_t groupPosition, size_t individualPosition) const
Get the coordinate of an Individual in a Group.
void deleteIndividualByIdFromGroup(size_t groupPosition, const std::string &individualId)
Delete an Individual from a group.
const LocusInfo & getLocusInfoByName(const std::string &locus_name) const
Get a LocusInfo by its name.
size_t getPloidyByLocusName(const std::string &locus_name) const
Get the ploidy of a locus.
const Locality< double > & localityByName(const std::string &name) const
Get a Locality by name.
size_t getLocalityPosition(const std::string &name) const
Get the position of a locality in the container.
const Locality< double > & localityAtPosition(size_t localityPosition) const
Get a Locality by localityPosition.
void addEmptyIndividualToGroup(size_t groupPosition, const std::string &individual_id)
Add an empty Individual to a Group.
std::shared_ptr< const Locality< double > > getLocalityByName(const std::string &name) const
Get a Locality by name.
const LocusInfo & getLocusInfoAtPosition(size_t locus_position) const
Get a LocusInfo by its position.
size_t getNumberOfLoci() const
Get the number of loci.
void setIndividualLocalityInGroupByName(size_t groupPosition, size_t individualPosition, const std::string &localityName)
Set the Locality of an Individual in a Group.
void addIndividualToGroup(size_t groupPosition, const Individual &individual)
Add an Individual to a Group.
std::shared_ptr< const Alphabet > sequenceAlphabet_
std::vector< std::string > getIndividualSequencesNamesInGroup(size_t groupPosition, size_t individualPosition) const
Get the Sequences' names from an Individual of a Group.
void setIndividualMonolocusGenotypeInGroup(size_t groupPosition, size_t individualPosition, size_t locusPosition, const MonolocusGenotypeInterface &monogen)
Set a MonolocusGenotype of an Individual from a group.
const Sequence & getIndividualSequenceAtPositionInGroup(size_t groupPosition, size_t individualPosition, size_t sequencePosition) const
Get a Sequence from an Individual of a Group.
std::unique_ptr< AnalyzedLoci > analyzedLoci_
void initIndividualGenotypeInGroup(size_t groupPosition, size_t individualPosition)
Initialize the genotype of an Individual in a Group.
std::shared_ptr< const Locality< double > > getLocalityAtPosition(size_t localityPosition) const
Get a Locality by localityPosition.
void setIndividualDateInGroup(size_t groupPosition, size_t individualPosition, const Date &date)
Set the Date of an Individual in a Group.
void addEmptyGroup(size_t group_id)
Add an empty Group to the DataSet.
void splitGroup(size_t group_id, std::vector< size_t > individuals_selection)
Split a group in two.
DataSet()
Build a new void DataSet.
void addLocality(const Locality< double > &locality)
Add a locality to the DataSet.
const char * what() const noexcept override
The GroupNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
size_t getGroupId() const
Get the id of the Group.
void addIndividual(const Individual &ind)
Add an Individual.
size_t getNumberOfIndividuals() const
Get the number of Individual in the Group.
const Individual & getIndividualAtPosition(size_t individualPosition) const
Get a reference to an Individual by its position.
const std::string & getGroupName() const
Get the name of the Group.
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.
std::shared_ptr< const Alphabet > getSequenceAlphabet() const
Return the alphabet of the sequences.
bool hasSequences() const
Tell if the Individual has some sequences.
The LocalityNotFoundException class.
virtual const std::string getIdentifier() const
Return the value of the identifier as a string.
const std::string & getName() const
Get the name of the locality.
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)