173 lines
5.3 KiB
C++
173 lines
5.3 KiB
C++
#include "Derevyanko2015RecombinationStrategy.h"
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
HaploidGenotype Derevyanko2015RecombinationStrategy::buildRecombinantGenotype(const Genotype* parentGenotype){
|
|
std::vector<Chromosome> chromosomes;
|
|
const std::vector<Chromosome>* fGenome = &parentGenotype->fatherGenome.chromosomes;
|
|
const std::vector<Chromosome>* mGenome = &parentGenotype->motherGenome.chromosomes;
|
|
|
|
|
|
// srand((unsigned int)time(NULL));
|
|
|
|
// int flag = rand() % 2;
|
|
const std::vector<Gene>* first;
|
|
const std::vector<Gene>* second;
|
|
|
|
first = &fGenome->at(0).genes;
|
|
second= &mGenome->at(0).genes;
|
|
|
|
double pNumt = 1e-2;
|
|
double pHybr = 1e-5;
|
|
|
|
bool sameSpecies = true;
|
|
if(first->at(0).getName().compare(second->at(0).getName()) != 0){
|
|
sameSpecies = false;
|
|
pHybr = 1e-2;
|
|
}
|
|
|
|
Chromosome childChromosome(mGenome->at(0).name);
|
|
Chromosome numtChromosome(mGenome->at(1).name);
|
|
std::string numtName = mGenome->at(1).genes.at(0).getName();
|
|
std::string numtSeq = mGenome->at(1).genes.at(0).sequence;
|
|
|
|
int flag = rand() % (int)(1/pHybr);
|
|
if(flag == 0){
|
|
// Ðåêîìáèíèðóåì ìèòîõîíäðèàëêó
|
|
int bound1 = rand() % first->at(0).sequence.length;
|
|
int bound2 = rand() % first->at(0).sequence.length;
|
|
|
|
// Åñëè á1>á2, îñíîâà - ïàïà, íàîáîðîò - ìàìà
|
|
std::string seq;
|
|
if(bound1 > bound2){
|
|
seq = first->at(0).sequence;
|
|
seq.replace(bound2, bound1-bound2,
|
|
second->at(0).sequence.substr(bound2, bound1-bound2));
|
|
}
|
|
else{
|
|
seq = second->at(0).sequence;
|
|
seq.replace(bound1, bound2-bound1,
|
|
first->at(0).sequence.substr(bound1, bound2-bound1));
|
|
}
|
|
|
|
std::string gName = second->at(0).getName();
|
|
Gene gene(Gene::Sequence, gName, seq);
|
|
childChromosome.insertGeneToEnd(gene);
|
|
std::cerr<<"Recombination occured:\t"<<seq<<"\n";
|
|
|
|
if(!sameSpecies){
|
|
// Òåñò íà íóìòèçàöèþ
|
|
int flagNumt = rand() % (int)(1/pNumt);
|
|
if(flagNumt == 0){
|
|
// Êóñîê ìóæñêîé ìòÄÍÊ êîïèðóåòñÿ â íóìò
|
|
int bound1 = rand() % first->at(0).sequence.length;
|
|
int bound2 = rand() % first->at(0).sequence.length;
|
|
std::string numtAdd = (bound1 < bound2) ?
|
|
first->at(0).sequence.substr(bound1, bound2-bound1) :
|
|
first->at(0).sequence.substr(bound2, bound1-bound2);
|
|
|
|
numtSeq += numtAdd;
|
|
std::cerr<<"New numt occured:\t"<<numtSeq<<"\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
else{
|
|
childChromosome.insertGeneToEnd(second->at(0));
|
|
}
|
|
|
|
Gene geneNumt(Gene::Sequence, numtName, numtSeq);
|
|
numtChromosome.insertGeneToEnd(geneNumt);
|
|
chromosomes.push_back(childChromosome);
|
|
chromosomes.push_back(numtChromosome);
|
|
|
|
return HaploidGenotype(chromosomes);
|
|
}
|
|
|
|
HaploidGenotype Derevyanko2015RecombinationStrategy::
|
|
buildRecombinantGenotype(const HaploidGenotype& fatherGenome, const HaploidGenotype& motherGenome){
|
|
std::vector<Chromosome> chromosomes;
|
|
const std::vector<Chromosome>* fGenome = &fatherGenome.chromosomes;
|
|
const std::vector<Chromosome>* mGenome = *motherGenome.chromosomes;
|
|
|
|
// std::vector<Chromosome> chromosomes;
|
|
// const std::vector<Chromosome>* fGenome = &parentGenotype->fatherGenome.chromosomes;
|
|
// const std::vector<Chromosome>* mGenome = &parentGenotype->motherGenome.chromosomes;
|
|
|
|
|
|
// srand((unsigned int)time(NULL));
|
|
|
|
// int flag = rand() % 2;
|
|
const std::vector<Gene>* first;
|
|
const std::vector<Gene>* second;
|
|
|
|
first = &fGenome->at(0).genes;
|
|
second= &mGenome->at(0).genes;
|
|
|
|
double pNumt = 1e-2;
|
|
double pHybr = 1e-5;
|
|
|
|
bool sameSpecies = true;
|
|
if(first->at(0).getName().compare(second->at(0).getName()) != 0){
|
|
sameSpecies = false;
|
|
pHybr = 1e-2;
|
|
}
|
|
|
|
Chromosome childChromosome(mGenome->at(0).name);
|
|
Chromosome numtChromosome(mGenome->at(1).name);
|
|
std::string numtName = mGenome->at(1).genes.at(0).getName();
|
|
std::string numtSeq = mGenome->at(1).genes.at(0).sequence;
|
|
|
|
int flag = rand() % (int)(1/pHybr);
|
|
if(flag == 0){
|
|
// Ðåêîìáèíèðóåì ìèòîõîíäðèàëêó
|
|
int bound1 = rand() % first->at(0).sequence.length;
|
|
int bound2 = rand() % first->at(0).sequence.length;
|
|
|
|
// Åñëè á1>á2, îñíîâà - ïàïà, íàîáîðîò - ìàìà
|
|
std::string seq;
|
|
if(bound1 > bound2){
|
|
seq = first->at(0).sequence;
|
|
seq.replace(bound2, bound1-bound2,
|
|
second->at(0).sequence.substr(bound2, bound1-bound2));
|
|
}
|
|
else{
|
|
seq = second->at(0).sequence;
|
|
seq.replace(bound1, bound2-bound1,
|
|
first->at(0).sequence.substr(bound1, bound2-bound1));
|
|
}
|
|
|
|
std::string gName = second->at(0).getName();
|
|
Gene gene(Gene::Sequence, gName, seq);
|
|
childChromosome.insertGeneToEnd(gene);
|
|
std::cerr<<"Recombination occured:\t"<<seq<<"\n";
|
|
|
|
if(!sameSpecies){
|
|
// Òåñò íà íóìòèçàöèþ
|
|
int flagNumt = rand() % (int)(1/pNumt);
|
|
if(flagNumt == 0){
|
|
// Êóñîê ìóæñêîé ìòÄÍÊ êîïèðóåòñÿ â íóìò
|
|
int bound1 = rand() % first->at(0).sequence.length;
|
|
int bound2 = rand() % first->at(0).sequence.length;
|
|
std::string numtAdd = (bound1 < bound2) ?
|
|
first->at(0).sequence.substr(bound1, bound2-bound1) :
|
|
first->at(0).sequence.substr(bound2, bound1-bound2);
|
|
|
|
numtSeq += numtAdd;
|
|
std::cerr<<"New numt occured:\t"<<numtSeq<<"\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
else{
|
|
childChromosome.insertGeneToEnd(second->at(0));
|
|
}
|
|
|
|
Gene geneNumt(Gene::Sequence, numtName, numtSeq);
|
|
numtChromosome.insertGeneToEnd(geneNumt);
|
|
chromosomes.push_back(childChromosome);
|
|
chromosomes.push_back(numtChromosome);
|
|
|
|
return HaploidGenotype(chromosomes);
|
|
|
|
} |