Beispiel #1
0
    std::pair<Chromosome, Breeder::BreedStats> Breeder::breed(const Chromosome& mum, const Chromosome& dad, uint32_t crossOverPerMillion)
    {
        BreedStats stats;
        stats.crossOvers = 0;

        std::random_device rd;
        std::uniform_int_distribution<> randomMillion(0, 999999);
        std::uniform_int_distribution<> mumOrDad(0, 1);
        bool startWithMum = mumOrDad(rd) == 0;

        const Gene* currentGene = startWithMum ? &mum.gene() : &dad.gene();
        const Gene* otherGene = startWithMum ? &dad.gene() : &mum.gene();

        Gene resultingGene;
        resultingGene.resize(currentGene->size());

        for(uint32_t i = 0; i < resultingGene.size(); i++)
        {
            resultingGene[i] = (*currentGene)[i];

            if(crossOverPerMillion > randomMillion(rd))
            {
                std::swap(currentGene, otherGene);
                ++stats.crossOvers;
            }
        }

        return {Chromosome(mum.maxCistronIds(), mum.informationDensity(), mum.startSequence(), mum.stopSequence(), resultingGene), stats};
    }
Beispiel #2
0
    void Chromosome::replaceCistronValues(const std::vector<Cistron>& cistrons)
    {
        CistronMap cistronMap;

        for(const auto& cistron : cistrons)
        {
            cistronMap.emplace(cistron.id(), cistron);
        }

        size_t start = 0;

        while((start = mGene.find(mStartSequence, start)) != std::string::npos)
        {
            size_t stop = mGene.find(mStopSequence, start);

            if(stop != std::string::npos)
            {
                size_t cistronStart = start + mStartSequence.size();
                Cistron cistron(mGene.substr(cistronStart, stop - cistronStart), mMaxCistronIds, mInformationDensity);

                if(cistronMap.count(cistron.id()))
                {
                    Gene toInsert = mStartSequence;
                    toInsert.append(cistronMap.at(cistron.id()).gene());
                    toInsert.append(mStopSequence);

                    mGene.replace(start, toInsert.size(), toInsert);
                }
            }

            start = stop;
        }
    }
