Beispiel #1
0
// 获取二叉树中叶子结点的个数 
int GetLeafCount(pBTNode pRoot)
{
	if (NULL == pRoot) {
		return 0;
	}
	if (NULL == pRoot->_pLeft && NULL == pRoot->_pRight) {
		return 1;
	}
	return GetLeafCount(pRoot->_pLeft) + GetLeafCount(pRoot->_pRight);
}
Beispiel #2
0
/**
 *
 * @brief
 *
 * @param[out] tree
 * created upgma tree. will be allocated here. use FreeMuscleTree()
 * to free
 * @param[in] mseq
 * @param[in] ftree
 *
 * @return non-zero on error
 *
 */    
int
GuideTreeFromFile(tree_t **tree, mseq_t *mseq, char *ftree)
{
    int iNodeCount;
    int iNodeIndex;
    
    (*tree) = (tree_t *) CKMALLOC(1 * sizeof(tree_t));
    if (MuscleTreeFromFile((*tree), ftree)!=0) {
        Log(&rLog, LOG_ERROR, "%s", "MuscleTreeFromFile failed");
        return -1;
    }

    /* Make sure tree is rooted */
    if (!IsRooted((*tree))) {
        Log(&rLog, LOG_ERROR, "User tree must be rooted");
        return -1;
    }
    
    if ((int)GetLeafCount((*tree)) != mseq->nseqs) {
        Log(&rLog, LOG_ERROR, "User tree does not match input sequences");
        return -1;
    }

    /* compare tree labels and sequence names and set leaf-ids */
    iNodeCount = GetNodeCount((*tree));
    for (iNodeIndex = 0; iNodeIndex < iNodeCount; ++iNodeIndex) {
        char *LeafName;
        int iSeqIndex;
        
        if (!IsLeaf(iNodeIndex, (*tree)))
            continue;
        LeafName = GetLeafName(iNodeIndex, (*tree));

        if ((iSeqIndex=FindSeqName(LeafName, mseq))==-1) {
            Log(&rLog, LOG_ERROR, "Label '%s' in tree could not be found in sequence names", LeafName);
            return -1;
        }
        
        SetLeafId((*tree), iNodeIndex, iSeqIndex);
    }

    if (rLog.iLogLevelEnabled <= LOG_DEBUG) {
        Log(&rLog, LOG_DEBUG, "tree logging...");
        LogTree((*tree),  LogGetFP(&rLog, LOG_DEBUG));
    }
    
    return 0;
}