コード例 #1
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//------------------------------------------------------------------------------
// Fill in weight, degree, etc.
void Tree::buildtraverse (NodePtr p)
{
	if (p)
	{
		p->SetWeight (0);
		/*p->SetModelCategory(vector<double>(1,1.0)); //added by BCO
		p->SetStateOrder(vector<int>(1,0)); //Added by BCO
		p->SetStateTimes(vector<double>(1,0.0)); //Added by BCO*/
		p->SetDegree (0);
		buildtraverse (p->GetChild ());
		buildtraverse (p->GetSibling ());
		if (p->IsLeaf())
		{
			Leaves++;
			p->SetWeight (1);
			/*p->SetModelCategory(vector<double>(1,1.0)); //Added by BCO
			p->SetStateOrder(vector<int>(1,0)); //Added by BCO
			p->SetStateTimes(vector<double>(1,0.0)); //Added by BCO*/
			
		}
		else
		{
			Internals++;
		}
		if (p != Root)
		{
			p->GetAnc()->AddWeight (p->GetWeight());
			p->GetAnc()->IncrementDegree();
		}
	}
}
コード例 #2
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//------------------------------------------------------------------------------
// Add Node below Below. Doesn't update any clusters, weights, etc.
void Tree::AddNodeBelow (NodePtr Node, NodePtr Below)
{
	NodePtr Ancestor = NewNode ();
	Ancestor->SetChild (Node);
	Node->SetAnc (Ancestor);
	NodePtr q = Below->GetAnc ();
	Internals++;
	if (Node->IsLeaf())
		Leaves++;
	if (q == NULL || Below == q->GetChild())
	{
		Node->SetSibling (Below);
		Ancestor->SetAnc (q);
		Ancestor->SetSibling (Below->GetSibling());
		Below->SetSibling (NULL);
		Below->SetAnc (Ancestor);
		if (q == NULL)
			Root = Ancestor;
		else
			q->SetChild (Ancestor);
	}
	else
	{
		// Get left sibling of Below
		NodePtr r = Below->LeftSiblingOf();
		while (Below != r->GetSibling())
			r = r->GetSibling();
		Node->SetSibling (Below);
		Ancestor->SetAnc (q);
		Ancestor->SetSibling (Below->GetSibling());
		Below->SetSibling (NULL);
		Below->SetAnc (Ancestor);
		r->SetSibling (Ancestor);
	}
}
コード例 #3
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//------------------------------------------------------------------------------
void Tree::makeNodeList (NodePtr p)
{
	if (p)
	{
		makeNodeList (p->GetChild ());
		makeNodeList (p->GetSibling ());
		if (p->IsLeaf())
		{
			int leafnumberposition=p->GetLeafNumber()-1;//modified by BCO
			string plabel=p->GetLabel(); //modified by BCO
			LeafList[plabel] = leafnumberposition; //modified by BCO
			assert((Leaves+Internals)>leafnumberposition);
			Nodes[leafnumberposition] = p; //modified by BCO
			p->SetIndex (leafnumberposition); //modified by BCO
		}
		else
		{
			Nodes[count] = p;
			p->SetIndex (count);
			count++;
		}
		if (p != Root)
		{
		}
	}
}
コード例 #4
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//------------------------------------------------------------------------------
void Tree::drawAsTextTraverse (NodePtr p)
{
	if (p)
	{
		drawAsTextTraverse (p->GetChild ());
		if (p->IsLeaf ())
			drawPendantEdge (p);
		if (p->GetSibling ())
			drawInteriorEdge (p);
		drawAsTextTraverse (p->GetSibling ());
	}
}
コード例 #5
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//Added by BCO
//------------------------------------------------------------------------------
void Tree::traversenoquote (NodePtr p)
{
	
	if (p)
	{
		if (p->IsLeaf())
		{
			for (int i=0; i<(NEXUSString (p->GetLabel())).length(); i++) {
				if ((NEXUSString (p->GetLabel()))[i]!= '\'') {
					*treeStream <<(NEXUSString (p->GetLabel()))[i];
				}
			}
			//*treeStream<<NEXUSString (p->GetLabel());
			if (EdgeLengths)
			{
				*treeStream << ':' << p->GetEdgeLength ();
			}
		}
		else
		{
			*treeStream << "(";
		}
		
		traversenoquote (p->GetChild());
		if (p->GetSibling())
		{
			*treeStream << ",";
		}
		else
		{
			if (p != Root)
			{
				*treeStream << ")";
				// 29/3/96
				if ((p->GetAnc()->GetLabel() != "") && InternalLabels)
				{
					*treeStream <<  NEXUSString (p->GetAnc()->GetLabel ()) ; //here's the change from traverse
				}
				if (EdgeLengths && (p->GetAnc () != Root))
				{
					*treeStream << ':' << p->GetAnc()->GetEdgeLength ();
				}
			}
		}
		traversenoquote (p->GetSibling());
	}
	
}
コード例 #6
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
void Tree::drawLine (NodePtr p, bool isChild)
{
	*treeStream << Line.c_str();
	
	if (p->IsLeaf())
    {
		* treeStream<< " " << p->GetLabel () <<endl;
    }
    else
    {
        // Draw internal label, if present
        string s = p->GetLabel();
        if (s != "" && isChild)
            *treeStream  << p->GetLabel();
		
	 	*treeStream  << endl;
    }
}
コード例 #7
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
//------------------------------------------------------------------------------
void Tree::traverse (NodePtr p)
{
	
	if (p)
	{
		if (p->IsLeaf())
		{
			*treeStream << NEXUSString (p->GetLabel());
			
			if (EdgeLengths)
			{
				*treeStream << ':' << p->GetEdgeLength ();
			}
		}
		else
		{
			*treeStream << "(";
		}
		
		traverse (p->GetChild());
		if (p->GetSibling())
		{
			*treeStream << ",";
		}
		else
		{
			if (p != Root)
			{
				*treeStream << ")";
				// 29/3/96
				if ((p->GetAnc()->GetLabel() != "") && InternalLabels)
				{
					*treeStream << '\'' << NEXUSString (p->GetAnc()->GetLabel ()) << '\'';
				}
				if (EdgeLengths && (p->GetAnc () != Root))
				{
					*treeStream << ':' << p->GetAnc()->GetEdgeLength ();
				}
			}
		}
		traverse (p->GetSibling());
	}
	
}
コード例 #8
0
ファイル: TreeLib.cpp プロジェクト: thanhleviet/brownie
NodePtr Tree::RemoveNode (NodePtr Node)
{
	NodePtr result = NULL;
	
	if (Node == Root)
	{
		if (Leaves == 1)
		{
			Root = NULL;
			Node->SetAnc (NULL);
			Leaves = Internals = 0;
		}					
		return result;
	}
	
	NodePtr p;
	NodePtr Ancestor = Node->GetAnc();
	
	if (Ancestor->GetDegree() == 2)
	{
		// ancestor is binary, so remove node and its ancestor
		if (Node->IsTheChild ())
			p = Node->GetSibling();
		else
			p = Ancestor->GetChild();
		NodePtr q = Ancestor->GetAnc();
		p->SetAnc (q);
		if (q != NULL)
		{
			if (Ancestor->IsTheChild())
				q->SetChild (p);
			else
			{
				NodePtr r = Ancestor->LeftSiblingOf ();
				r->SetSibling (p);
			}
			p->SetSibling (Ancestor->GetSibling());
			result = p;
		}
		else
		{
			// Ancestor is the root
			Root = p;
			p->SetSibling (NULL);
			result = p;
		}
		delete Ancestor;
		Internals--;
		if (Node->IsLeaf())
			Leaves--;
		Node->SetAnc (NULL);
		Node->SetSibling (NULL);
	}
	else
	{
		// polytomy, just remove node
		NodePtr q;
		if (Node->IsTheChild())
		{
			Ancestor->SetChild (Node->GetSibling());
			q = Node->GetSibling ();
		}
		else
		{
			q = Node->LeftSiblingOf ();
			q->SetSibling (Node->GetSibling ());
		}
		Node->SetSibling (NULL);
		Node->SetAnc (NULL);
		if (Node->IsLeaf())
			Leaves--;
		Ancestor->SetDegree (Ancestor->GetDegree() - 1);
		result = q;
	}
}