void Host::RestoreHost(const string& sline)
{
	stringstream ssline(sline);

	ssline >> lociKIR;
	ssline >> lociMHC;
	ssline >>age;
	ssline >> tuning;
	ssline >> dead;
	ssline >> mutationRateHost;
	ssline >> inhibitoryKIRs;
	ssline >> activatingKIRs;
	int totalInfections;
	ssline >> totalInfections;

	/*use the streamstring from the position after "totalInfections"
	 *for that I copy the rest of the line into a string, and then reassign the streamstring with the content of
	 *for "restLine. For it to work, I have to clear the string first!
	 */
	string restLine;
	getline(ssline,restLine);
	ssline.clear();
	ssline.str(restLine);
	string infectionString;
	int type; double inf_time; double immune_time; double clearance_time;
	for(int i=0; i<totalInfections; i++)
	{
		Infection dummyInfection;
		infectionString = dummyInfection.RestoreInfection(ssline);
		infections.push_back(dummyInfection);
		ssline.clear();
		ssline.str(infectionString);
	}

	string geneString;
	//cout <<"mhc string>>>>>"<<ssline.str() <<endl;
	for(int i=0; i<lociMHC*TWO; i++)
	{
		Gene mhc;
		geneString = mhc.RestoreGenes(ssline);
		mhcGenes.push_back(mhc);
		ssline.clear();
		ssline.str(geneString);
	}

	string kirString;
	for(int i=0; i<lociKIR*TWO; i++)
	{
		//cout <<"kir string>>>>>"<<ssline.str() <<endl;
		KIRGene kir;
		kirString = kir.RestoreGenes(ssline);
		kirGenes.push_back(kir);
		ssline.clear();
		ssline.str(kirString);

	}
}
Beispiel #4
0
void SmallWorld::initialize() {
	
	for (int i = 0; i < bugNum; i++) {
		Gene gene;
		gene.initialize(minSpeed, maxSpeed, nodeNum * turn);
		genes[i] = gene;
	}
	
	generations++;
}
Beispiel #5
0
void FONSEModel::calculateLogLikelihoodRatioPerGroupingPerCategory(std::string grouping, Genome& genome, std::vector<double> &logAcceptanceRatioForAllMixtures)
{
	int numGenes = genome.getGenomeSize();
	//int numCodons = SequenceSummary::GetNumCodonsForAA(grouping);
	double likelihood = 0.0;
	double likelihood_proposed = 0.0;

	double mutation[5];
	double selection[5];
	double mutation_proposed[5];
	double selection_proposed[5];

	std::string curAA;

	Gene *gene;
	SequenceSummary *sequenceSummary;
	unsigned aaIndex = SequenceSummary::AAToAAIndex(grouping);

#ifdef _OPENMP
//#ifndef __APPLE__
	#pragma omp parallel for private(mutation, selection, mutation_proposed, selection_proposed, curAA, gene, sequenceSummary) reduction(+:likelihood,likelihood_proposed)
#endif
	for (unsigned i = 0u; i < numGenes; i++)
	{
		gene = &genome.getGene(i);
		sequenceSummary = gene->getSequenceSummary();
		if (sequenceSummary->getAACountForAA(aaIndex) == 0) continue;

		// which mixture element does this gene belong to
		unsigned mixtureElement = parameter->getMixtureAssignment(i);
		// how is the mixture element defined. Which categories make it up
		unsigned mutationCategory = parameter->getMutationCategory(mixtureElement);
		unsigned selectionCategory = parameter->getSelectionCategory(mixtureElement);
		unsigned expressionCategory = parameter->getSynthesisRateCategory(mixtureElement);
		// get phi value, calculate likelihood conditional on phi
		double phiValue = parameter->getSynthesisRate(i, expressionCategory, false);


		// get current mutation and selection parameter
		parameter->getParameterForCategory(mutationCategory, FONSEParameter::dM, grouping, false, mutation);
		parameter->getParameterForCategory(selectionCategory, FONSEParameter::dOmega, grouping, false, selection);

		// get proposed mutation and selection parameter
		parameter->getParameterForCategory(mutationCategory, FONSEParameter::dM, grouping, true, mutation_proposed);
		parameter->getParameterForCategory(selectionCategory, FONSEParameter::dOmega, grouping, true, selection_proposed);
		
		likelihood += calculateLogLikelihoodRatioPerAA(*gene, grouping, mutation, selection, phiValue);
		likelihood_proposed += calculateLogLikelihoodRatioPerAA(*gene, grouping, mutation_proposed, selection_proposed, phiValue);
	}
	//likelihood_proposed = likelihood_proposed + calculateMutationPrior(grouping, true);
	//likelihood = likelihood + calculateMutationPrior(grouping, false);

	logAcceptanceRatioForAllMixtures[0] = (likelihood_proposed - likelihood);
}
Beispiel #6
0
/* -----------------------------------------------------------------------
 * makeGeneVector():
 *
 * Returns a vector of n randomly generated genes of length CHROMOSOME_LENGTH. Gives each
 * object in the vector a fitness level of 0 to start it out.
 * -----------------------------------------------------------------------
 */
vector<Gene> makeGeneVector(int n)
{
    vector<Gene> geneVector;
    
    /* Make INITIAL_POPULATION amount of random genes and push it to firstNGenes */
    for (int i = 0; i < INITIAL_POPULATION; i++)
    {
        Gene g;
        g.setValues(makeRandomGene(), 0);
        geneVector.push_back(g);
    }
    
    return geneVector;
}
Beispiel #7
0
genotypes::genotypes(int genomSize) {

	Gene n;
	
	for(int i = 0; i < genomSize; i++){
		for(int j = 0; j < SEGMENT_SIZE; j++){
			if(rand()%2){
				n.flip(j);
			}
		}
		genom.push_back(n);
		n.reset();
	}

}
Beispiel #8
0
unsigned int Neuron::loadWeights(Gene const &gene, unsigned int index)
{
  unsigned int i(0);
  for (auto &s : _inputs)
    {
      s.second = gene.getWeight(index + i);
      i++;
    }
  return index + i;
}
Beispiel #9
0
	bool operator<(const Gene& g) const {
		if( (compareChar(chrom.c_str(), g.getChr().c_str()) < 0) ||
				(hs == g.getHS() && entrez_ID < g.getEID()) ||
				(hs == g.getHS() && entrez_ID == g.getEID() && start_p < g.getStart()) ||
				(hs == g.getHS() && entrez_ID == g.getEID() && start_p == g.getStart() && stop_p < g.getStop())
		)
			return true;
		else
			return false;
	}
