Esempio n. 1
0
/* clone a node */
stTree *stTree_cloneNode(stTree *node) {
    stTree *node2 = stTree_construct();
    stTree_setBranchLength(node2, stTree_getBranchLength(node));
    stTree_setClientData(node2, stTree_getClientData(node));
    stTree_setLabel(node2, stTree_getLabel(node));
    return node2;
}
Esempio n. 2
0
static stTree *eventTree_getStTree_R(Event *event) {
    stTree *ret = stTree_construct();
    stTree_setLabel(ret, stString_print("%" PRIi64, event_getName(event)));
    stTree_setBranchLength(ret, event_getBranchLength(event));
    for(int64_t i = 0; i < event_getChildNumber(event); i++) {
        Event *child = event_getChild(event, i);
        stTree *childStTree = eventTree_getStTree_R(child);
        stTree_setParent(childStTree, ret);
    }
    return ret;
}
Esempio n. 3
0
// Return a new tree rooted a given distance above the given node.
stTree *stTree_reRoot(stTree *node, double distanceAbove) {
    if(stTree_getParent(node) == NULL) {
        // This node is already the root.
        stTree *newRoot = stTree_clone(node);
        stTree_clearClientData(newRoot, true);
        return newRoot;
    }

    assert(stTree_getBranchLength(node) >= distanceAbove);

    stTree *newRoot = stTree_construct();
    // This node and its children (if any) are fine already.
    stTree *clonedNode = stTree_clone(node);
    stTree_setParent(clonedNode, newRoot);
    stTree_setBranchLength(clonedNode, distanceAbove);
    tree_cloneFlippedTree(stTree_getParent(node), node, newRoot,
                          stTree_getBranchLength(node) - distanceAbove);
    // Having the same client data can be a problem
    stTree_clearClientData(newRoot, true);
    return newRoot;
}
Esempio n. 4
0
static stTree *tree_parseNewickStringP(char **token, char **newickTreeString) {
    stTree *tree = stTree_construct();
    if((*token)[0] == '(') {
        assert(strlen(*token) == 1);
        tree_parseNewickTreeString_getNextToken(token, newickTreeString);
        while(1) {
            stTree_setParent(tree_parseNewickStringP(token, newickTreeString), tree);
            assert(strlen(*token) == 1);
            if((*token)[0] == ',') {
                tree_parseNewickTreeString_getNextToken(token, newickTreeString);
            }
            else {
                break;
            }
        }
        assert((*token)[0] == ')'); //for every opening bracket we must have a close bracket.
        tree_parseNewickTreeString_getNextToken(token, newickTreeString);
    }
    tree_parseNewickString_getLabel(token, newickTreeString, tree);
    tree_parseNewickString_getBranchLength(token, newickTreeString, tree);
    assert(**token == ',' || **token == ';' || **token == ')'); //these are the correct termination criteria
    return tree;
}
Esempio n. 5
0
/* construct an ETree node from a malnComp */
static stTree *malnCompToETreeNode(struct malnComp *comp) {
    stTree *eTree = stTree_construct();
    stTree_setLabel(eTree, comp->seq->orgSeqName);
    return eTree;
}