Beispiel #1
0
        def make_class_tree(
            master_tree,
            permutation_extent,
            method,
            with_check=True,
            checklist=[],
            ):
            """
            Function returns a tree object derived from a master tree,
            but with some permutation applied. The type of permutation
            is defined by `method`, one of 'nni', 'spr' and 'coal'
            If with_check is True, the generated tree is checked against
            a checklist of other trees on the same species, and permutations
            are applied until the new tree has a unique topology. This is 
            only implemented for nni and spr.
            """

            if num_permutations == 0:
                return master_tree

            new_tree = Tree(master_tree.newick)

            if method == 'nni':
                if with_check:
                    while not self.check_diff_top(new_tree, checklist):
                        new_tree = Tree(master_tree.newick)
                        for i in range(permutation_extent):
                            new_tree = new_tree.nni()
                else:
                    for i in range(num_permutations):
                        new_tree = new_tree.nni()
            elif method == 'spr':
                if with_check:
                    while not self.check_diff_top(new_tree, checklist):
                        new_tree = Tree(master_tree.newick)
                        for i in range(permutation_extent):
                            new_tree = \
                                new_tree.spr(disallow_sibling_SPRs=True)
                else:
                    for i in range(num_permutations):
                        new_tree = new_tree.spr()
            elif method == 'coal':
                new_tree = \
                    master_tree.get_constrained_gene_tree(scale_to=permutation_extent)
            return new_tree
Beispiel #2
0
        def make_class_tree(
            master_tree,
            permutation_extent,
            method,
            with_check=True,
            checklist=[],
        ):
            """
            Function returns a tree object derived from a master tree,
            but with some permutation applied. The type of permutation
            is defined by `method`, one of 'nni', 'spr' and 'coal'
            If with_check is True, the generated tree is checked against
            a checklist of other trees on the same species, and permutations
            are applied until the new tree has a unique topology. This is 
            only implemented for nni and spr.
            """

            if num_permutations == 0:
                return master_tree

            new_tree = Tree(master_tree.newick)

            if method == 'nni':
                if with_check:
                    while not self.check_diff_top(new_tree, checklist):
                        new_tree = Tree(master_tree.newick)
                        for i in range(permutation_extent):
                            new_tree = new_tree.nni()
                else:
                    for i in range(num_permutations):
                        new_tree = new_tree.nni()
            elif method == 'spr':
                if with_check:
                    while not self.check_diff_top(new_tree, checklist):
                        new_tree = Tree(master_tree.newick)
                        for i in range(permutation_extent):
                            new_tree = \
                                new_tree.spr(disallow_sibling_SPRs=True)
                else:
                    for i in range(num_permutations):
                        new_tree = new_tree.spr()
            elif method == 'coal':
                new_tree = \
                    master_tree.get_constrained_gene_tree(scale_to=permutation_extent)
            return new_tree