Genome* SelfAdaptiveMutation::mutateProper(Genome* target) {
	std::vector<Gene*> genes = target->getGenome();
	std::vector<Gene*> results;
	for (unsigned int i = 0; i < this->initialGenomeLength; i++)
		results.push_back(genes[i]->copy());

	double rhoZero = HierRNG::gaussian(0, 1);

	for (unsigned int index: this->stdDevIndices) {
		Gene* target = genes[index];
		double stdDev = target->getIndex();
		double tauResult = this->tauPrime * rhoZero
			+ this->tau * HierRNG::gaussian(0, 1);
		stdDev *= this->useTauPlusOneCorrection ?
			pow(stdDev, tauResult) : exp(tauResult);
		results.push_back(target->copy(stdDev));
	}

	for (unsigned int i = 0; i < this->initialGenomeLength; i++) {
		Gene* original = results[i];
		double newIndex = original->getIndex();
		newIndex = newIndex
			+ results[this->initialGenomeLength + i]->getIndex()
			* HierRNG::gaussian(0, 1);
		results[i] = original->copy(newIndex);
		delete(original);
	}

	return new Genome(results, target->getSpeciesNode());
}
Beispiel #11
0
void main()
{
	CDiophantine dp(1, 2, 3, 4, 30);

	int ans;
	ans = dp.Solve();
	if (ans == -1)
	{
		cout << "No solution found." << endl;
	}
	else
	{
		Gene gn = dp.GetGene(ans);

		cout << "The solution set to a+2b+3c+4d=30 is:\n";
		cout << "a = " << gn.getAlleles()[0] << "." << endl;
		cout << "b = " << gn.getAlleles()[1] << "." << endl;
		cout << "c = " << gn.getAlleles()[2] << "." << endl;
		cout << "d = " << gn.getAlleles()[3] << "." << endl;
	}
	getchar();
}
Beispiel #12
0
void genetic::Generation::Generate(const genetic::Generation& ancestor)
{
  int& nCells = gainput.max_cells;
  m_cells = vector<Cell>(nCells, Cell());

  int iCell = 0;

  // Chose Elites
  for(; iCell < gainput.max_elite; ++iCell) m_cells[iCell] = ancestor.m_cells[iCell];

  // Selection to Next Generation
  while(iCell < nCells)
  {
    Gene child;

    if(drand(1.0) > gainput.thre_cloning)
    {
      child = ancestor.Select().Gen();
    }
    else
    {
      Cell father(ancestor.Select());
      Cell mother(ancestor.Select());
//    if(father.Fitness() > mother.Fitness())
        child = father.Gen() * mother.Gen();
//    else
//      child = mother.Gen() * father.Gen();
    }
    // Mutation
    if(drand(1.0) < gainput.thre_mutation) child.pMutate();
    if(drand(1.0) < gainput.thre_mutation) child.gMutate();

    m_cells[iCell++] = Cell(child);
  }

  ComputeProbability();
}
Beispiel #13
0
void Gene::singleCross(Gene& g1,Gene& g2,unsigned position){
	Gene g1temp = g1;
	unsigned word = position / bits_per_word;
	unsigned bit = position % bits_per_word;
	unsigned byte_before = word * sizeof(g1.data[0]);
	memcpy(g1temp.data, g2.data, byte_before);
	memcpy(g2.data, g1.data, byte_before);
	for(int i = 0 ; i < bit ; i++){
		if( (g1.data[word] & (BIT_MASK << i)) != (g2.data[word] & (BIT_MASK << i)) ){
			unsigned pos = i + word * bits_per_word;
			g1temp.toggle(pos);
			g2.toggle(pos);
		}
	}
	g1 = g1temp;
};
Beispiel #14
0
double genetic::Evaluate(const double& scale, const double& np, const Gene& gene, const Matrix& K)
{
  Matrix Kp;
  Permute(K, gene.Sequence(), Kp);

  double weight = 0.0;
  for(int i = 0; i < Kp.Nrows(); ++i)
    for(int j = i + 1; j < Kp.Ncols(); ++j)
    {
      double d = j - i;
//    weight += Kp.element(i, j) * pow(d, np);
      weight += Kp.element(i, j) * d * d;
    }

  return scale * weight;
}
Beispiel #15
0
void SmallWorld::breed() {
	
	if (bugs.size() > 2) {
		
		vector<Gene> tmp;
		tmp.resize(bugs.size());
		
		tmp[0] = bugs[0].getGene();
		tmp[1] = bugs[1].getGene();
		
		for (int i = 2; i < bugs.size() - 1; i++) {
			Gene gene;
			gene.crossover(tmp[0].dna, tmp[1].dna, nodeNum * turn);
			
			for (int j = 0; j < int(nodeNum / 4); j++) {
				gene.mutation(minSpeed, maxSpeed, probability);
			}
			
			tmp[i] = gene;
		}
		
		for (int i = bugs.size() - 2; i < bugs.size() - 1; i++) {
			Gene gene;
			gene.crossover(tmp[0].dna, tmp[1].dna, nodeNum * turn);
			
			for (int j = 0; j < int(nodeNum / 4); j++) {
				gene.mutation(minSpeed, maxSpeed, probability * 10);
			}
			
			tmp[i] = gene;
		}
		
		for (int i = bugs.size() - 1; i < bugs.size(); i++) {
			Gene gene;
			gene.initialize(minSpeed, maxSpeed, nodeNum * turn);
			tmp[i] = gene;
		}
		
		genes.swap(tmp);
	}
	
	generations++;
}
Beispiel #16
0
void Neuron::saveWeights(Gene &gene) const
{
  for (auto s : _inputs)
    gene.addWeight(s.second);
}
Beispiel #17
0
void FONSEModel::calculateLogLikelihoodRatioPerGene(Gene& gene, unsigned geneIndex, unsigned k, double* logProbabilityRatio)
{
	double likelihood = 0.0;
	double likelihood_proposed = 0.0;
	std::string curAA;
	std::vector <unsigned> positions;
	double mutation[5];
	double selection[5];

	SequenceSummary *seqsum = gene.getSequenceSummary();

	// get correct index for everything
	unsigned mutationCategory = parameter->getMutationCategory(k);
	unsigned selectionCategory = parameter->getSelectionCategory(k);
	unsigned expressionCategory = parameter->getSynthesisRateCategory(k);

	double phiValue = parameter->getSynthesisRate(geneIndex, expressionCategory, false);
	double phiValue_proposed = parameter->getSynthesisRate(geneIndex, expressionCategory, true);


	/* This loop causes a compiler warning because i is an int, but openMP won't compile if I change i to unsigned.
		Maybe worth looking into? */
#ifndef __APPLE__
#pragma omp parallel for private(mutation, selection, positions, curAA) reduction(+:likelihood,likelihood_proposed)
#endif
	for (int i = 0; i < getGroupListSize(); i++)
	{
		curAA = getGrouping(i);

		parameter->getParameterForCategory(mutationCategory, FONSEParameter::dM, curAA, false, mutation);
		parameter->getParameterForCategory(selectionCategory, FONSEParameter::dOmega, curAA, false, selection);

		likelihood += calculateLogLikelihoodRatioPerAA(gene, curAA, mutation, selection, phiValue);
		likelihood_proposed += calculateLogLikelihoodRatioPerAA(gene, curAA, mutation, selection, phiValue_proposed);
	}

	//std::cout << logLikelihood << " " << logLikelihood_proposed << std::endl;

	double stdDevSynthesisRate = parameter->getStdDevSynthesisRate(false);
	double logPhiProbability = Parameter::densityLogNorm(phiValue, (-(stdDevSynthesisRate * stdDevSynthesisRate) / 2), stdDevSynthesisRate, true);
	double logPhiProbability_proposed = Parameter::densityLogNorm(phiValue_proposed, (-(stdDevSynthesisRate * stdDevSynthesisRate) / 2), stdDevSynthesisRate, true);
	double currentLogLikelihood = (likelihood + logPhiProbability);
	double proposedLogLikelihood = (likelihood_proposed + logPhiProbability_proposed);
	if (phiValue == 0) {
		std::cout << "phiValue is 0\n";
	}
	if (phiValue_proposed == 0) {
		std::cout << "phiValue_prop is 0\n";
	}
	logProbabilityRatio[0] = (proposedLogLikelihood - currentLogLikelihood) - (std::log(phiValue) - std::log(phiValue_proposed));
	logProbabilityRatio[1] = currentLogLikelihood - std::log(phiValue_proposed);
	if (std::isinf(logProbabilityRatio[1])) {
		std::cout << "logprob1 inf\n";
	}
	logProbabilityRatio[2] = proposedLogLikelihood - std::log(phiValue);
	if (std::isinf(logProbabilityRatio[2])) {
		std::cout << "logprob2 inf\n";
	}

	//------------NOTE: Jeremy, Cedric changed the reverse jump to where we DON'T include it. I had my RFP
	//LogLikelihood go to 0 because of now missing terms. I have added the code underneath to where we calculate it---/

	logProbabilityRatio[3] = currentLogLikelihood;
	logProbabilityRatio[4] = proposedLogLikelihood;
}
void Host::MutateGenesForMutualInvasion(int mutationType, KIRGene& kir_hap2, Map& kirMap, GenePool& mhcPool, double simulationTime, double time_invasion, int gene_type)
{

	if(mutationType == 1)//pick another molecule as mutation
	{
		KIRGene newGene(RandomNumber(2,16));
		/*if(!kirMap.IsGeneInMap(newGene))
		{
			kirMap.FillMap(mhcPool, newGene);
			//cout <<simulationTime << "|" <<time_invasion <<endl;
			if(simulationTime < time_invasion)//only after the invasion time, the receptor type should be allowed to mutate
				newGene.SetGeneType(gene_type);
			kir_hap2.Copy(newGene);
		}//*/
		int M_id = 0;
		int mhcPoolSize = mhcPool.GetPoolSize();
		
		//calculate the value of M_id to determine whether the gene is pseudogene or not
		for(unsigned int i = 0; i < mhcPoolSize; i++)
		{
			Gene mhcGene;
			mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
			int L = newGene.BindMolecule(mhcGene);
			if(L >= newGene.GetGeneSpecificity())
				M_id += (1<<i);
		}
		//set the Gene pseudo
		newGene.SetPseudogene(M_id);
		if(gene_type !=2)////force to have only one type of receptors, if the user wants it!
			newGene.SetGeneType(gene_type);
		kir_hap2.Copy(newGene);
		return;
	}

	if(mutationType == 2)//point mutation + L
	{
		if(RandomNumberDouble()<0.8)
		{
			kir_hap2.PointMutation();
			//kirMap.FillMap(mhcPool, kir_hap2);
			int M_id = 0;
			int mhcPoolSize = mhcPool.GetPoolSize();
			
			//calculate the value of M_id to determine whether the gene is pseudogene or not
			for(unsigned int i = 0; i < mhcPoolSize; i++)
			{
				Gene mhcGene;
				mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
				int L = kir_hap2.BindMolecule(mhcGene);
				if(L >= kir_hap2.GetGeneSpecificity())
					M_id+= (1<<i);
			}
			//set the Gene pseudo
			kir_hap2.SetPseudogene(M_id);
		}

		if(RandomNumberDouble()<0.2)
		{
			kir_hap2.MutateSpecificity();
			//kirMap.FillMap(mhcPool, kir_hap2);
			int M_id = 0;
			int mhcPoolSize = mhcPool.GetPoolSize();
			
			//calculate the value of M_id to determine whether the gene is pseudogene or not
			for(unsigned int i = 0; i < mhcPoolSize; i++)
			{
				Gene mhcGene;
				mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
				int L = kir_hap2.BindMolecule(mhcGene);
				if(L >= kir_hap2.GetGeneSpecificity())
					M_id+= (1<<i);
			}
			//set the Gene pseudo
			kir_hap2.SetPseudogene(M_id);
		}
		if(RandomNumberDouble()<0.2)
		{
			if(simulationTime >= time_invasion) //only after the invasion time, the receptor type should be allowed to mutate
				kir_hap2.MutateReceptorType();
		}
		return;
	}
}
void Host :: MutateGenes(int mutationType, KIRGene& kir_hap2, Map& kirMap, GenePool& mhcPool, int gene_type)
{
	if(mutationType == 1)//pick another molecules as mutation
	{
		KIRGene newGene(RandomNumber(2,16));
		/*if(!kirMap.IsGeneInMap(newGene))
		{
			kirMap.FillMap(mhcPool, newGene);
			if(gene_type !=2)////force to have only one type of receptors, if the user wants it!
				newGene.SetGeneType(gene_type);
			kir_hap2.Copy(newGene);
		}//*/
		int M_id = 0;
		int mhcPoolSize = mhcPool.GetPoolSize();
		
		//calculate the value of M_id to determine whether the gene is pseudogene or not
		for(unsigned int i = 0; i < mhcPoolSize; i++)
		{
			Gene mhcGene;
			mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
			int L = newGene.BindMolecule(mhcGene);
			if(L >= newGene.GetGeneSpecificity())
				M_id += (1<<i);
		}
		newGene.SetPseudogene(M_id);
		if(gene_type !=2)////force to have only one type of receptors, if the user wants it!
			newGene.SetGeneType(gene_type);
		kir_hap2.Copy(newGene);
		return;
	}

	if(mutationType == 2)//point mutation + L
	{

		if(RandomNumberDouble()<0.8) //pointmutation
		{
			kir_hap2.PointMutation();
			//kirMap.FillMap(mhcPool, kir_hap2);
			int M_id = 0;
			int mhcPoolSize = mhcPool.GetPoolSize();
			
			//calculate the value of M_id to determine whether the gene is pseudogene or not
			for(unsigned int i = 0; i < mhcPoolSize; i++)
			{
				Gene mhcGene;
				mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
				int L = kir_hap2.BindMolecule(mhcGene);
				if(L >= kir_hap2.GetGeneSpecificity())
					M_id += (1<<i);
			}
			kir_hap2.SetPseudogene(M_id);
		}

		if(RandomNumberDouble()<0.8) //mutate L
		{
			kir_hap2.MutateSpecificity();
			//kirMap.FillMap(mhcPool, kir_hap2);
			int M_id = 0;
			int mhcPoolSize = mhcPool.GetPoolSize();
			
			//calculate the value of M_id to determine whether the gene is pseudogene or not
			for(unsigned int i = 0; i < mhcPoolSize; i++)
			{
				Gene mhcGene;
				mhcGene.SetGeneID(mhcPool.GetGenes().at(i));
				int L = kir_hap2.BindMolecule(mhcGene);
				if(L >= kir_hap2.GetGeneSpecificity())
					M_id += (1<<i);
			}
			kir_hap2.SetPseudogene(M_id);
		}
		if(RandomNumberDouble()<0.8)//mutate type
		{
			kir_hap2.MutateReceptorType();
		}
		return;
	}
}
/*FUNCTIONS OF CLASS HOST
 *Constructs a host for the initialization of the population: it fills the MHC genes with a randomly picked allele from the population
 * and creates KIRs that match their own MHC according to the specificity*/
