Beispiel #1
0
        def make_master_tree(
            n,
            method,
            names=None,
            inner_edge_params=(1, 1),
            leaf_params=(1, 1),
            distribution_func=np.random.gamma,
            ):
            """
            Function returns a tree object with n tips,
            named according to `names`, and constructed
            according to `method`, which is one of 'random_topology',
            'random_yule' and 'random_coal'
            """

            if method == 'random_topology':
                master_topology = Tree.new_random_topology(n,
                        names=names, rooted=True)
                master_tree = \
                    master_topology.randomise_branch_lengths(inner_edges=inner_edge_params,
                        leaves=leaf_params,
                        distribution_func=branch_length_func)
                master_tree.newick = '[&R] ' + master_tree.newick
            elif method == 'random_yule':
                master_tree = Tree.new_random_yule(n, names=names)
            elif method == 'random_coal':
                master_tree = Tree.new_random_coal(n, names=names)
            return master_tree
Beispiel #2
0
        def make_master_tree(
                n,
                method,
                names=None,
                inner_edge_params=(1, 1),
                leaf_params=(1, 1),
                distribution_func=np.random.gamma,
        ):
            """
            Function returns a tree object with n tips,
            named according to `names`, and constructed
            according to `method`, which is one of 'random_topology',
            'random_yule' and 'random_coal'
            """

            if method == 'random_topology':
                master_topology = Tree.new_random_topology(n,
                                                           names=names,
                                                           rooted=True)
                master_tree = \
                    master_topology.randomise_branch_lengths(inner_edges=inner_edge_params,
                        leaves=leaf_params,
                        distribution_func=branch_length_func)
                master_tree.newick = '[&R] ' + master_tree.newick
            elif method == 'random_yule':
                master_tree = Tree.new_random_yule(n, names=names)
            elif method == 'random_coal':
                master_tree = Tree.new_random_coal(n, names=names)
            return master_tree
Beispiel #3
0
            print 'There was an IOError: {0}'.format(e)
            print 'Geodesic distances couldn\'t be calculated'
            raise

    def run(self, trees):
        self.writetmp(trees)
        rooted = self.allrooted(trees)
        self.call(rooted)
        try:
            matrix = self.read(len(trees))
            self.clean()
            return matrix
        except IOError:
            print 'except'
            matrix = None
            raise

    def writetmp(self, trees):
        with open('{0}/geotrees.nwk'.format(self.tmpdir), 'w') as tmpf:
            tmpf.write('\n'.join(tree.newick.rstrip() for tree in
                       trees))


if __name__ == '__main__':
    from tree import Tree
    trees = [Tree.new_random_coal(10) for _ in range(100)]
    g = GTP()
    print g
    m = g.run(trees)
    print m
Beispiel #4
0
            print 'There was an IOError: {0}'.format(e)
            print 'Geodesic distances couldn\'t be calculated'
            raise

    def run(self, trees):
        self.writetmp(trees)
        rooted = self.allrooted(trees)
        self.call(rooted)
        try:
            matrix = self.read(len(trees))
            self.clean()
            return matrix
        except IOError:
            print 'except'
            matrix = None
            raise

    def writetmp(self, trees):
        with open('{0}/geotrees.nwk'.format(self.tmpdir), 'w') as tmpf:
            tmpf.write('\n'.join(tree.newick.rstrip() for tree in trees))


if __name__ == '__main__':
    from tree import Tree
    trees = [Tree.new_random_coal(10) for _ in range(100)]
    g = GTP()
    print g
    m = g.run(trees)
    print m