MendelCreature Genetics
Instructor Tutorial

This notebook provides instruction on how to use the MendelCreature genetics packages to construct genomes of fictional (and non-fictional) creatures for exploration by genetics students, much in the fashion of a fruit-fly laboratory exercise. You should have three template packages, MendelPeas.m, MendelBeans.m, and MendelDragon.m. The MendelPeas and MendelBeans packages represent genderless genomes with the capability of self-fertilization (as is typical of many plants). Although the two fictional plants exhibit the same traits, they have a different genetic structure - the MendelPeas have mostly independent traits and no crossover, while the MendelBeans exhibit fully linked traits with crossover. The Mendel Dragon package incorporates the complexity of gender, thus requiring the mating of opposite-gender individuals, as well as adding the possibility for sex-linked traits.
Building a MendelCreature Package
	We will start by building our own MendelCreature, which in this case will be a variety of clover.  MendelClover will have two trait types - number of leaves and color of flowers.  In this clover, four-leaves will be recessive to three-leaves, but genes for purple flowers and for white flowers will combine in the heterozygous plants to make pink flowers.
	(If you do not wish to be able to construct your own MendelCreature packages, you can simply download the MendelClover.m package and skip this section).
	In order to build our MendelClover, we will use MendelPeas as a template.  Open the package MendelPeas.m, which you have hopefully downloaded into the same directory as this tutorial notebook.  You will likely have to select 'Packages (*.m)' from the menu denoting 'Files of type:'  The package should begin with the line BeginPackage["MendelPeas`"].
	Because we don't want to change the original MendelPeas package, we will go ahead and save this version with a new name. Click onto the package screen, then select File followed by Save as Special, and then Package Format. Edit the file name from 'MendelPeas' to 'MendelClover' and click Save. (if it starts as 'MendelTutor', you are trying to save *this* notebook - Cancel and try again, making sure to click on the MendelPeas window before trying the save).
	Close the MendelPeas.m window and open your newly created package, MendelClover.m, which you should again find among files of type 'package'. Note that the file should still look exactly like MendelPeas.  Begin by editing the BeginPackage line, changing MendelPeas to MendelClover. Notice that the apostrophe at the end is important! Your first line should thus be edited to read BeginPackage["MendelClover`"]
	The next segment describes the TYPE of the genome, which we don't need to change. This is followed by a list of usage commands (eg. MakePop::usage = "etc...") which describe for the user how the various commands in the package work - these do not need to be changed either. Continue to the line Begin["`Private`"]. Immediately following this line begins the definition for the genome, which is a Mathematica list of the form Peas = {{...},{...},...,{...}}. This is the primary section to edit for the definition of our genome.
	Start by editing the variable Peas to Clover. Nine lines below is another statement, GENOME = Peas;, in which Peas should again be edited to Clover. The following line reads COPCT = 0;. This variable represents the crossover frequency for our plant, and should be set to a number from zero to one.  As we are not interested in a crossover study of our clover, especially given that we will presume our two traits are not linked on the same chromosome, we will not edit the zero setting.
	Return back to the line that now reads Clover = { , which is followed by seven lines of brackets, numbers and commas and then a final line with a closing bracket and a semicolon(};). Mathematica uses the curly brackets to represent lists, and in this case, each element of our Clover genome is itself a list, enclosed by brackets on its own line, each of which represents a trait in the genome. Each trait list, as can be seen from the leftover Peas genome, consists of three numbers and four quoted strings:
	{1, 6, .50, "Seeds", "Smooth", "Smooth", "Wrinkled"},
	The first number represents which chromosome a particular trait is associated with.  If we wish to link traits, we would give each trait the same chromosome number. Numbers 1 and 2 actually have a special representation as sex-linked genes for gendered genomes, but in this case, they have no special meaning. We will arbitrarily designate chromosome 5 as the home for the three/four leaf trait, and so change the 1 to a 5.
	The second number represents the location of a gene on a chromosome, as measured in genetic units from the center of the chromosome outward, and is a number from 0 to 50.  This number is meaningless except in crossover calculations, so we can choose any value - we'll say the three/four leaf trait lives near the end of the chromosome, at location 47, so we change the 6 to a 47.
	The third number represents the frequency (from 0.0 to 1.0) of 'dominant' genes in a sample population of MendelCreatures. A good number to use is .50, which means that when the user of the package creates a starting population using MakePop, half of the genes in the population will be the first (dominant) gene, and half will be the second (recessive) gene.  If you wish to generate more recessive trait individuals in the starting population, you would make this number lower. Clover will retain the default .50 value.
	The first string is generally a noun describing where the trait manifests itself.  In the case of our clover, this gene affects the number of "Leaves", which we encase in quotes to represent as a word string (replacing "Seeds"). The second and fourth strings are generally adjectives describing the phenotype associated with homozygous individuals, with the dominant trait expressed first, where applicable. The third string describes the heterozygous phenotype, and will match the dominant trait or describe the combined genetic effect. "Three", "Three", and "Four" describe the homozygous dominant, heterozygous and homozygous recessive number of leaves for our clover, which should now have the following trait description in the first line of the list:
	{5, 47, .50, "Leaves", "Three", "Three", "Four"},
	If we place the second trait on chromosome 1, position 12, again with a 50-50 gene distribution, the edit for the second trait becomes
	{1, 12, .50, "Flowers", "Purple", "Pink", "White" }
	Because this is the last trait we eliminate the comma at the end, which is meant to separate elements of the list (note that it is missing after the last of the Peas traits). We can then eliminate the remaining leftover traits.  The full Clover genome definition should thus look like this:
