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) # outbase = ".".join(treefile.split(".")[:-1]) # num_samples = 20 # num_times = 3 ts = sps.SpatialSlimTreeSequence(pyslim.load(treefile), dim=2) for time in np.floor(np.linspace(0, num_gens - 1, num_times)): datafile = outbase + ".{}.admixture.txt".format(time) if os.path.isfile(datafile): print(datafile, "already exists.") data = np.loadtxt(datafile) samples = np.array([np.int(u) for u in data[:, 0]]) admixture = data[:, 1:] else: print(datafile, "does not exist, computing.") samples, admixture = compute_admixture(ts, time, num_gens - 1, num_samples) data = np.column_stack([samples, admixture]) np.savetxt(datafile, data)
# 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 num_indivs = 200 locs = ts.individual_locations() xmax = max(locs[:, 0]) ymax = max(locs[:, 1]) alive = ts.individuals_alive(0) left_third = np.logical_and(alive, locs[:, 0] < xmax / 3) right_third = np.logical_and(alive, locs[:, 0] > 2 * xmax / 3)