Question: Build on your answer to question 4 on assignment 7c. Write a function that will examine how a population evolves over several generations due to

Build on your answer to question 4 on assignment 7c. Write a function that will examine how a population evolves over several generations due to genetic drift. You will use your two functions that you have already written, draw_alleles(fA) and generate_population(fA, N). The new function, evolve_time(fA, N), will track the number of generations, starting with 0. Each time it calls generate_population(fA, N), it will check if fA is equal to 0 or 1. If either of these is true, it will stop running and return whether the A allele fixed (fA equals 1) or was lost (fA equals 0) and the number of generations that past.

Two functions already written:

def draw_alleles(fA): genotype='' rand_1=random.random() rand_2=random.random() if (rand_1 genotype='AA' elif (rand_1>fA) and (rand_2>fA): genotype='aa' else: if (rand_1 genotype='Aa' return

def generate_population(fA, N): aa_counter=0 Aa_counter=0 AA_counter=0 for i in range (N): this= draw_alleles (fA) if(this =='aa'): aa_counter=aa_counter+1 elif(this =='Aa'): Aa_counter=Aa_counter+1 else : AA_counter=AA_counter+1 return

Function that needs to be written:

def evolve_time(fA, N): # this function will run until fA is equal to 0 or to 1. It will track the number of generations # that have passed, generations_ctr, starting with 0. When it ends, it will return a string, outcome, which will be either # "fixed" or "lost", as well as the number of generations that past. return outcome, generations_ctr

def main(): fA = 0.3 N = 10 outcome, generations = evolve_time(fA, N) # write a print statement here return

main()

The language is Python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!