Skip to content

Instantly share code, notes, and snippets.

@ashander
Last active October 31, 2016 23:08
Show Gist options
  • Save ashander/efe8442d82cf349c74779308cbb445ed to your computer and use it in GitHub Desktop.
Save ashander/efe8442d82cf349c74779308cbb445ed to your computer and use it in GitHub Desktop.
Msprime records $\sum_i (l_i - r_i)$ will _not_ sum to `n-1` for `n` samples (unless there is no recombination)
import msprime
pop = __import__('random').randint(2, 20000)
sum = 0
with open('example.tsv', 'w') as f:
msprime.simulate(pop, recombination_rate = 10).write_records(f)
with open('example.tsv', 'r') as f:
f.readline()
l = f.readlines()
for line in l:
vec = line.split('\t')
sum += float(vec[1]) - float(vec[0])
assert int(sum) + 1 == pop, "population size: {}, 'coverage': {}".format(pop, int(sum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment