Skip to content

Commit

Permalink
Fix bug with merging attr transitions for rec tree
Browse files Browse the repository at this point in the history
  • Loading branch information
binho authored and binho committed Apr 19, 2024
1 parent 73f45fc commit 02bb95f
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/phylojunction/data/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,17 +1157,17 @@ def recur_grabbing_int_nds_to_merge(
# print(int_node_lists_to_merge)

for sublist in int_node_lists_to_merge:
# must be the case b/c of how int_node_lists_to_merge is built
# must be the 1st entry b/c of how int_node_lists_to_merge is built
# (first item is necessarily the youngest, as older
# consecutively pruned internal nodes are appended to end of
# list)
youngest_int_nd_name = sublist[0]
found_child_to_paste_to = False

for leaf_nd in self.tree_reconstructed.leaf_node_iter():
leaf_node_name = leaf_nd.label
for nd2merge_with in self.tree_reconstructed.preorder_node_iter():
nd2merge_with_name = nd2merge_with.label
complete_tr_leaf_nd = \
self.tree.find_node_with_label(leaf_node_name)
self.tree.find_node_with_label(nd2merge_with_name)
complete_tr_leaf_nd_parent_name = \
complete_tr_leaf_nd.parent_node.label

Expand All @@ -1176,7 +1176,13 @@ def recur_grabbing_int_nds_to_merge(
found_child_to_paste_to = True

# debugging
# print(youngest_int_nd_name, "is pasted to", leaf_node_name)
# print(youngest_int_nd_name, "is pasted to", nd2merge_with_name)

# first we check if that node already had its list
# of attribute transitions, because if not, we must
# create one
if nd2merge_with_name not in self.rec_tr_at_dict:
self.rec_tr_at_dict[nd2merge_with_name] = list()

# merge of AttributeTransition's!
for int_nd_name in sublist:
Expand All @@ -1186,13 +1192,27 @@ def recur_grabbing_int_nds_to_merge(
reversed(self.rec_tr_at_dict[int_nd_name])

for at2merge in int_nd_to_merge_at_list:
self.rec_tr_at_dict[leaf_node_name].\
self.rec_tr_at_dict[nd2merge_with_name].\
insert(0, at2merge)

if not found_child_to_paste_to:
exit(("Could not find a reconstructed tree leaf to"
"paste the attribute transitions of pruned"
"internal node" + youngest_int_nd_name))
tr_str = \
self.tree.as_string(
schema="newick",
suppress_internal_taxon_labels=True,
suppress_internal_node_labels=False,
suppress_rooting=True)
print(tr_str)
tr_rec_str = \
self.tree_reconstructed.as_string(
schema="newick",
suppress_internal_taxon_labels=True,
suppress_internal_node_labels=False,
suppress_rooting=True)
print(tr_rec_str)
exit(("Could not find a reconstructed tree leaf to "
"paste the attribute transitions of pruned "
"internal node " + youngest_int_nd_name))

# remove internal nodes that are not in the rec tree
rec_tr_nd_names = \
Expand Down

0 comments on commit 02bb95f

Please sign in to comment.