# Yee-Shiuan Chen $pop_size = @ARGV[0]; #takes in population size $max_gen = @ARGV[1]; #takes in number of generations $fitness_value = @ARGV[2]; #takes in fitness value $answer = 0; #this variable carries the percentage fixation for ($t = 0; $t < 100; $t++) { #for 100 trails $individual[2] = 0; #individual 2 is the number of homozygous mutant(bio5488) $individual[1] = 1; #individual 1 is the number of heterozygotes(start as one) $individual[0] = $pop_size - 1; #individual 0 is the number of homozygous wild-types(- the het) for ($j = 0; $j < $max_gen; $j++) { #counts the number of generations distribute(); #call "distribute" function to calculate the probabilities make_next_G(); #call "make_next_G" to assign the next generation if ($individual[2] == $pop_size) { #if homozygous mutants dominate the population $answer++; #add one to answer last; #leave the loop 'cause there is no point } if (($individual[1]+$individual[2]) == 0 ) { #if hets and homozygous mutants disappear from population last; #leave the loop 'cause there is no point } } } print "$answer%\n"; #print the answer sub distribute { #defines the subfunction $density[0] = $individual[0] * 1; #this defines the number range for homo wt $density[1] = $individual[1] * $fitness_value + $density[0]; #number range for het if dominant #$density[1] = $individual[1] + $density[0]; #number range for het if recessive $density[2] = $individual[2] * $fitness_value + $density[1]; #number range for homo mutant } sub make_next_G { #defines sub function for ($i = 0; $i < 3; $i++) { #for each types of individual $individual[$i] = 0; #make everything zero for the new generation } for ($i = 0; $i < $pop_size; $i++) { #for the entire population $individual[(sample() + sample())]++; #for each individual call "sample" twice for each allele } #if both allele is wt, then 0+0=0 and add 1 to $indivi[0] } #if het, then 0+1 or 1+0 = 1 and add 1 to $indivi[1] #if homo mutant then 1+1=2 and add 1 to $indivi[2] sub sample { #defines sub function $random_number = int rand ($density[2]); #piack a random integer any where from 1 to max for ($a = 0; $a < 3; $a++) { #for three types of genotypes if ($random_number < $density[$a]) { #if number less than a particular type (0,1 or 2) $output = int ($a / 2); #if 0 then 0/2=0 and output 0 #if 2 then 2/2=1 and output 1 if ($a == 1) { #if 1 then it's a het and have to pick between $output = int rand (2); #0 and 1 again to see if mutant or wt } return ($output); #return the output last; #leave the loop } } }