Clover={
      {5,47,.50,"Leaves","Three","Three","Four"},
      {1,12,.50,"Flowers","Purple", "Pink","White"}
      };
	You should now be able to click on the MendelClover package and Save it, now that it is complete.

Working with a MendelCreature
	Now that we have created a package for MendelClover, let's run some 'genetics' experiments! You will first want to open a New Mathematica window under the File menu.
	In order for Mathematica to find our package, we first ensure that Mathematica knows which directory to find packages in. We enclose the entire path (the list of folders/directories from outside in) in quotes inside the SetDirectory function. Use the Windows search function (Start-Search-For Files or Folders) or the Mac finder to search for 'MendelPeas.m', and then click on the file to reveal the list of directories or folders. The following line is a Windows2000 example (grl is a username - your path will be different!):

SetDirectory["C:\Documents and Settings\grl\My \
Documents\Mathematica"];

We then load the package of interest using <<, which is shorthand for the Get function and loads in a file from the specified directory.

<< MendelClover.m

If you remember, at the beginning of our package there were a set of usage statements, which, when a package has been loaded, will provide us with help information about statements in the package.  For example, if we are uncertain as to how the function MakePop works, we can 'ask', using the question mark help syntax.

?MakePop

Lets make a population of three clover plants, and save it in a variable ThePatch.The input for MakePop is a number representing the desired number of individuals in the newly created population.

ThePatch = MakePop[3]

Hmmm. not very interesting - just a list of 'Neutral Gender' statements and some coded numbers. To see the list of traits (or phenotype), we will need to use the ShowPop function, which takes a coded population list as an argument.

ShowPop[ThePatch]

Our clover population (ThePatch) is a Mathematica list, from which we can select an individual, either by using the Mathematica index notation, or by the package function PickOne, which takes a population list and a position number and gives the code of a particular individual at that position.  The traits belonging with a single individual code can be viewed using ShowOne.

SecondPlant  =  PickOne[ThePatch, 2];
ThirdPlant  =  ThePatch[[3]];
ShowOne[SecondPlant]
ShowOne[ThirdPlant]

We can now do a genetic recombination using the Breed command, which requires two individuals and a number of desired offspring, and generates a new population.

