Exemplo n.º 1
0
 def alternate_admixes(self, n=1000):
     for i in xrange(n):
         old_tree = deepcopy(self.tree)
         self.tree = addadmix(
             self.tree,
             new_node_names=['n' + str(i) + a for a in ['o', 'n']])
         if self.no_admixes + 1 == get_number_of_admixes(self.tree):
             print 'INCREASED NUMBER OF ADMIXTURES BY ONE= ' + 'TRUE'
         else:
             print 'INCREASED NUMBER OF ADMIXTURES BY ONE= ' + 'FALSE'
         ad = make_consistency_checks(self.tree, ['s1', 's2', 's3', 's4'])
         if not ad[0]:
             print ad
             plot_graph(old_tree, drawing_name='good.png')
             plot_graph(self.tree, drawing_name='bad.png')
             break
         #plot_graph(self.tree)
         old_tree = deepcopy(self.tree)
         self.tree = deladmix(self.tree)
         if self.no_admixes == get_number_of_admixes(self.tree):
             print 'DECREASED NUMBER OF ADMIXTURES BY ONE= ' + 'TRUE'
         else:
             print 'DECREASED NUMBER OF ADMIXTURES BY ONE= ' + 'FALSE'
         #plot_graph(self.tree)
         print self.tree
         ad = make_consistency_checks(self.tree, ['s1', 's2', 's3', 's4'])
         if not ad[0]:
             print ad
             plot_graph(old_tree, drawing_name='good.png')
             plot_graph(self.tree, drawing_name='bad.png')
             deladmix(old_tree)
             break
Exemplo n.º 2
0
def topological_support(start_tree, n=10000, nodes=None):
    from tree_plotting import plot_as_directed_graph, plot_graph, pretty_print, pretty_string
    tree = start_tree
    score = 0
    for i in range(n):
        prop_index = choice(3, 1)
        if prop_index == 0 and get_number_of_admixes(tree) > 0:
            new_tree = deladmix(tree)[0]
            score -= 1
        elif prop_index == 1:
            new_tree = make_regraft(tree, _get_new_nodes(i, prop_index))[0]
        elif prop_index == 2:
            new_tree = addadmix(tree, _get_new_nodes(i, prop_index))[0]
            score += 1
        else:
            new_tree = tree
        consistent, information = make_consistency_checks(new_tree, nodes)
        if consistent:
            if get_number_of_admixes(new_tree) < 50:
                tree = new_tree
        else:
            print information
            print 'last_good_tree', tree
            print 'new_bad_tree', new_tree
            plot_as_directed_graph(tree, drawing_name='before.png')
            wait(1)
            plot_as_directed_graph(new_tree, drawing_name='after.png')
            wait(1)
        if i % 1000 == 0:
            plot_as_directed_graph(tree,
                                   drawing_name='number_' + str(i) + 'K.png')
            wait(1)
    plot_as_directed_graph(tree, drawing_name='final_tree.png')
    wait(1)
    return score
Exemplo n.º 3
0
def check(tree, pks={}):
    result, fails = make_consistency_checks(tree)
    if not result:
        stringed_message = ''
        print fails
        for test_key, (test_result, test_message) in fails.items():
            if test_result:
                stringed_message += test_key + ": TRUE" + '\n'
            else:
                stringed_message += test_key + ": FALSE" + '\n'
                stringed_message += "    " + test_message + '\n'
        print stringed_message
        assert result, "The tree was inconsistent :" + '\n' + stringed_message
Exemplo n.º 4
0
 def many_admixes(self, n=100):
     for i in xrange(n):
         self.tree = addadmix(
             self.tree,
             new_node_names=['n' + str(i) + a for a in ['o', 'n']])
         #plot_graph(self.tree)
         if self.no_admixes + 1 == get_number_of_admixes(self.tree):
             print 'INCREASED NUMBER OF ADMIXTURES BY ONE= ' + 'TRUE'
         else:
             print 'INCREASED NUMBER OF ADMIXTURES BY ONE= ' + 'FALSE'
         self.no_admixes = get_number_of_admixes(self.tree)
         ad = make_consistency_checks(self.tree, ['s1', 's2', 's3', 's4'])
         if not ad[0]:
             print ad
             plot_graph(self.tree, drawing_name='bad.png')
             break
     plot_as_directed_graph(self.tree)