Host::Host(int loci_kir, int loci_mhc, double _mutationRate, bool _tuning, int numberOfExtraKirs,Map& kirMap, MHCGenePool& mhcPool, bool hla) {

	InitializeHostParameters(_mutationRate,_tuning, loci_kir, loci_mhc);
	//fill the mhc Genes
	for(int i = 0; i <lociMHC*TWO; i++)
	{
		Gene firstGene;
		int mhc1 = mhcPool.RandomlyPickGene(hla);
		firstGene.SetGeneID(mhc1);
		mhcGenes.push_back(firstGene);
	}

/*
	Gene secondGene;
	secondGene.SetGeneID(mhc2);
	mhcGenes.push_back(secondGene);*/

	//create random KIRs with random specificity for ONE haplotype
	// (at the beginning of the simulation, the size of the map should equal the LOCI_NUMBER)
	map< pair<int,int>, pair <int, int> > ::iterator it;
	for(it = kirMap.GetMap().begin(); it != kirMap.GetMap().end(); it ++)
	{
		int id = it->first.first;
		int geneType = it->first.second;
		int L = it->second.first;
		int pseudo = it->second.second;
		KIRGene kir;
		kir.SetGeneSpecificity(L);
		kir.SetGeneID(id);
		kir.SetPseudogene(pseudo);
		kir.SetGeneType(geneType);
		kir.SetGeneFunctionality(false);
		kir.SetGeneExpression(false);
		kirGenes.push_back(kir);
		//cout << "printing genes in host first constructor" <<endl;
		//kir.PrintGenes();
	}

	int size = kirGenes.size();
	//make sure that the first haplotype has number lociKIR (regardless of the Map size!)
	while(size < lociKIR)
	{
		KIRGene bla = kirGenes.at(size-1);
		kirGenes.push_back(bla);
		size ++;
	}

	//copy the first kirs into the other haplotype (all individuals are homozygous!)
	for(int i=0; i<lociKIR; i++)
	{
		KIRGene kir = kirGenes.at(i);
		kirGenes.push_back(kir);

	}

	if(tuning == true)
		EducateKIRs();
	ExpressKIRs(numberOfExtraKirs);
	//CountFunctionalKIRs();
	age = RandomNumber(1,70); //population initialized with a random age between 1 and 70
	//cout <<inhibitoryKIRs << "|" <<activatingKIRs <<"|"<<CountExpressedKIRs() <<endl;
}
int main(int argc, char * argv[])
{

    int c;
    int option_index = 0;

    string truth_file="";
    string result_file="";
    string gene_file="";
    string output_file="";
    string rule_file="";
    int base_resolution=1;
    int max_diff=20;
    string pseudo_counts="0,0,0,0,0,0";
    int print_num=0;

    static struct option long_options[] = {
        {"truth-file",            required_argument, 0,  't' },
        {"result-file",           required_argument, 0,  'r' },
        {"gene-annotation-file",  required_argument, 0,  'g' },
        {"output-file",           required_argument, 0,  'o' },
        {"subsetting-rule-file",  required_argument, 0,  's' },
        {"base-resolution",       required_argument, 0,  'b' },
        {"max-diff",              required_argument, 0,  'm' },
        {"pseudo-counts",         required_argument, 0,  'p' },
        {"use-number",            no_argument,       0,  'u' },
        {"help",                  no_argument,       0,  'h' },
        {0, 0, 0, 0}
    };

    while(1)
    {
        c = getopt_long(argc, argv, "t:r:g:o:s:b:m:p:uh",
                 long_options, &option_index);
        if (c==-1)
        {
            break;
        }
        switch(c)
        {
            case 'h':
                usage();
                exit(0);
            case 't':
                truth_file=optarg;
                break;
            case 'r':
                result_file=optarg;
                break;
            case 'g':
                gene_file=optarg;
                break;
            case 'o':
                output_file=optarg;
                break;
            case 's':
                rule_file=optarg;
                break;
            case 'b':
                base_resolution=atoi(optarg);
                break;
            case 'm':
                max_diff=atoi(optarg);
                break;
            case 'p':
                pseudo_counts=optarg;
                break;
            case 'u':
                print_num=1;
                break;
            default:
                break;
        }

    }


    if(truth_file.compare("")==0 || result_file.compare("")==0 || gene_file.compare("")==0 || output_file.compare("")==0|| rule_file.compare("")==0)
    {
        usage();
        exit(0);
    }

    pseudo_counts_t pct;
    get_pseudo_counts(pseudo_counts, pct);

    cerr<<"loading gene annotation file..."<<endl;    

    Gene g;
    g.loadGenesFromFile((char*)gene_file.c_str());
    g.setGene();    

    cerr<<"loading result file..."<<endl;

    Bedpe res;
    res.loadFromFile((char *)result_file.c_str());

    cerr<<"removing duplicate results..."<<endl;
    res.uniq();
    
    cerr<<"loading truth file..."<<endl;

    Bedpe truth;
    truth.loadFromFile((char*)truth_file.c_str());

    vector<evaluate_t> evaluates;

    cerr<<"comparing by subsetting rules..."<<endl;

    ExecuteByRule exe;
    exe.execute(res, truth, (char*)output_file.c_str(), (char*)rule_file.c_str(), evaluates, g, base_resolution, max_diff, pct, print_num);

    cerr<<"printing evaluation results..."<<endl;
   
    Printer per;
    per.print(evaluates, (char*)output_file.c_str(), gene_file, base_resolution, max_diff, pseudo_counts, version);

    return 0;
}
Beispiel #22
0
	bool operator==(const Gene& g) const { return entrez_ID == g.getEID(); }
