Published
Edited
Apr 29, 2021
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fractionZeroAlleles = {
const data = []
generationsWF.forEach((pop, gen) => {
data.push({
gen,
fraction: calcFractionZeroAlleles(pop),
type: "Wright-Fisher"
})
data.push({
gen,
fraction: calcFractionZeroAlleles(generationsM[gen]),
type: "Moran"
})
data.push({
gen,
fraction: calcFractionZeroAlleles(generationsM[gen * N]),
type: "Moran * N"
})
})
return data
}
Insert cell
Insert cell
Insert cell
function simulateMoran() {
// const initial = Array.from({ length: N }, () => randBit())
const initial = generationsWF[0]
const generations = [initial];
for (let i = 0; i < (r-1) * N; ++i) {
let pop = generations[generations.length - 1]

// Copy parent generation
let offspring = pop.map(genotype => genotype)
// Pick a random individual to clone and a random to die
const [i, j] = randWithReplacement()
// Replace type on site j with the type on site i
offspring[j] = offspring[i]
generations.push(offspring)
}
return generations
}
Insert cell
function simulateWrightFisher() {
const initial = Array.from({ length: N }, () => randBit())
const gen = [initial];
for (let i = 0; i < r-1; ++i) {
let pop = gen[gen.length - 1]
let offspring = Array.from({ length: N }, () => {
return pop[randInt(N)]
})
gen.push(offspring)
}
return gen
}
Insert cell
calcFractionZeroAlleles = (pop) => {
let numOneAlleles = pop.reduce((tot, bit) => tot + bit, 0)

return (N - numOneAlleles) / N
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more