#include "Derevyanko2015RecombinationStrategy.h" #include #include HaploidGenotype Derevyanko2015RecombinationStrategy::buildRecombinantGenotype(const Genotype* parentGenotype){ std::vector chromosomes; const std::vector* fGenome = &parentGenotype->fatherGenome.chromosomes; const std::vector* mGenome = &parentGenotype->motherGenome.chromosomes; // srand((unsigned int)time(NULL)); // int flag = rand() % 2; const std::vector* first; const std::vector* 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"<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"<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 chromosomes; const std::vector* fGenome = &fatherGenome.chromosomes; const std::vector* mGenome = *motherGenome.chromosomes; // std::vector chromosomes; // const std::vector* fGenome = &parentGenotype->fatherGenome.chromosomes; // const std::vector* mGenome = &parentGenotype->motherGenome.chromosomes; // srand((unsigned int)time(NULL)); // int flag = rand() % 2; const std::vector* first; const std::vector* 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"<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"<at(0)); } Gene geneNumt(Gene::Sequence, numtName, numtSeq); numtChromosome.insertGeneToEnd(geneNumt); chromosomes.push_back(childChromosome); chromosomes.push_back(numtChromosome); return HaploidGenotype(chromosomes); }