def consensus_tree():
    trees = []
    add_trees = True
    while add_trees:
        try:
            phy_tree = PhyTree()
            path = input("Tree's path: ")
            if os.path.isdir(path):
                files = os.listdir(path)
                for f in files:
                    p = PhyTree()
                    p.load_file(path + f)
                    trees.append(p)
                break
            else:
                phy_tree.load_file(path)
        except ValueError as e:
            print(e)
            continue
        trees.append(phy_tree)
        add_trees = not ask_if_finished()
    print("Threshold:")
    threshold = get_float()

    result = consensus(trees, threshold)
    path = input("Save as: ")
    result.save(path)
def rf_distance_cmd():
    print("First tree:")
    left = get_file_path()
    print("Second tree:")
    right = get_file_path()
    left_tree = PhyTree()
    left_tree.load_file(left)
    right_tree = PhyTree()
    right_tree.load_file(right)
    distance = rf_distance(left_tree, right_tree)
    print(f"Distance: {distance}")
def cut(file_name: str):
    if not os.path.isfile(file_name):
        print("Given file has to exist.")
        return
    tree = PhyTree()
    tree.load_file(file_name)
    wanted_leaves = set()
    choose_leaves = True
    while choose_leaves:
        print(f"Chosen leaves: {wanted_leaves}")
        leaf = input("Add leaf: ")
        if leaf not in tree.leaves:
            print(f"{leaf} was not among the tree's leaves")
            continue
        if leaf in wanted_leaves:
            print(f"{leaf} is already among wanted leaves")
            continue
        wanted_leaves.add(leaf)
        choose_leaves = not ask_if_finished()
    cutter = TreeCutter()
    cutter.attach_tree(tree)
    cutter.choose_leaves(wanted_leaves)
    new_tree = cutter.cut()
    new_tree.save(file_name)
Exemplo n.º 4
0
def update(file_name: str):
    tree = PhyTree()
    tree.load_file(file_name)
    modify(file_name, tree)