X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fme.c;h=8a00591ab680cb6846fc9ea7765c4a9b7e893c0f;hb=dc2dda7eb763b4e140f1e5adb7fa8bfaa2661f6d;hp=69d1cb210bb5d17c3a69c928870457e4032e9098;hpb=d88302b4735b5b7c9132387090bb592d906fe1cb;p=ape.git diff --git a/src/me.c b/src/me.c index 69d1cb2..8a00591 100644 --- a/src/me.c +++ b/src/me.c @@ -1,7 +1,7 @@ -/* me.c 2008-01-14 */ +/* me.c 2012-04-30 */ /* Copyright 2007-2008 Olivier Gascuel, Rick Desper, - R port by Vincent Lefort, me_*() below modified by Emmanuel Paradis */ + R port by Vincent Lefort and Emmanuel Paradis */ /* This file is part of the R-package `ape'. */ /* See the file ../COPYING for licensing issues. */ @@ -20,10 +20,15 @@ void makeOLSAveragesTable(tree *T, double **D, double **A); void bNNI(tree *T, double **avgDistArray, int *count, double **D, int numSpecies); //functions from NNI.c void NNI(tree *T, double **avgDistArray, int *count, double **D, int numSpecies); +//functions from SPR.c +void SPR(tree *T, double **D, double **A, int *count); +//functions from TBR.c +void TBR(tree *T, double **D, double **A); -void me_b(double *X, int *N, char **labels, int *nni, - int *edge1, int *edge2, double *el, char **tl) +void me_b(double *X, int *N, int *labels, + int *nni, int *spr, int *tbr, + int *edge1, int *edge2, double *el) { double **D, **A; set *species, *slooper; @@ -46,11 +51,13 @@ void me_b(double *X, int *N, char **labels, int *nni, T = BMEaddSpecies(T, addNode, D, A); } // Compute bNNI - if (*nni == 1) - bNNI(T, A, &nniCount, D, n); + if (*nni) bNNI(T, A, &nniCount, D, n); assignBMEWeights(T,A); - tree2phylo(T, edge1, edge2, el, tl, n); + if (*spr) SPR(T, D, A, &nniCount); + if (*tbr) TBR(T, D, A); + + tree2phylo(T, edge1, edge2, el, labels, n); freeMatrix(D,n); freeMatrix(A,2*n - 2); @@ -59,8 +66,8 @@ void me_b(double *X, int *N, char **labels, int *nni, T = NULL; } -void me_o(double *X, int *N, char **labels, int *nni, - int *edge1, int *edge2, double *el, char **tl) +void me_o(double *X, int *N, int *labels, int *nni, + int *edge1, int *edge2, double *el) { double **D, **A; set *species, *slooper; @@ -85,11 +92,11 @@ void me_o(double *X, int *N, char **labels, int *nni, } makeOLSAveragesTable(T,D,A); // Compute NNI - if (*nni == 1) + if (*nni) NNI(T,A,&nniCount,D,n); assignOLSWeights(T,A); - tree2phylo(T, edge1, edge2, el, tl, n); + tree2phylo(T, edge1, edge2, el, labels, n); freeMatrix(D,n); freeMatrix(A,2*n - 2); @@ -98,11 +105,11 @@ void me_o(double *X, int *N, char **labels, int *nni, T = NULL; } -/************************************************************************* +/* - MATRIX FUNCTIONS + -- MATRIX FUNCTIONS -- -*************************************************************************/ +*/ double **initDoubleMatrix(int d) { @@ -118,9 +125,10 @@ double **initDoubleMatrix(int d) return(A); } -double **loadMatrix (double *X, char **labels, int n, set *S) +//double **loadMatrix (double *X, char **labels, int n, set *S) +double **loadMatrix (double *X, int *labels, int n, set *S) { - char nextString[MAX_LABEL_LENGTH]; +// char nextString[MAX_LABEL_LENGTH]; node *v; double **table; int i, j, a, b; @@ -131,9 +139,10 @@ double **loadMatrix (double *X, char **labels, int n, set *S) for(i=0; iindex2 = i; S = addToSet(v,S); for (j=i; jlabel,label,NODE_LABEL_LENGTH); +// strncpy(newNode->label,label,NODE_LABEL_LENGTH); + newNode->label = label; newNode->index = index; newNode->index2 = -1; newNode->parentEdge = parentEdge; @@ -267,8 +279,7 @@ tree *detrifurcate(tree *T) return(T); if (NULL != v->parentEdge) { - Rprintf ("Error: root %s is poorly rooted.\n",v->label); - exit(0); + error("root %d is poorly rooted.", v->label); } for(e = v->middleEdge, v->middleEdge = NULL; NULL != e; e = f ) { @@ -297,7 +308,8 @@ void compareSets(tree *T, set *S) for(X = S; NULL != X; X = X->secondNode) { w = X->firstNode; - if (0 == strcmp(v->label,w->label)) +// if (0 == strcmp(v->label,w->label)) + if (v->label == w->label) { v->index2 = w->index2; w->index2 = -1; @@ -310,7 +322,8 @@ void compareSets(tree *T, set *S) for(X = S; NULL != X; X = X->secondNode) { w = X->firstNode; - if (0 == strcmp(v->label,w->label)) +// if (0 == strcmp(v->label,w->label)) + if (v->label == w->label) { v->index2 = w->index2; w->index2 = -1; @@ -319,8 +332,7 @@ void compareSets(tree *T, set *S) } if (-1 == v->index2) { - Rprintf("Error leaf %s in tree not in distance matrix.\n",v->label); - exit(0); + error("leaf %d in tree not in distance matrix.", v->label); } e = depthFirstTraverse(T,NULL); while (NULL != e) @@ -328,16 +340,14 @@ void compareSets(tree *T, set *S) v = e->head; if ((leaf(v)) && (-1 == v->index2)) { - Rprintf("Error leaf %s in tree not in distance matrix.\n",v->label); - exit(0); + error("leaf %d in tree not in distance matrix.", v->label); } e = depthFirstTraverse(T,e); } for(X = S; NULL != X; X = X->secondNode) if (X->firstNode->index2 > -1) { - Rprintf("Error node %s in matrix but not a leaf in tree.\n",X->firstNode->label); - exit(0); + error("node %d in matrix but not a leaf in tree.", X->firstNode->label); } return; }