NewPatch = 
        Breed[SecondPlant, ThirdPlant, 4];
ShowPop[NewPatch]

Notice that a genderless MendelCreature can self-fertilize, if desired

NewPatch2  =  
        Breed[SecondPlant, SecondPlant, 2];
ShowPop[NewPatch2]

If we would like to generate a new population by random pairings, we can BreedPop, which takes a population, and two numbers, the first of which is the number of random pairings to make, and the second of which represents the number of offspring from each pairing. Notice self-pairing is possible in the genderless case.

PatchKids  =  
        BreedPop[ThePatch, 4, 4];
ShowPop[PatchKids]

The last three commands are useful for gathering statistics on larger populations. CountTrait takes a population and a given trait and returns the number of individuals with that trait, as well as the total number in the population and the ratio of the two numbers.

BigPatch  =  MakePop[1000];
CountTrait[BigPatch, "Three Leaves"]
CountTrait[BigPatch, "Four Leaves"]
CountTrait[BigPatch, "White Flowers"]
CountTrait[BigPatch, "Purple Flowers"]
CountTrait[BigPatch, "Pink Flowers"]

Assuming and even frequency of alleles, it looks like 'Three Leaves' is dominant to 'Four Leaves', while 'White Flowers' and 'Purple Flowers' are homozygous traits that combine for heterozygous 'Pink Flowers'.
	CountTraitMatch is useful for determining linkage of traits. It requires input of a population, a list of traits (contained by brackets and separated by commas), and an operator, designating whether you are looking for an individual with the first trait And each of the others, or looking for creatures with one trait Or another.

CountTraitMatch[BigPatch, {"Four Leaves", "Pink Flowers"}, 
      And]

So in this case, about 1/8 of the BigPatch population has four leaves and pink flowers, which is an expected result for an independent distribution (1/4 "Four Leaves" times 1/2 "Pink Flowers"). This would indicate that the traits are on different chromosomes.
	If we wish to pick a portion of a population with a given set of traits, we can use FindTraitMatches, which takes the same arguments as CountTraitMatch, but returns a population subset.

PurpleFours  =  
        FindTraitMatches[BigPatch, {"Four Leaves", "Purple Flowers"}, 
          And];
WhiteThrees  =   FindTraitMatches[
          BigPatch, {"Three Leaves", "White Flowers"}, 
          And];
ShowOne[PurpleFours[[1]]]
ShowOne[WhiteThrees[[1]]]

Our population numbers seem to indicate that purple, white and four are all homozygous traits, but three could be heterozygous or homozygous. If we breed PurpleFours to WhiteThrees, we would expect all offspring to be heterozygous for flower color, and thus have 'pink flowers'.

Hetero  =  
        Breed[PurpleFours[[1]], WhiteThrees[[1]], 
          100];
CountTrait[Hetero, "Pink Flowers"]
CountTrait[Hetero, "Three Leaves"]

One of two things will happen with leaves - there will either be all three-leaved plants or about 50% three leaved plants.  What does each possible result mean about the WhiteThrees individual selected for the breeding?
	With the MendelCreature commands, you should be able to combine creatures in the same fashion as you would for live genetics experiments.  Be sure to name populations as they are created, as each time MakePop,Breed,and BreedPop are executed, they generate new, randomized populations.
	A final, useful command is DumpSave, which allows you to save the information currently held in the kernel memory for use when you come back to Mathematica later on.
DumpSave requires a filename (in quotes, usually with the suffix .mx) and a list of variables whose values are to be stored.

DumpSave["CloverSave.mx", {BigPatch, ThePatch}];

BigPatch  =  {}
ThePatch  =  {}

Notice the values of BigPatch and ThePatch have been eliminated, and the lists are empty.  We can 'reload' the information with the << input command, which will restore the values originally in the patch variables.

<< CloverSave.mx

BigPatch[[1]]

ThePatch

This notebook created by Dr. Garrett R. Love for the Shodor Education Foundation. Copyright 2001