# alpha = 0.5, # edgecolors='none', # facecolors='black') for k, indiv in enumerate(samples): admix = admixture[k, :] admix /= sum(admix) draw_pie(ax, locs[indiv, 0], locs[indiv, 1], admix) return fig num_gens = 301 treefile = sps.run_slim(script=script, seed=23, SIGMA=4.0, W=50.0, K=5.0, NUMGENS=num_gens, BURNIN=1) outbase = ".".join(treefile.split(".")[:-1]) num_samples = 200 num_times = 5 # num_gens = 901 # treefile = sps.run_slim(script = script, # seed = 23, # SIGMA = 3.0, # W = 50.0, # K = 5.0, # NUMGENS = num_gens, # BURNIN=1)
x = np.concatenate([x, dists[:, k]]) y = np.concatenate([y, div[:, k]]) po = np.random.choice(len(x), len(x), replace=False) ax.scatter(x[po], y[po], s=10, alpha=0.5, marker=".", c=colors[po]) ax.set_xlabel("geographic distance") ax.set_ylabel("genetic distance") return fig # for script in ("valleys.slim", "flat_map.slim"): ## pass in script on command-line num_gens = 1 treefile = sps.run_slim(script=script, seed=23, SIGMA=0.4, W=50.0, NUMGENS=num_gens, BURNIN=10000) outbase = ".".join(treefile.split(".")[:-1]) recapfile = outbase + ".recap.trees" if os.path.isfile(recapfile): ts = sps.SpatialSlimTreeSequence(pyslim.load(recapfile), dim=2) else: ts = pyslim.load(treefile) ts = sps.SpatialSlimTreeSequence(ts.recapitate(Ne=1e3, recombination_rate=1e-9), dim=2) ts.dump(recapfile) num_targets = 4
locs[ips[pair_indices[po], 1], 1] - locs[ips[pair_indices[po], 0], 1], # dY color=colors[po], alpha=0.4, width=0.15, units='xy', scale=1) return fig # for script in ("valleys.slim", "flat_map.slim"): ## pass in script on command-line treefile = sps.run_slim(script=script, seed=23, SIGMA=1.5, W=50.0, K=5.0, NUMGENS=30) outbase = ".".join(treefile.split(".")[:-1]) ts = sps.SpatialSlimTreeSequence(pyslim.load(treefile), dim=2) # number of time steps to plot the flux for plot_ngens = 10 xmax = max([ind.location[0] for ind in ts.individuals()]) ymax = max([ind.location[1] for ind in ts.individuals()]) circle_xy = (xmax / 2, ymax / 2) circle_rad = xmax / 3
def update(frame): inds = ts.individuals_by_time(frame) circles.set_offsets(locs[inds, :]) # color based on age so far circles.set_color(colormap(ts.individuals_age(frame)[inds])) circles.set_sizes(size_fun(inds)), return circles animation = ani.FuncAnimation(fig, update, frames=np.linspace(0, num_gens - 1, num_gens)) return animation for script in ("flat_map.slim", "valleys.slim"): num_gens = 300 treefile = sps.run_slim(script=script, seed=23, SIGMA=0.4, W=8.0, NUMGENS=num_gens) outbase = ".".join(treefile.split(".")[:-1]) ts = sps.SpatialSlimTreeSequence(pyslim.load(treefile), dim=2) today = np.where(ts.individual_times == 0)[0] animation = animate_ancestry(ts, np.random.choice(today, 1), num_gens) animation.save(outbase + ".ancestry.mp4", writer='ffmpeg')
} paths = [] pathcolors = [] for u, p in path_dict: if periodic: this_paths = break_path(path_dict[(u, p)], W) else: this_paths = [path_dict[(u, p)]] for this_path in this_paths: paths.append(this_path) pathcolors.append(treecolors[p]) lc = cs.LineCollection(paths, linewidths=0.5, colors=pathcolors) ax.add_collection(lc) treefile = sps.run_slim(script=script, **kwargs) patchfile = treefile + ".landscape" outbase = ".".join(treefile.split(".")[:-1]) ts = pyslim.load(treefile) patchdata = np.loadtxt(patchfile) patchtimes = patchdata[:, 0] patchvals = patchdata[:, 1:] patches = sps.patch_polygons(patchtimes, patchvals, ts.slim_generation) W = patchdata.shape[1] - 1 today = ts.individuals_alive_at(0) has_parents = ts.has_individual_parents() max_time = np.max(ts.individual_times[has_parents]) if len(today) < num_indivs: raise ValueError(f"Not enough individuals: only {len(today)} alive today!")
import pyslim, msprime import numpy as np import spatial_slim as sps import os, sys # we have the full pedigree for this long num_gens = 200 treefile = sps.run_slim(script="flat_map.slim", seed=23, SIGMA=1.0, W=50.0, K=5.0, NUMGENS=num_gens, BURNIN=1) outbase = ".".join(treefile.split(".")[:-1]) # treefile = "valleys/run_1.0_50.0_5.0_100_23.trees" ts = sps.SpatialSlimTreeSequence(pyslim.load(treefile), dim=2) ### # Find effective generation time: # for each time t in the past, # take the average over all individuals alive at time t # of the average of their two parents' age at the time of their birth # where individuals are chosen proportionally to their genetic contribution to the modern generation # So, as t increases, this should converge to the effective generation time. # # Said another way: # 1) pick a bit of today's genome # 2) trace back to the individual, x, from whom it was inherited t time units in the past # 3) pick a random one of x's two parents, whom we call y.