Esempio n. 1
0
/* clone a node, linking in new mafTreeNodeCompLink object */
static stTree *cloneNode(stTree *srcNode, struct malnCompCompMap *srcDestCompMap) {
    stTree *destNode = stTree_cloneNode(srcNode);
    struct mafTreeNodeCompLink *srcNcLink = getNodeCompLink(srcNode);
    struct malnComp *destComp = malnCompCompMap_get(srcDestCompMap, srcNcLink->comp);
    mafTreeNodeCompLink_construct(-1, destNode, destComp);
    return destNode;
}
Esempio n. 2
0
// clone this node, make its supertree a child, and clone all children
// other than oldNode, leaving this node as a child of nodeToAddTo
static void tree_cloneFlippedTree(stTree *node, stTree *oldNode,
                                  stTree *nodeToAddTo,
                                  double branchLength) {
    if(stTree_getParent(node) != NULL) {
        // This node isn't the root
        stTree *clonedNode = stTree_cloneNode(node);
        stTree_setParent(clonedNode, nodeToAddTo);
        stTree_setBranchLength(clonedNode, branchLength);
        // Clone its children (other than oldNode) and their subtrees
        for(int64_t i = 0; i < stTree_getChildNumber(node); i++) {
            stTree *child = stTree_getChild(node, i);
            if(child != oldNode) {
                stTree *clonedChild = stTree_clone(child);
                stTree_setParent(clonedChild, clonedNode);
            }
        }
        
        // Recurse on the parent of this node.
        tree_cloneFlippedTree(stTree_getParent(node), node,
                              clonedNode, stTree_getBranchLength(node));
    } else {
        // We have to treat the root specially, because we're going to
        // eliminate it. Just add all the other children of the root
        // as children of nodeToAddTo.
        for(int64_t i = 0; i < stTree_getChildNumber(node); i++) {
            stTree *child = stTree_getChild(node, i);
            if(child != oldNode) {
                stTree *clonedChild = stTree_clone(child);
                stTree_setParent(clonedChild, nodeToAddTo);
                stTree_setBranchLength(clonedChild, stTree_getBranchLength(child) + branchLength);
            }
        }
    }
}
Esempio n. 3
0
/* recursively clone a tree */
static stTree *tree_clonetree(stTree *node, stTree *parent2) {
    stTree *node2 = stTree_cloneNode(node);
    stTree_setParent(node2, parent2);
    for (int i = 0; i < stTree_getChildNumber(node); i++) {
        tree_clonetree(stTree_getChild(node, i), node2);
    }
    return node2;
}