def are_disjoint(tnu1, tnu2): assert table.is_record(tnu1) assert table.is_record(tnu2) if tnu1 == forest_tnu: return False if tnu2 == forest_tnu: return False if tnu1 == tnu2: return False (tnu1, tnu2) = find_peers(tnu1, tnu2) return tnu1 != tnu2
def mrca(tnu1, tnu2): while True: if tnu1 == forest_tnu: return forest_tnu if tnu2 == forest_tnu: return forest_tnu assert table.is_record(tnu1) assert table.is_record(tnu2) # to_accepted ?? if tnu1 == tnu2: return tnu1 (tnu1, tnu2) = find_peers(tnu1, tnu2) assert get_mutex(tnu1) == get_mutex(tnu2)
def how_related(tnu1, tnu2): if tnu1 == tnu2: # If in differently checklists, this could be an incompatibility return rel.eq assert table.is_record(tnu1) assert table.is_record(tnu2) assert get_checklist(tnu1) == get_checklist(tnu2) (peer1, peer2) = find_peers(tnu1, tnu2) if peer1 == peer2: if peer1 == tnu1: return rel.gt elif peer2 == tnu2: return rel.lt return rel.disjoint
def to_accepted(tnu): if not table.is_record(tnu): print ("Not a record: %s" % tnu) assert False probe = get_accepted(tnu) if probe: return probe else: return tnu
def find_peers(tnu_1, tnu_2): assert table.is_record(tnu_1) assert table.is_record(tnu_2) tnu1 = to_accepted(tnu_1) tnu2 = to_accepted(tnu_2) if tnu1 == forest_tnu or tnu2 == forest_tnu: return (forest_tnu, forest_tnu) assert get_checklist(tnu1) == get_checklist(tnu2) #? mutex1 = get_mutex(tnu1) mutex2 = get_mutex(tnu2) if mutex1 == mutex2: if debug: print ("# Kludge %s %s" % (get_unique(tnu1), get_unique(tnu2))) tnu1 = get_parent(tnu1) mutex1 = get_mutex(tnu1) #print("# Mutexes are %s %s" % (mutex1, mutex2)) # Mutex of the forest is 0. Going in 0-ward direction. while mutex1 != mutex2: assert mutex1 >= 0 assert mutex2 >= 0 if mutex1 > mutex2: # If p2 is closer to the root, try going rootward from p1 if tnu1 == forest_tnu: return (forest_tnu, forest_tnu) tnu1 = get_parent(tnu1) mutex1 = get_mutex(tnu1) else: # mutex1 < mutex2: # If p1 is closer to the root, try going rootward from p2 if tnu2 == forest_tnu: return (forest_tnu, forest_tnu) tnu2 = get_parent(tnu2) mutex2 = get_mutex(tnu2) if debug: print("# find_peers(%s, %s) = %s, %s" % \ (get_unique(tnu_1), get_unique(tnu_2), get_unique(tnu1), get_unique(tnu2))) return (tnu1, tnu2)
def get_spaceless(tnu): if tnu == None: return "none" if tnu == forest_tnu: return "forest" assert table.is_record(tnu) checklist = get_checklist(tnu) name = get_name(tnu) tnus_with_this_name = \ get_nodes_with_value(checklist, canonical_name, name) if len(tnus_with_this_name) > 1: # TBD: what if id is None? Use id of accepted? name = name + "#" + get_taxon_id(tnu) if not is_accepted(tnu): name = "?" + name # Not sure about this?? # name = name.replace(" ", "_") return name