Beispiel #1
0
    def test_newick(self):

        N, colors = 30, 5
        repeats = 20

        for _ in range(repeats):

            tree = random_colored_tree(N, colors)
            newick = to_newick(tree)
            tree2 = parse_newick(newick)

            # colors of tree must be converted to 'str'
            label_color = [(v.label, v.color) for v in tree.leaves()]
            label_color2 = [(v.label, v.color) for v in tree2.leaves()]

            self.assertListEqual(label_color, label_color2)
Beispiel #2
0
import tralda.tools.GraphTools as gt

import asymmetree.treeevolve as te
from asymmetree.analysis import (undirected_fitch,
                                 rs_transfer_edges,
                                 below_equal_above,
                                 ldt_graph,
                                 RsScenarioConstructor,)
from asymmetree.tools.PhyloTreeTools import (to_newick,)

S = te.simulate_species_tree(10)
TGT = te.simulate_dated_gene_tree(S, dupl_rate=1.0, loss_rate=0.5,
                                  hgt_rate=0.5)
OGT = te.observable_tree(TGT)

print('--- S ---\n', to_newick(S))
print(to_newick(S, distance=False, label_inner=False))
print('--- OGT ---\n', to_newick(OGT))

ldt, above, equal = below_equal_above(OGT, S)
fitch = undirected_fitch(OGT, rs_transfer_edges(OGT, S))
n = ldt.order()
print('Genes:', n, 'Total relations:', int(n * (n-1) / 2))
print('< {}\n= {}\n> {}'.format(ldt.size(), equal.size(), above.size()))

rs_scen_constr = RsScenarioConstructor(ldt)
result = rs_scen_constr.run()

if result:
    S2, T2 = result
    print('--- S2 ---\n', to_newick(S2, distance=False))
Beispiel #3
0
from asymmetree.paraphylo import TreeReconstructor
from asymmetree.tools.PhyloTreeTools import (to_newick, parse_newick,
                                             reconstruct_timestamps)


__author__ = 'David Schaller'


# species tree

#S = ts.simulate_species_tree(10)
S = parse_newick('(((((16:0.38786287055727103,(18:0.2071277923445058,19:0.2071277923445058)17:0.18073507821276524)12:0.10075553853805931,(14:0.13224182895383052,15:0.13224182895383052)13:0.3563765801414998)4:0.07517286794939665,(6:0.5373882998574596,(8:0.4434182448023457,(10:0.04929450217312242,11:0.04929450217312242)9:0.3941237426292233)7:0.0939700550551139)5:0.02640297718726732)2:0.2512472266526016,3:0.8150385036973286)1:0.18496149630267142)0:0.0;')
reconstruct_timestamps(S)

print('------------- original species tree -------------')
print(to_newick(S))

tr = TreeReconstructor(cotree_mode='best')


# gene families

for i in range(100):
    TGT_simulator = te.GeneTreeSimulator(S)
    TGT = TGT_simulator.simulate(dupl_rate=1.0, loss_rate=1.0)
    TGT = te.assign_rates(TGT, S, base_rate=1,
                          autocorr_variance=0.2,
                          rate_increase=('gamma', 0.5, 2.2),
                          CSN_weights=(1, 1, 1))
    OGT = te.observable_tree(TGT)
    
Beispiel #4
0
import asymmetree.treeevolve as te
from asymmetree.analysis.BestMatches import lrt_from_observable_tree
from asymmetree.tools.PhyloTreeTools import (
    to_newick, )

D = 1.0
L = 1.0
H = 0.0

# --------------------------------------------------------------------------
#                            SPECIES TREE
# --------------------------------------------------------------------------

S = te.simulate_species_tree(10, planted=True, non_binary_prob=0.2)
print('------------- S -------------')
print(to_newick(S))

# --------------------------------------------------------------------------
#                             GENE TREE
# --------------------------------------------------------------------------

TGT_simulator = te.GeneTreeSimulator(S)
TGT = TGT_simulator.simulate(dupl_rate=D,
                             loss_rate=L,
                             hgt_rate=H,
                             prohibit_extinction='per_species')

TGT = te.assign_rates(TGT,
                      S,
                      base_rate=1,
                      autocorr_variance=0.2,
Beispiel #5
0
# -*- coding: utf-8 -*-

import asymmetree.treeevolve as te
from asymmetree.tools.PhyloTreeTools import (
    to_newick, )

__author__ = 'David Schaller'

print('Yule ------------------------')
tree = te.simulate_species_tree(10, model='yule', birth_rate=1.0)
print(to_newick(tree))

print('EBDP ------------------------')
tree2 = te.simulate_species_tree(10,
                                 episodes=[(1.0, 0.3, 0.8, 0.0),
                                           (0.9, 0.4, 0.6, 0.3)])
print(to_newick(tree2))

print('Yule age ------------------------')
tree3 = te.simulate_species_tree_age(2.0, model='yule', birth_rate=1.0)
print(to_newick(tree3))

print('EBDP age ------------------------')
tree4 = te.simulate_species_tree_age(2.0,
                                     model='EBDP',
                                     birth_rate=1.0,
                                     episodes=[(1.0, 0.3, 0.8, 0.0),
                                               (0.9, 0.4, 0.6, 0.3)])
print(to_newick(tree4))