@@ -222,17 +222,15 @@ void reroot_tree(MAT::Tree* T, const std::string& rnid, const std::string& input
222222 // The new root will not be a leaf when we are done, but keep track of whether it started
223223 // as a leaf.
224224 bool new_root_was_leaf = (norder[0 ]->children .size () == 0 );
225+ fprintf (stderr, " Moving root to node %s over a distance of %ld connections.\n " , rnid.c_str (), norder.size ()-1 );
226+ std::vector<MAT ::Mutation> ref_changes;
227+ // If the current root node has mutations, then move them to the ref_changes list.
225228 if (T->root ->mutations .size () != 0 ) {
226- // The way mutations are handled below assumes that the root and reference are synonymous,
227- // and as we change the rooting of the tree, we change the mutations to reflect that the
228- // reference is changing as well. In order to preserve the original reference in the case
229- // that the root differs from it, we would have to do something else with mutations to keep
230- // things consistent. I'm not going to implement that until & unless there's a need for it.
231- fprintf (stderr, " ERROR: Root node has mutations; support for maintaining existing reference has not been implemented. Exiting\n " );
232- exit (1 );
229+ for (auto m: T->root ->mutations ) {
230+ add_ref_change (ref_changes, m);
231+ }
232+ T->root ->mutations .clear ();
233233 }
234- fprintf (stderr, " Moving root to node %s over a distance of %ld connections.\n " , rnid.c_str (), norder.size ());
235- std::vector<MAT ::Mutation> ref_changes;
236234 std::reverse (norder.begin (), norder.end ()); // reverse so the root is first.
237235 for (size_t i = 0 ; i < norder.size () - 1 ; i++) {
238236
0 commit comments