Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 40 ยท Projects and Practice

Project: A Genetics Simulator

Build a small simulator that follows DNA through transcription, translation, mutation and inheritance, using the ideas from the whole course.

In this project you will combine the ideas from the DNA and inheritance chapters into one small program. You will write a gene, copy it (replication), transcribe it (transcription), translate it and mutate it (translation and mutations), and finally pass alleles to offspring (crosses).

This is a simulation: a simplified model written for learning. It is not a tool for real genetic analysis. Real cells have many more steps, such as splicing and proofreading.

Step 1: the central dogma pipeline

Start with functions for each step. The codon table is the standard genetic code written in the order U, C, A, G. Each function does one job so you can test it alone.

Python DNA to RNA to protein

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The program finds the first AUG, so the CC before it is ignored. In real cells, the ribosome finds the start in a more complicated way.

Step 2: mutations and their effects

Next we add a function that mutates a random base and describes what happened. We compare the old protein with the new one. A fixed random seed makes the run repeatable.

Python Random mutations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You can try other seeds and sequences. Notice how often a random change is silent or outside the coding region, and how the effect depends on position.

Step 3: inheritance

Now track alleles. Each parent gives one allele at random. We can estimate how often a recessive trait appears when two carriers have many children.

Python Carrier parents: how many affected children?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The simulated proportions should be close to the theoretical binomial probabilities. This shows why "one in four" is a probability for each child, not a rule that one child in every family of four is affected.

Extensions to try

  1. Add a function that counts the GC content of a gene.
  2. Make the mutation function delete a base and observe the frameshift.
  3. Add a second gene and simulate a dihybrid cross.
  4. Compare your results with a Punnett square.
  5. Change the code so a stop codon in the middle of a gene produces a shorter protein and print its length.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. In the pipeline, what is the relationship between the coding strand and the mRNA?

    The mRNA is made from the template strand, so it matches the coding strand with uracil instead of thymine.
  2. 2. Why might a random mutation not change the protein?

    The genetic code is degenerate, and parts of a sequence do not code for protein.
  3. 3. Two carrier parents (Aa x Aa) each have 4 children. Does exactly one child have to be aa?

    Each child is an independent event with probability 1/4, so families vary.

Summary

  • A simulation can model DNA, RNA, protein and inheritance with a few short functions.
  • Replication, transcription and translation are separate steps you can test independently.
  • Mutation effects depend on type and position.
  • Probabilities in genetics describe chances for each child, not guaranteed ratios in small families.

Next: Project: Allele Frequencies and the Hardy-Weinberg Principle