1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/**
* PLL (version 1.0.0) a software library for phylogenetic inference
* Copyright (C) 2013 Tomas Flouri and Alexandros Stamatakis
*
* Derived from
* RAxML-HPC, a program for sequential and parallel estimation of phylogenetic
* trees by Alexandros Stamatakis
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* For any other enquiries send an Email to Tomas Flouri
* Tomas.Flouri@h-its.org
*
* When publishing work that uses PLL please cite PLL
*
* @file trash.c
*/
#include "mem_alloc.h"
#ifndef WIN32
#include <sys/times.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include "pll.h"
#include "pllInternal.h"
/** @brief Reorder nodes in PLL tree
Re-order the internal nodes of the tree of PLL instance \a tr in a preorder
traversal such that they start from \a p
@param tr
PLL instance
@param np
Array of node pointers
@param p
Node from where the preorder traversal should start
@param count
@todo
why not insert a break in the for loop when the node is found?
*/
static void reorderNodes(pllInstance *tr, nodeptr *np, nodeptr p, int *count)
{
int i, found = 0;
if(isTip(p->number, tr->mxtips))
return;
else
{
for(i = tr->mxtips + 1; (i <= (tr->mxtips + tr->mxtips - 1)) && (found == 0); i++)
{
if (p == np[i] || p == np[i]->next || p == np[i]->next->next)
{
if(p == np[i])
tr->nodep[*count + tr->mxtips + 1] = np[i];
else
{
if(p == np[i]->next)
tr->nodep[*count + tr->mxtips + 1] = np[i]->next;
else
tr->nodep[*count + tr->mxtips + 1] = np[i]->next->next;
}
found = 1;
*count = *count + 1;
}
}
assert(found != 0);
reorderNodes(tr, np, p->next->back, count);
reorderNodes(tr, np, p->next->next->back, count);
}
}
void nodeRectifier(pllInstance *tr)
{
nodeptr *np = (nodeptr *)rax_malloc(2 * tr->mxtips * sizeof(nodeptr));
int i;
int count = 0;
tr->start = tr->nodep[1];
tr->rooted = PLL_FALSE;
/* TODO why is tr->rooted set to PLL_FALSE here ?*/
for(i = tr->mxtips + 1; i <= (tr->mxtips + tr->mxtips - 1); i++)
np[i] = tr->nodep[i];
reorderNodes(tr, np, tr->start->back, &count);
rax_free(np);
}
nodeptr findAnyTip(nodeptr p, int numsp)
{
return isTip(p->number, numsp) ? p : findAnyTip(p->next->back, numsp);
}
|