15 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::permuteMultiG(
18 auto permutedPmgc = make_unique<PolymorphismMultiGContainer>(pmgc);
19 vector<size_t> groups;
20 for (
size_t i = 0; i < permutedPmgc->size(); ++i)
22 groups.push_back(permutedPmgc->getGroupId(i));
24 std::shuffle(groups.begin(), groups.end(), RandomTools::DEFAULT_GENERATOR);
25 for (
size_t i = 0; i < permutedPmgc->size(); ++i)
27 permutedPmgc->setGroupId(i, groups[i]);
34 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::permuteMonoG(
36 const std::set<size_t>& groups)
38 unique_ptr<PolymorphismMultiGContainer> permutedPmgc;
40 vector<vector<unique_ptr<const MonolocusGenotypeInterface>>> monoGens;
41 monoGens.resize(locNum);
43 for (
size_t i = 0; i < pmgc.
size(); ++i)
45 if (groups.find(pmgc.
getGroupId(i)) != groups.end())
47 for (
size_t j = 0; j < locNum; ++j)
54 for (
size_t i = 0; i < locNum; ++i)
56 std::shuffle(monoGens[i].begin(), monoGens[i].end(), RandomTools::DEFAULT_GENERATOR);
60 for (
size_t i = 0; i < pmgc.
size(); ++i)
62 if (groups.find(pmgc.
getGroupId(i)) != groups.end())
64 auto tmpMg = make_unique<MultilocusGenotype>(locNum);
65 for (
size_t j = 0; j < locNum; ++j)
68 tmpMg->setMonolocusGenotype(j, *(monoGens[j][k]));
70 permutedPmgc->addMultilocusGenotype(tmpMg, pmgc.
getGroupId(i));
76 permutedPmgc->addMultilocusGenotype(tmpMg, pmgc.
getGroupId(i));
82 for (
auto&
id : grpIds)
85 permutedPmgc->setGroupName(
id, name);
93 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::permuteIntraGroupMonoG(
95 const set<size_t>& groups)
97 auto permutedPmgc = make_unique<PolymorphismMultiGContainer>();
99 vector<vector<unique_ptr<const MonolocusGenotypeInterface>>> monoGens;
100 monoGens.resize(locNum);
102 for (
auto& g : groups)
104 size_t nbIndInGroup = 0;
106 for (
size_t i = 0; i < pmgc.
size(); ++i)
109 if (groups.find(indivGrp) != groups.end())
115 for (
size_t j = 0; j < locNum; ++j)
124 permutedPmgc->addMultilocusGenotype(tmpMg, indivGrp);
129 if (nbIndInGroup > 0)
131 for (
size_t j = 0; j < locNum; ++j)
133 std::shuffle(monoGens[j].begin(), monoGens[j].end(), RandomTools::DEFAULT_GENERATOR);
137 auto tmpMg = make_unique<MultilocusGenotype>(locNum);
138 for (
size_t k = 0; k < nbIndInGroup; ++k)
140 for (
size_t j = 0; j < locNum; ++j)
143 tmpMg->setMonolocusGenotype(j, *(monoGens[j][k]));
146 permutedPmgc->addMultilocusGenotype(tmpMg, g);
153 for (
auto&
id : grpIds)
156 permutedPmgc->setGroupName(
id, name);
164 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::permuteAlleles(
166 const std::set<size_t>& groups)
168 auto permutedPmgc = make_unique<PolymorphismMultiGContainer>();
170 vector<vector<size_t>> alleles;
171 alleles.resize(locNum);
173 for (
size_t i = 0; i < pmgc.
size(); ++i)
175 if (groups.find(pmgc.
getGroupId(i)) != groups.end())
177 for (
size_t j = 0; j < locNum; ++j)
180 for (
size_t k = 0; k < pmgc.
multilocusGenotype(i).monolocusGenotype(j).getAlleleIndex().size(); ++k)
188 for (
size_t i = 0; i < locNum; ++i)
190 std::shuffle(alleles[i].begin(), alleles[i].end(), RandomTools::DEFAULT_GENERATOR);
193 vector<size_t> k(locNum, 0);
194 for (
size_t i = 0; i < pmgc.
size(); ++i)
196 if (groups.find(pmgc.
getGroupId(i)) != groups.end())
198 auto tmpMg = make_unique<MultilocusGenotype>(locNum);
199 for (
size_t j = 0; j < locNum; ++j)
209 permutedPmgc->addMultilocusGenotype(tmpMg, pmgc.
getGroupId(i));
214 permutedPmgc->addMultilocusGenotype(tmpMg, pmgc.
getGroupId(i));
220 for (
auto&
id : grpIds)
223 permutedPmgc->setGroupName(
id, name);
231 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::permuteIntraGroupAlleles(
233 const set<size_t>& groups)
235 auto permutedPmgc = make_unique<PolymorphismMultiGContainer>();
237 vector<vector<size_t>> alleles;
238 alleles.resize(locNum);
240 for (
auto& g : groups)
242 size_t nbIndInGroup = 0;
244 vector<vector<size_t>> nbAllelesForInds;
245 nbAllelesForInds.resize(locNum);
247 for (
size_t i = 0; i < pmgc.
size(); ++i)
250 if (groups.find(indivGrp) != groups.end() )
255 for (
size_t j = 0; j < locNum; ++j)
260 nbAllelesForInds[j].push_back(nbAlls);
261 for (
size_t k = 0; k < nbAlls; ++k)
272 permutedPmgc->addMultilocusGenotype(tmpMg, indivGrp);
277 if (nbIndInGroup > 0)
279 for (
size_t i = 0; i < locNum; ++i)
282 std::shuffle(alleles[i].begin(), alleles[i].end(), RandomTools::DEFAULT_GENERATOR);
286 vector<size_t> k(locNum, 0);
288 for (
size_t ind = 0; ind < nbIndInGroup; ind++)
290 auto tmpMg = make_unique<MultilocusGenotype>(locNum);
291 for (
size_t j = 0; j < locNum; ++j)
293 if (nbAllelesForInds[j][ind] == 1)
295 if (nbAllelesForInds[j][ind] == 2)
299 permutedPmgc->addMultilocusGenotype(tmpMg, g);
307 for (
auto&
id : grpIds)
310 permutedPmgc->setGroupName(
id, name);
318 unique_ptr<PolymorphismMultiGContainer> PolymorphismMultiGContainerTools::extractGroups(
320 const set<size_t>& groups)
322 auto subPmgc = make_unique<PolymorphismMultiGContainer>();
323 for (
auto& g : groups)
326 for (
size_t i = 0; i < pmgc.
size(); ++i)
329 if (groups.find(indivGrp) != groups.end() )
334 subPmgc->addMultilocusGenotype(tmpMg, indivGrp);
341 auto grpIds = subPmgc->getAllGroupsIds();
342 for (
auto&
id : grpIds)
345 subPmgc->setGroupName(
id, name);
The BiAlleleMonolocusGenotype class.
The MonoAlleleMonolocusGenotype class.
MonolocusGenotypeInterface * clone() const override=0
virtual std::vector< size_t > getAlleleIndex() const =0
Get the alleles' index.
const MonolocusGenotypeInterface & monolocusGenotype(size_t locusPosition) const
Get a MonolocusGenotype.
bool isMonolocusGenotypeMissing(size_t locusPosition) const
Tell if a MonolocusGenotype is a missing data.
The PolymorphismMultiGContainer class.
size_t getGroupId(size_t position) const
Get the Group id of a MultilocusGenotype.
size_t getNumberOfLoci() const
Get the number of loci if the MultilocusGenotypes are aligned.
const MultilocusGenotype & multilocusGenotype(size_t position) const
Get a MultilocusGenotype at a position.
std::string getGroupName(size_t groupId) const
Get the group name for a given group id or just the id if not available juste return it's id.
std::set< size_t > getAllGroupsIds() const
Get the groups' ids.
size_t size() const
Get the number of MultilocusGenotype.