Run update21b to get the starting point file for this
week's lab, which will appear in cs21b/labs/04. The program
handin21b will only submit files from this directory.
In biology, the genotype describes an organism's heriditary information while the phenotype is the organism's actual observed properties, including its body and behavior. An organism's physical properties determine how well it survives, and if it manages to reproduce and pass on its genes. This distinction between the genotype and the phenotype is fundamental to the study of evolution.
In this lab we will focus on the mapping between a genotype and a phenotype. Next lab we will simulate a simple evolutionary process using this mapping.
Often in the computational modeling of evolution, the representation of the genotype will be abstracted from the level of base pairs, amino acids, or even proteins. Instead the genotype will be represented as a sequence of numbers that represent phenotypic features.
In this lab we will define a genotype consisting of a sequence of
integers that code for the features of a face including head size,
head color, eye size, eye position, eye color, mouth size, mouth
position, and mouth color. We will generate random genotypes and then
use the graphics library to draw the face (i.e. the associated
A face genotype will consist of a list of 15 features as described in the table below:
|0||100||200||radius of head|
|1||1||255||red component of head color|
|2||1||255||green component of head color|
|3||1||255||blue component of head color|
|4||5||50||radius of eyes|
|5||40||80||horizontal offset of each eye from the center of the head|
|6||1||255||red component of eye color|
|7||1||255||green component of eye color|
|8||1||255||blue component of eye color|
|9||40||100||length of mouth|
|10||10||30||width of mouth|
|11||40||80||vertical offset of mouth from the center of the head|
|12||1||255||red component of mouth color|
|13||1||255||green component of mouth color|
|14||1||255||blue component of mouth color|
The following figure illustrates how the above genotype features (except for the color components) will map into the phenotype of a face.
For example, the following genotype was randomly generated using the minimum and maximum values given in the table above:
[144, 44, 50, 103, 42, 55, 140, 242, 104, 78, 16, 75, 206, 26, 225]
This results in the following phenotype:
We will be representing the genotype as a list of 15 integers. Here are a few helpful hints on how to use lists.
Like strings, lists can be indexed. For example, the following code uses a for loop to index through a list and print each item.
ls = [100, 200, 300, 400] for i in range(len(ls)): print ls[i]
We can also create lists using an accumulator pattern. Like strings, we could use concatenation to accumulate a list, but it is more typical to use the append method which will add a given value to the end of a list. For example, the following code uses a for loop to create a list of length 10 containing random coin flips.
ls =  for i in range(10): ls.append(choice(['heads','tails'])) print ls
You're welcome to add more features to your face, such as a nose or
ears. Be sure to define reasonable limits for their size, location,
and color. Add these limits to the lists geneMins
and geneMaxs. Also, make sure to add comments to explain
how these features are to be interpreted for drawing purposes.
Once you are satisfied with your program, hand it in by typing handin21b in a terminal window.