Exemplo n.º 1
0
//Returns the node at the root of the subtree (if one exists which is all of the children of the node are in the same family, assuming the the family name is is the first characters in the name of the leaf nodes 
Phylogeny_Node* SisterFinder::all_match(Phylogeny_Node* n,string s){
    if (n->leaf) {
        if (n->name.substr(0,s.length()) == s) {
            return n;
        } else {
            return NULL;
        }
    }else{
        Phylogeny_Node* l = all_match(n->left_child, s);
        Phylogeny_Node* r = all_match(n->right_child, s);
        if (l == NULL) {
            return r;
        }else if(r == NULL){
            return l;
        }else{
            if(l==n->left_child && r==n->right_child) return n;
            else{ 
                //reroot at the parent of the one thats not the child
                Phylogeny_Node* newRoot;
                if (l != n->left_child) {
                    newRoot = n->left_child;
                    n->left_child = newRoot->left_child;
                    newRoot->parent = n->parent;
                    n->parent = newRoot;
                    newRoot->left_child = n;
                }else{
                    newRoot = n->right_child;
                    n->right_child = newRoot->right_child;
                    newRoot->parent = n->parent;
                    n->parent = newRoot;
                    newRoot->right_child = n;
                }
                double swap_b = newRoot->bootstrap;
                double swap_l = newRoot->branch_length;
                newRoot->bootstrap = n->bootstrap;
                newRoot->branch_length = n->branch_length;
                n->bootstrap = swap_b ;
                n->branch_length = swap_l;
                
                Phylogeny_Node* swap = newRoot->left_child;
                newRoot->left_child = newRoot->right_child;
                newRoot->right_child = swap;
                if (newRoot->parent == NULL) {
                    phylo->root = newRoot;
                }else{
                    if(n==newRoot->parent->left_child){
                        newRoot->parent->left_child = newRoot;
                    }else{
                        newRoot->parent->right_child = newRoot;
                    }
                }
                
                Phylogeny_Node* p= all_match(newRoot, s);
                return p;
            }
        }
    }
    return NULL;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
	both_null();
	pattern_null();
	text_null();
	pattern_larger_than_text();
	both_empty();
	empty_pattern();
	empty_text();
	all_match();
	no_match();
	non_overlapping_match();
	overlapping_match();
}
Exemplo n.º 3
0
//If the tree has a consistant family name (defined as substing before "-" character) return this family name, otherwise return an empty string.
string SisterFinder::print_name_if_same(Phylogeny_Node* n){
    if (n->leaf) {
        string p = n->print();
        return p.substr(0,p.find_first_of("-"));
    }
    Phylogeny_Node* l = n->left_child;
    while (!l->leaf) {
        l = l->left_child;
    }
    string p = l->print();
    string name = p.substr(0,p.find_first_of("-"));
    Phylogeny_Node* a = all_match(n, name);
    if (a==n) {
        return name;
    }
    return "";
}
Exemplo n.º 4
0
//Find the subtree which is consistant with the names of the family given (or prefix in the general case) and find the sisters and put them in the sister names array
SisterFinder::SisterFinder(Phylogeny* p, string s){
    phylo = p;
    target = all_match(p->root,s);
    sister_names_count = 0;
    get_sisters();
}