Init version
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
#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){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int bound1 = rand() % first->at(0).sequence.length;
|
||||
int bound2 = rand() % first->at(0).sequence.length;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20>1><3E>2, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>
|
||||
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){
|
||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int flagNumt = rand() % (int)(1/pNumt);
|
||||
if(flagNumt == 0){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>
|
||||
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){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int bound1 = rand() % first->at(0).sequence.length;
|
||||
int bound2 = rand() % first->at(0).sequence.length;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20>1><3E>2, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>
|
||||
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){
|
||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int flagNumt = rand() % (int)(1/pNumt);
|
||||
if(flagNumt == 0){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "../../ChromosomeRearrangementStrategy.h"
|
||||
|
||||
class Derevyanko2015RecombinationStrategy : public ChromosomeRearrangementStrategy{
|
||||
public:
|
||||
virtual HaploidGenotype buildRecombinantGenotype(const Genotype*);
|
||||
virtual HaploidGenotype buildRecombinantGenotype(const HaploidGenotype&, const HaploidGenotype&);
|
||||
};
|
||||
Reference in New Issue
Block a user