Course 5.2Lesson 1 of 3
A Punnett square lists every way two gametes can meet. In code, a gamete is a letter and a genotype is a sorted pair of letters. A Counter of the four boxes gives the 1:2:1 ratio of genotypes and the 3:1 ratio of tall to short.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
In the Heredity chapter you met Mendel's pea plants. A tall plant crossed with a short one gave only tall plants. When those plants were crossed with each other, about one plant in four came out short.
A Punnett square explains this. It lists every way a gamete of one parent can meet a gamete of the other. Here you build it in Python, so the computer does the listing and the counting.
Plant height in peas is set by one gene with two forms:
A plant carries two letters. TT and Tt plants are tall; only tt is short.
Each gamete gets one of the parent's two letters. In Python, a genotype is a string, and list() splits it into its letters:
It prints ['T', 't']: the two kinds of gamete a Tt plant makes, in equal numbers.
A child gets one letter from each parent. Adding two strings joins them, but the order can come out either way: "t" + "T" gives "tT". Biologists always write the dominant letter first, so "tT" and "Tt" are the same genotype.
sorted() fixes this. Capital letters come before small ones, so the dominant letter always lands first:
It prints Tt. Without sorting, a count would treat tT and Tt as two different genotypes.
Two loops visit every pair of gametes, one from each parent. That is exactly what the square does.
It prints ['TT', 'Tt', 'Tt', 'tt']: the four boxes, read row by row.
The phenotype is what you see. A small function turns a genotype into it:
One T is enough for a tall plant, so the test is simply whether "T" is in the string.
Counter from the collections module counts how often each item appears in a list:
It prints Counter({'Tt': 2, 'TT': 1, 'tt': 1}): the 1:2:1 ratio of genotypes. Counting phenotypes instead gives 3 tall to 1 short, the 3:1 ratio. Mendel saw nearly this: tall and short plants, about to 1.
The program builds the square for Tt with Tt, prints it as a grid, and counts the genotypes and the phenotypes.
tT and Tt are counted apart, and the genotype count shows four kinds instead of three.g[0] == "T" works only when every genotype is sorted. "T" in g always works.Counter needs from collections import Counter, or Python stops with NameError.list("Tt") gives ['T', 't']."".join(sorted(a + b)), so the dominant letter comes first.Counter(kids) gives the 1:2:1 genotype ratio; counting phenotypes gives 3:1.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
"".join(sorted("t" + "T")) give, and why is the sort needed?phenotype test "T" in genotype and not genotype == "TT"?{'Tt': 2, 'TT': 1, 'tt': 1}. What is the ratio of phenotypes?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…