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
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)
def plot_string_tree(stree): plot_graph(identifier_to_tree_clean(stree))
updat = updater(sigma / sqrt(2 * n - 2 + 4 * k)) new_tree = update_all_branches(new_tree, updat) if new_tree is None: return tree, 1, 0 #rejecting by setting backward jump probability to 0. return new_tree, 1, 1 class rescale_class(object): new_nodes = 0 proposal_name = 'rescale' adaption = True input = 'tree' require_admixture = 0 reverse_require_admixture = 0 reverse = 'rescale' admixture_change = 0 def __call__(self, *args, **kwargs): return rescale(*args, **kwargs) if __name__ == '__main__': from tree_plotting import plot_graph from Rcatalogue_of_trees import tree_on_the_border2_with_children plot_graph(tree_on_the_border2_with_children) new_tree = rescale(tree_on_the_border2_with_children) plot_graph(new_tree) print 'old_tree', tree_on_the_border2_with_children print 'new_tree', new_tree