-/* dist_dna.c 2008-12-22 */
+/* dist_dna.c 2010-03-29 */
-/* Copyright 2005-2008 Emmanuel Paradis
+/* Copyright 2005-2010 Emmanuel Paradis
/* This file is part of the R-package `ape'. */
/* See the file ../COPYING for licensing issues. */
#define LN4 1.386294361119890572454
/* returns 8 if the base is known surely, 0 otherwise */
-#define KnownBase(a) a & 8
+#define KnownBase(a) (a & 8)
/* returns 1 if the base is adenine surely, 0 otherwise */
#define IsAdenine(a) a == 136
#define COMPUTE_DIST_F84\
P = ((double) Ns/L);\
Q = ((double) (Nd - Ns)/L);\
- d[target] = -2*A*log(1 - (P/(2*A) - (A - B)*Q/(2*A*C))) + 2*(A - B - C)*log(1 - Q/(2*C));\
+ d[target] = -2*A*log(1 - P/(2*A) - (A - B)*Q/(2*A*C)) + 2*(A - B - C)*log(1 - Q/(2*C));\
if (*variance) {\
t1 = A*C;\
t2 = C*P/2;\
t3 = (A - B)*Q/2;\
a = t1/(t1 - t2 - t3);\
b = A*(A - B)/(t1 - t2 - t3) - (A - B - C)/(C - Q/2);\
- var[target] = (a*a*P + b*b*Q - pow(a*P + b*Q, 2))/2;\
+ var[target] = (a*a*P + b*b*Q - pow(a*P + b*Q, 2))/L;\
}
void distDNA_F84(unsigned char *x, int *n, int *s, double *d,
}
}
-void BaseProportion(unsigned char *x, int *n, double *BF)
+void BaseProportion(unsigned char *x, int *n, double *BF, int *freq)
{
int i, m;
}
}
}
- for (i = 0; i < 4; i++) BF[i] /= m;
+ if (! *freq) for (i = 0; i < 4; i++) BF[i] /= m;
}
void SegSites(unsigned char *x, int *n, int *s, int *seg)
basis = x[i];
i++;
while (i < *n * (j + 1)) {
- if (x[i] == basis) i++;
+ if (!KnownBase(x[i]) || x[i] == basis) i++;
else {
seg[j] = 1;
break;