# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

import random

# +
#WrightFisherSimulation

popSize=100
nGen=100
genomeLength=100
muRates={ 'A': {'C': 0.1,'G': 0.1,'T': 0.1},
         'C':{'A': 0.1,'G': 0.1,'T': 0.1} ,
         'G':{'A': 0.1,'C': 0.1,'T': 0.1},
         'T':{'A': 0.1,'C': 0.1,'G': 0.1}}

def mutate(popDict,muRates):
    muPopDict=popDict
    for j in list(popDict.keys()):
        template=popDict[j]
        position=random.choice(range(genomeLength))
        mutation=random.choice(list(muRates[template[position]].keys()))
        if random.random()<muRates[template[position]][mutation]:
            product=template[0:position]+mutation+template[(position+1):genomeLength]
        muPopDict[j]=product
    return(muPopDict)
def select(popDict):
    newPopDict=dict(zip(range(popSize),[popDict[random.choice(list(popDict.keys()))] for i in range(popSize)]))
#    print(newPopDict)
    return(newPopDict)


# +
#make Pop dict:
popDict=dict(zip(range(popSize),["".join(["A"]*genomeLength)]*popSize))

for gen in range(nGen):
    print (gen)
    popDict=select(popDict)
    #print(popDict)
    popDict=mutate(popDict,muRates)
    
# -

from Bio import SeqIO

from matplotlib import pyplot as plt
import numpy as np

np.unique(list(popDict.values()),return_counts=True)



StarcoderdataJupyterScriptsDedupFiltered