Exemple #1
0
double MothurFisher::hyper_323(double n11, double n1_, double n_1, double n){
	try {
		return(exp(lnbico(n1_,n11)+lnbico(n-n1_,n_1-n11)-lnbico(n,n_1)));
	}catch(exception& e) {
		m->errorOut(e, "MothurFisher", "hyper_323");
		exit(1);
	}
}
Exemple #2
0
double MotifSearch::matrix_score() {
	double ms = 0.0;
	float* freq_matrix = new float[4 * motif.ncols()];
	motif.calc_freq_matrix(freq_matrix);
	int nc = motif.ncols();
	int w = motif.get_width();
	double sc[] = {0.0,0.0,0.0,0.0};
	for(int i = 0; i < 4 * nc; i += 4) {
		for(int j = 0; j < 4; j++) {
			ms += gammaln((double) freq_matrix[i + j] + params.pseudo[j]);
			sc[j] += freq_matrix[i + j];
		}
	}
	delete [] freq_matrix;
	ms -= nc * gammaln((double) motif.number() + params.npseudo);
	for (int j = 0; j < 4; j++)
		ms -= sc[j] * log(params.backfreq[j]);
	/* 
		 This factor arises from a modification of the model of Liu, et al 
		 in which the background frequencies of DNA bases are taken to be
		 constant for the organism under consideration
	 */
	double vg = 0.0;
	ms -= lnbico(w - 2, nc - 2);
	for(int j = 0; j < 4; j++)
		vg += gammaln(params.pseudo[j]);
	vg -= gammaln((double) (params.npseudo));
	ms -= ((double) nc * vg);
	return ms;
}
Exemple #3
0
double prob_overlap(int x, int s1, int s2, int n) {
  assert(x <= s1);
	assert(x <= s2);
	assert(s1 <= n);
	assert(s2 <= n);

	if(x == 0)
		return 1;

	int m1 = min(s1, s2);
	int m2 = max(s1, s2);
	double ret, lt;
	if(x > m1 - x) {
		ret = 0.0;
		for(int i = x; i <= m1; i++) {
			lt = lnbico(m1, i) + lnbico(n - m1, m2 - i) - lnbico(n, m2);
			ret += lt;
		}
		return ret;
	} else {
		ret = 1.0;
		for(int i = 0; i < x; i++) {
			lt = lnbico(m1, i) + lnbico(n - m1, m2 - i) - lnbico(n, m2);
			ret -= lt;
		}
	}
	return ret;
}
Exemple #4
0
double log_prob_overlap(int x, int s1, int s2, int n) {
	assert(x <= s1);
	assert(x <= s2);
	assert(s1 <= n);
	assert(s2 <= n);

	if(x == 0)
		return 0;

	int m1 = min(s1, s2);
	int m2 = max(s1, s2);
	double ret = 0.0, lt;
	for(int i = x; i <= m1; i++) {
		lt = lnbico(m1, i) + lnbico(n - m1, m2 - i) - lnbico(n, m2);
		if(! ret)
			ret = lt;
		else
			ret = logsum(ret, lt);
		if(lt < ret - 5) break;
	}
	return ret;
}