@@ -57,8 +57,9 @@ def get_ancestor(id1, id2, ncbi):
57
57
Return dictionary {ancestor_id: ancestor_rank}
58
58
"""
59
59
tree = ncbi .get_topology ([id1 , id2 ], intermediate_nodes = False )
60
- ancestor = tree .get_common_ancestor (id1 , id2 ).name
61
- return (ncbi .get_rank ([ancestor ]))
60
+ ancestor_name = tree .common_ancestor (id1 , id2 )
61
+ ancestor_id = int (ancestor_name .name )
62
+ return (ncbi .get_rank ([ancestor_id ]))
62
63
63
64
64
65
def check_common_ancestor (ref_id , ancestor , minDist , maxDist , ncbi ):
@@ -68,6 +69,7 @@ def check_common_ancestor(ref_id, ancestor, minDist, maxDist, ncbi):
68
69
"""
69
70
ref_lineage = ncbi .get_lineage (ref_id )
70
71
(min_ref , max_ref ) = get_rank_range (ref_lineage , minDist , maxDist , ncbi )
72
+ ancestor = int (ancestor )
71
73
if not ancestor in ref_lineage :
72
74
return (0 )
73
75
ancestor_index = len (ref_lineage ) - ref_lineage .index (ancestor ) - 1
@@ -78,7 +80,7 @@ def check_common_ancestor(ref_id, ancestor, minDist, maxDist, ncbi):
78
80
79
81
def remove_clade (tree , node_id ):
80
82
""" Remove a clade from a tree """
81
- removed_clade = tree .search_nodes (name = str (node_id ))[0 ]
83
+ removed_clade = list ( tree .search_nodes (name = str (node_id ) ))[0 ]
82
84
removed_node = removed_clade .detach ()
83
85
return (tree )
84
86
@@ -96,12 +98,12 @@ def get_leaves_dict(spec_lineage, tree, min_index, max_index):
96
98
for i in range (len (spec_lineage )):
97
99
if i >= min_index and i <= max_index :
98
100
curr_node = spec_lineage [i ]
99
- node = tree .search_nodes (name = str (curr_node ))
101
+ node = list ( tree .search_nodes (name = str (curr_node ) ))
100
102
if len (node ) > 0 :
101
103
for leaf in node :
102
104
node_dict [spec_lineage [i ]] = []
103
105
for t in leaf .traverse ():
104
- if t .is_leaf () :
106
+ if t .is_leaf :
105
107
if not t .name in already_added :
106
108
already_added .append (t .name )
107
109
node_dict [spec_lineage [i ]].append (t .name )
0 commit comments