def get_new_otu_id(old_otu_id, tree, dissim):
 create_tip_index(tree)
 cache_tip_names(tree)
 node = tree._tip_index[old_otu_id]
 distance_up_tree = 0
 while ((not node.isRoot()) and ((distance_up_tree + node.Length) < dissim)):
  distance_up_tree += node.Length
  node = node.Parent
 if node.isTip():
  return node.Name
 else:
  return choice(node._tip_names)

def get_new_otu_id ( old_otu_id , tree , dissim ) : create_tip_index ( tree ) cache_tip_names ( tree ) node = tree . _tip_index [ old_otu_id ] distance_up_tree = 0 while ( ( not node . isRoot ( ) ) and ( ( distance_up_tree + node . Length ) < dissim ) ) : distance_up_tree += node . Length node = node . Parent if node . isTip ( ) : return node . Name else : return choice ( node . _tip_names )
simulates an otu switching to related one input a tipname .