Beispiel #23
0
void FONSEModel::simulateGenome(Genome & genome)
{
	unsigned codonIndex;
	std::string curAA;

	std::string tmpDesc = "Simulated Gene";

	for (unsigned geneIndex = 0; geneIndex < genome.getGenomeSize(); geneIndex++) //loop over all genes in the genome
	{
		if (geneIndex % 100 == 0) my_print("Simulating Gene %\n", geneIndex);
		Gene gene = genome.getGene(geneIndex);
		SequenceSummary sequenceSummary = gene.geneData;
		std::string tmpSeq = "ATG"; //Always will have the start amino acid


		unsigned mixtureElement = getMixtureAssignment(geneIndex);
		unsigned mutationCategory = getMutationCategory(mixtureElement);
		unsigned selectionCategory = getSelectionCategory(mixtureElement);
		unsigned synthesisRateCategory = getSynthesisRateCategory(mixtureElement);
		double phi = getSynthesisRate(geneIndex, synthesisRateCategory, false);

		std::string geneSeq = gene.getSequence();
		for (unsigned position = 1; position < (geneSeq.size() / 3); position++)
		{
			std::string codon = geneSeq.substr((position * 3), 3);
			curAA = SequenceSummary::codonToAA(codon);

			//TODO: Throw an error here instead
			if (curAA == "X") {
				if (position < (geneSeq.size() / 3) - 1) my_print("Warning: Internal stop codon found in gene % at position %. Ignoring and moving on.\n", gene.getId(), position);
				continue;
			}

			unsigned numCodons = SequenceSummary::GetNumCodonsForAA(curAA);

			double* codonProb = new double[numCodons](); //size the arrays to the proper size based on # of codons.
			double* mutation = new double[numCodons - 1]();
			double* selection = new double[numCodons - 1]();


			if (curAA == "M" || curAA == "W")
			{
				codonProb[0] = 1;
			}
			else
			{
				getParameterForCategory(mutationCategory, FONSEParameter::dM, curAA, false, mutation);
				getParameterForCategory(selectionCategory, FONSEParameter::dOmega, curAA, false, selection);
				calculateCodonProbabilityVector(numCodons, position, mutation, selection, phi, codonProb);
			}


			codonIndex = Parameter::randMultinom(codonProb, numCodons);
			unsigned aaStart, aaEnd;
			SequenceSummary::AAToCodonRange(curAA, aaStart, aaEnd, false);  //need the first spot in the array where the codons for curAA are
			codon = sequenceSummary.indexToCodon(aaStart + codonIndex);//get the correct codon based off codonIndex
			tmpSeq += codon;
		}
		std::string codon = sequenceSummary.indexToCodon((unsigned)Parameter::randUnif(61.0, 64.0)); //randomly choose a stop codon, from range 61-63
		tmpSeq += codon;
		Gene simulatedGene(tmpSeq, tmpDesc, gene.getId());
		genome.addGene(simulatedGene, true);
	}
}