uint64 rank(Perm p) { Perm p2; copyPerm(p2, p); Perm r; invertPerm(p2, r); return rankRecur(PERM_LEN, p2, r); }
bool SpidirParams::order(SpeciesTree *stree) { if (stree->nnodes != nsnodes) { printError("wrong number of parameters: %d %d\n", stree->nnodes, nsnodes); return false; } ExtendArray<Node*> nodeorder(0, stree->nnodes); getTreePreOrder(stree, &nodeorder); // make interior node names ExtendArray<int> inodes(stree->nnodes); int inodename = 1; for (int i=0; i<stree->nnodes; i++) { Node *node = nodeorder[i]; if (node->isLeaf()) { inodes[node->name] = -1; } else { inodes[node->name] = inodename++; } } // loop through preordered nodes to construct permutation ExtendArray<int> invperm(0, stree->nnodes); for (int j=0; j<nsnodes; j++) { if (invperm.size() != j) { printError("unable to match '%s' to the species tree", names[j].c_str()); return false; } // try to parse node id as an int int id; bool isint = (sscanf(names[j].c_str(), "%d", &id) == 1); for (int i=0; i<stree->nnodes; i++) { if (stree->nodes[i]->isLeaf()) { // if leaf, check if names match if (names[j] == stree->nodes[i]->longname) { invperm.append(i); break; } } else { if (isint && id == inodes[i]) { invperm.append(i); break; } } } } // apply permutation ExtendArray<int> perm(stree->nnodes); invertPerm(invperm, perm, nsnodes); permute(names, perm, nsnodes); permute(sp_alpha, perm, nsnodes); permute(sp_beta, perm, nsnodes); return true; }