File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -129,13 +129,20 @@ def lowest_common_ancestor(self, *tax_ids):
129
129
return reduce (self .lowest_common_ancestor_double , tax_ids )
130
130
131
131
def lowest_common_ancestor_double (self , tax_id_1 , tax_id_2 ):
132
- parent_gen_1 = networkx .dfs_postorder_nodes (self .tax_graph , tax_id_1 )
133
- parent_gen_2 = networkx .dfs_postorder_nodes (self .tax_graph , tax_id_2 )
134
- parent_id = None
135
- for ptax_id_1 , ptax_id_2 in itertools .izip (parent_gen_1 , parent_gen_2 ):
136
- if ptax_id_1 != ptax_id_2 :
137
- break
138
- parent_id = ptax_id_1
132
+ parent_gen_1 = networkx .dfs_preorder_nodes (self .tax_graph , tax_id_1 )
133
+ parent_gen_2 = networkx .dfs_preorder_nodes (self .tax_graph , tax_id_2 )
134
+ parent_tax_ids1 = set ()
135
+ parent_tax_ids2 = set ()
136
+ for ptax_id_1 , ptax_id_2 in itertools .izip_longest (parent_gen_1 , parent_gen_2 ,
137
+ fillvalue = '1' ):
138
+ parent_tax_ids1 .add (ptax_id_1 )
139
+ if ptax_id_2 in parent_tax_ids1 :
140
+ return ptax_id_2
141
+ parent_tax_ids2 .add (ptax_id_2 )
142
+ if ptax_id_1 in parent_tax_ids2 :
143
+ return ptax_id_1
139
144
140
145
# the tax_ids don't share a common parent; return None
141
- return parent_id
146
+ # this should basically never happen with our current taxonomy because everything shares
147
+ # '1' as a parent
148
+ return None
You can’t perform that action at this time.
0 commit comments