当前位置: 首页>>代码示例>>C++>>正文


C++ DNA::resize方法代码示例

本文整理汇总了C++中DNA::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ DNA::resize方法的具体用法?C++ DNA::resize怎么用?C++ DNA::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DNA的用法示例。


在下文中一共展示了DNA::resize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: translateToDnaPhenotypicOrdinal

tsp_individual_multi::DNA tsp_individual_multi::translateToDnaPhenotypicOrdinal(const DNA trait){
    DNA ordinal;
    DNA tmp;
    
    for(int i=0;i<trait.size();i++){
        tmp.push_back(i);
    }
    
    ordinal.resize(trait.size());
    
    for(int i=0;i<trait.size();i++){
        ordinal[i] = tmp[trait[i]];
        tmp.erase(tmp.begin() + trait[i]);
    }
    
    return ordinal;
}
开发者ID:Riyaaaaa,项目名称:Metaheuristics-Template-Library,代码行数:17,代码来源:tsp_ga.cpp

示例2: segregating

PermutationTest& PermutationTest::permute (DNA *dna_in, const int niter, Random &ran) {
	dna = dna_in;
	int i, j, k, pos;

	/* Find out which sites are bi-allelic segregating */
	/* (segregating for short) */
	char state1, state2;
	vector<bool> segregating (dna->lseq);
	for (i = 0; i < dna->lseq; i++) {
		segregating[i] = false;
		state1 = (*dna) [0][i];
		for (j = 1; j < dna->nseq; j++)
			if ( (*dna) [j][i] != state1) {
				state2 = (*dna) [j][i];
				segregating[i] = true;
				j++;
				for (; j < dna->nseq; j++)
					if ( (*dna) [j][i] != state1 && (*dna) [j][i] != state2) {
						/* Tri-allelic segregating */
						segregating[i] = false;
						break;
					}
				break;
			}
	}

	/* Count number of segregating sites */
	int nseg = 0;
	for (i = 0; i < dna->lseq; i++)
		if (segregating[i]) {
			nseg++;
		}
	if (nseg == 0) {
		error ("No segregating sites found");
	}

	/* Copy segregating sites to a new DNA object */
	sdna.resize (dna->nseq, nseg);
	vector<double> d (nseg, 0.0);
	for (i = 0, pos = 0; i < dna->lseq; i++)
		if (segregating[i]) {
			for (j = 0; j < dna->nseq; j++) {
				sdna[j][pos] = (*dna) [j][i];
			}
			d[pos] = (double) i;
			++pos;
		}

	/* Calculate frequency statistics */
	vector<double> F (sdna.lseq, 1.0);								/* F is the marginal frequency of the dna[0][i] (A) allele at site i */
	vector<double> four (4, 0.0);									/* G[i][j] is the frequency of AB (G[i][j][0]), Ab (1), aB (2), ab (3) */
	LowerTriangularMatrix< vector<double> > G (sdna.lseq, four);
	for (i = 0; i < sdna.lseq; i++) {
		state1 = sdna[0][i];
		for (j = 1; j < sdna.nseq; j++)
			if (sdna[j][i] == state1) {
				F[i]++;
			}
		F[i] /= (double) sdna.nseq;
	}
	for (i = 0; i < sdna.lseq; i++)
		for (j = 0; j < i; j++) {
			state1 = sdna[0][i];
			state2 = sdna[0][j];
			for (k = 0; k < sdna.nseq; k++) {
				if (sdna[k][i] == state1 && sdna[k][j] == state2) {
					++G[i][j][0];
				} else if (sdna[k][i] == state1 && sdna[k][j] != state2) {
					++G[i][j][1];
				} else if (sdna[k][i] != state1 && sdna[k][j] == state2) {
					++G[i][j][2];
				} else if (sdna[k][i] != state1 && sdna[k][j] != state2) {
					++G[i][j][3];
				} else {
					warning ("Unexpected choice");
				}
			}
			for (k = 0; k < 4; k++) {
				G[i][j][k] /= (double) sdna.nseq;
			}
		}

	/* Calculate LD statistics for pairs of sites */
	LowerTriangularMatrix<double> A (nseg, 0.0);
	LowerTriangularMatrix<double> B (nseg, 0.0);
	LowerTriangularMatrix<double> C (nseg, 0.0);
	Matrix<double> D (nseg, nseg, 0.0);
	double temp;
//  ofstream out("__out.txt");
//  char tab = '\t';
//  out << "locusA" << tab << "locusB" << tab << "rsq" << tab << "Dprime" << tab << "G4" << "dist" << endl;
	for (i = 0; i < nseg; i++) {
		for (j = 0; j < i; j++) {
			temp = G[i][j][0] - F[i] * F[j];
			A[i][j] = pow (temp, 2.0) / (F[i] * (1. - F[i]) * F[j] * (1. - F[j]) );
			B[i][j] = (temp < 0.0) ? -temp / MIN (F[i] * F[j], (1. - F[i]) * (1. - F[j]) ) : temp / MIN (F[i] * (1. - F[j]), (1. - F[i]) * F[j]);
			C[i][j] = (G[i][j][0] > 0.0 && G[i][j][1] > 0.0 && G[i][j][2] > 0.0 && G[i][j][3] > 0.0) ? 1.0 : 0.0;
			D[i][j] = D[j][i] = d[i] - d[j];
//		  out << i << tab << j << tab << A[i][j] << tab << B[i][j] << tab << C[i][j] << tab << D[i][j] << endl;
		}
//.........这里部分代码省略.........
开发者ID:agapow,项目名称:omegamip,代码行数:101,代码来源:permute.cpp


注:本文中的DNA::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。