def test_read_write(self): """Read and write an ARG""" rho = 1.5e-8 # recomb/site/gen l = 10000 # length of locus k = 10 # number of lineages n = 2*10000 # effective popsize arg = arglib.sample_arg(k, n, rho, 0, l) # round ages and pos for easy equality for node in arg: node.age = round(node.age) node.pos = round(node.pos) stream = StringIO.StringIO() arglib.write_arg(stream, arg) stream.seek(0) arg2 = arglib.read_arg(stream) self.assertTrue(arg.equal(arg2))
def test_recomb(self): """ Investigate the fact that some recombinations are not visible """ k = 3 n = 1e4 rho = 1.5e-8 * 20 mu = 2.5e-8 length = 1000 arg = arglib.sample_arg(k, n, rho, start=0, end=length) times = arghmm.get_time_points(10) arghmm.discretize_arg(arg, times) arg.set_ancestral() arg.prune() recombs = arglib.get_recomb_pos(arg) # find recombs by walking recombs2 = [] i = 0 while True: tree = arg.get_marginal_tree(i - .5) recomb = arghmm.find_tree_next_recomb(tree, i + 1, tree=True) if recomb: recombs2.append(recomb.pos) i = recomb.pos else: break # these are suppose to differ because some recombination occur # in the hole of ancestral sequence intervals print recombs print recombs2 arglib.write_arg("tmp/b.arg", arg)
def test_recomb(self): """ Investigate the fact that some recombinations are not visible """ k = 3 n = 1e4 rho = 1.5e-8 * 20 mu = 2.5e-8 length = 1000 arg = arglib.sample_arg(k, n, rho, start=0, end=length) times = arghmm.get_time_points(10) arghmm.discretize_arg(arg, times) arg.set_ancestral() arg.prune() recombs = arglib.get_recomb_pos(arg) # find recombs by walking recombs2 = [] i = 0 while True: tree = arg.get_marginal_tree(i-.5) recomb = arghmm.find_tree_next_recomb(tree, i+1, tree=True) if recomb: recombs2.append(recomb.pos) i = recomb.pos else: break # these are suppose to differ because some recombination occur # in the hole of ancestral sequence intervals print recombs print recombs2 arglib.write_arg("tmp/b.arg", arg)
move_layout(layout1, x=i*(nleaves+2)) move_layout(layout2, x=(i+1)*(nleaves+2)) mapping = get_mapping(tree1, tree2, pos, times) draw_mapping(tree1, tree2, layout1, layout2, times, mapping) #============================================================================= if 0: k = 10 n = 1e4 rho = 1.5e-8 * 100 mu = 2.5e-8 length = 1000 arg = arglib.sample_arg(k, n, rho, start=0, end=length) arglib.write_arg("tmp/a.arg", arg) muts = arglib.sample_arg_mutations(arg, mu) seqs = arglib.make_alignment(arg, muts) #arg = arglib.read_arg("tmp/a.arg") #arg.set_ancestral() #find_recomb_coal(tree, last_tree, recomb_name=None, pos=None) times = arghmm.get_time_points(30, maxtime=60e3) arghmm.discretize_arg(arg, times) # get recombs recombs = list(x.pos for x in arghmm.iter_visible_recombs(arg)) print "recomb", recombs pos = recombs[0] + 1
# treelib.layout_tree(tree2, xscale=1, yscale=1), leaves=0) move_layout(layout1, x=i * (nleaves + 2)) move_layout(layout2, x=(i + 1) * (nleaves + 2)) mapping = get_mapping(tree1, tree2, pos, times) draw_mapping(tree1, tree2, layout1, layout2, times, mapping) #============================================================================= if 0: k = 10 n = 1e4 rho = 1.5e-8 * 100 mu = 2.5e-8 length = 1000 arg = arglib.sample_arg(k, n, rho, start=0, end=length) arglib.write_arg("tmp/a.arg", arg) muts = arglib.sample_arg_mutations(arg, mu) seqs = arglib.make_alignment(arg, muts) #arg = arglib.read_arg("tmp/a.arg") #arg.set_ancestral() #find_recomb_coal(tree, last_tree, recomb_name=None, pos=None) times = arghmm.get_time_points(30, maxtime=60e3) arghmm.discretize_arg(arg, times) # get recombs recombs = list(x.pos for x in arghmm.iter_visible_recombs(arg)) print "recomb", recombs pos = recombs[0] + 1