File: phyfromclust.cpp

package info (click to toggle)
muscle 3.60-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,384 kB
  • ctags: 2,079
  • sloc: cpp: 26,452; xml: 185; makefile: 101
file content (95 lines) | stat: -rw-r--r-- 2,743 bytes parent folder | download | duplicates (14)
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
#include "muscle.h"
#include "tree.h"
#include "clust.h"

void Tree::InitCache(unsigned uCacheCount)
	{
	m_uCacheCount = uCacheCount;

	m_uNeighbor1 = new unsigned[m_uCacheCount];
	m_uNeighbor2 = new unsigned[m_uCacheCount];
	m_uNeighbor3 = new unsigned[m_uCacheCount];

	m_Ids = new unsigned[m_uCacheCount];

	m_dEdgeLength1 = new double[m_uCacheCount];
	m_dEdgeLength2 = new double[m_uCacheCount];
	m_dEdgeLength3 = new double[m_uCacheCount];
	m_dHeight = new double[m_uCacheCount];

	m_bHasEdgeLength1 = new bool[m_uCacheCount];
	m_bHasEdgeLength2 = new bool[m_uCacheCount];
	m_bHasEdgeLength3 = new bool[m_uCacheCount];
	m_bHasHeight = new bool[m_uCacheCount];

	m_ptrName = new char *[m_uCacheCount];

	for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
		{
		m_uNeighbor1[uNodeIndex] = NULL_NEIGHBOR;
		m_uNeighbor2[uNodeIndex] = NULL_NEIGHBOR;
		m_uNeighbor3[uNodeIndex] = NULL_NEIGHBOR;
		m_bHasEdgeLength1[uNodeIndex] = false;
		m_bHasEdgeLength2[uNodeIndex] = false;
		m_bHasEdgeLength3[uNodeIndex] = false;
		m_bHasHeight[uNodeIndex] = false;
		m_dEdgeLength1[uNodeIndex] = dInsane;
		m_dEdgeLength2[uNodeIndex] = dInsane;
		m_dEdgeLength3[uNodeIndex] = dInsane;
		m_dHeight[uNodeIndex] = dInsane;
		m_ptrName[uNodeIndex] = 0;
		m_Ids[uNodeIndex] = uInsane;
		}
	}

void Tree::FromClust(Clust &C)
	{
	Clear();

	m_uNodeCount = C.GetNodeCount();
	InitCache(m_uNodeCount);

// Cluster is always rooted. An unrooted cluster
// is represented by a pseudo-root, which we fix later.
	m_bRooted = true;
	const unsigned uRoot = C.GetRootNodeIndex();
	m_uRootNodeIndex = uRoot;
	m_uNeighbor1[uRoot] = NULL_NEIGHBOR;
	m_bHasEdgeLength1[uRoot] = false;

	for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
		{
		if (C.IsLeaf(uNodeIndex))
			{
			const char *ptrName = C.GetNodeName(uNodeIndex);
			m_ptrName[uNodeIndex] = strsave(ptrName);
			m_Ids[uNodeIndex] = C.GetNodeId(uNodeIndex);
			continue;
			}

		const unsigned uLeft = C.GetLeftIndex(uNodeIndex);
		const unsigned uRight = C.GetRightIndex(uNodeIndex);

		const double dLeftLength = C.GetLength(uLeft);
		const double dRightLength = C.GetLength(uRight);

		m_uNeighbor2[uNodeIndex] = uLeft;
		m_uNeighbor3[uNodeIndex] = uRight;

		m_dEdgeLength1[uLeft] = dLeftLength;
		m_dEdgeLength1[uRight] = dRightLength;

		m_uNeighbor1[uLeft] = uNodeIndex;
		m_uNeighbor1[uRight] = uNodeIndex;

		m_bHasEdgeLength1[uLeft] = true;
		m_bHasEdgeLength1[uRight] = true;

		m_dEdgeLength2[uNodeIndex] = dLeftLength;
		m_dEdgeLength3[uNodeIndex] = dRightLength;

		m_bHasEdgeLength2[uNodeIndex] = true;
		m_bHasEdgeLength3[uNodeIndex] = true;
		}
	Validate();
	}