Errata
There are a couple of errors in the lab files that you need to fix.
Option 1: If you have not started on the lab, simply remove bacterium.py and run
update21 to get a fresh copy:
$ rm bacterium.py
rm: remove regular file `bacterium.py'? y
$ update21
Adding /home/asas/cs21/labs/11/bacterium.py
Option 2: Edit the bacterium.py file to fix the errors. First,
hasTrait should add a
self parameter:
def hasTrait(self, gene)
-----
Second, the
undraw() method needs to reset the
drawn list
on line 43:
def undraw(self):
"""
Undraws the bacterium from its current window
"""
self.body.undraw() #Undraw the cell
curr = self.drawn.getHead() #Undraw each spot
while curr != None:
curr.getData().undraw()
curr = curr.getNext()
self.drawn = LinkedList()
Run update21, if you haven't already, to create the
cs21/labs/11 directory. Then cd into your cs21/labs/11
directory and create the python programs for lab 11 in this directory
(handin21 looks for your lab 11 assignments in your cs21/labs/11 directory).
$ update21
$ cd cs21/labs/11
Introduction
A common tool used in biology experiments is to alter the genomes or epigenomes
of organisms to see the resulting effects. While early geneticists picked
easily visible traits (e.g., flower color) to trace their experiments, most
genes of interest do not have an easily visible phenotype. Instead,
biologists often tag genes with small fragments that, when present and expressed
, produce fluorescent colors. As a result, it becomes easy to identify if a
certain gene is present/expressed by detecting if the organism gives off
a fluorescence when exposed to ultraviolet light. The Nobel Prize in Chemistry
for 2008 was award to a team of chemists who discovered and developed
green
flourescent proteins.
In this lab, you will simulate the creation of a new bacteria genome and
visualize the results. You will complete a class, Bacterium that
represents one bacterium object. The bacterium has a genome, which will
be a linked list of all of the genes it contains. Each gene is tagged
with a fluorescent marker so you can see what genes are present in the cell
using graphics in python. Your main program is open ended - I want to see
you design your own lab! Your program should allow a user to create
several bacterium cells, add and remove genes multiple times, visualizing the
changes over time. Below is a brief summary of the files in your directory:
- node.py - the definition of the Node class discussed in lecture.
This represents a node in a linked list and contains a data value and a link
to the next node. This file has already been completed, you should
not modify it. But you should read it and ensure you understand its usage.
- linkedlist.py - a partial definition of the LinkedList class that
we began in lecture. While several methods have been defined, you will need
to complete all non-implemented methods.
- bacterium.py - the partial definition of the Bacterium class.
I have implemented several methods for you, you will need to complete all
non-implemented methods.
- colony.py - your main program. This is largely open-ended. Have fun
and be creative, you will be graded on your design and creativity. There
are some parameters below that you can use to guide you.
The LinkedList Class
You should implement each class and test them before you
move on to the next step.
A linked list represents a collection of items as a set of linked Node
objects. The data maintained a linked list includes:
- The first item in the sequence: head (a Node)
- The last item in the sequence: tail (a Node)
- The total number of items in the sequence: size (an int)
You should review your notes from class to ensure you understand the
Node class and the major operations in the list interface.
The methods for the
LinkedList include:
- __init__() - A constructor that initializes a LinkedList
object. This has been completed for you
- __str__() - returns a string representation of
the LinkedList object. This has been completed for you
- __len__() - returns the length of the list. This has been
completed for you
- isEmpty() - returns True of the list has no items. This has
been completed for you
- insertAtTail(data) - adds an item to the end of the linked list,
similar to append in Python lists. This has been completed for
you, based on our algorithm from class
- insertAtHead(data) - adds an item to the front of the linked list.
You must complete this method
- removeFromHead(), removeFromTail() - remove an item from the front
or end of the linked list, respectively. Your method must return the data
value that was stored in the removed node. You must complete this method.
- getHead() - returns a reference to the head node in the list.
This has been completed for you
- findNode(data) - searches the list for a matching item to the given
data. If the item is in the list, a reference to its Node is returned,
otherwise None is returned.
You must complete the test function at the bottom of the class and ensure
your linked list works before moving on.
The Bacterium Class
The Bacterium class represents a bacterium cell and its genome. To avoid
all the details of an actual genome (in other words, to abstract
away the genome), we will use a simplistic representation of a cell. The
genome will be a collection of genes. A gene, in turn, is identified simply
by the color that it has been tagged with (e.g., yellow, blue, red). A
bacterium cell is alive as long as it has some genes to work with, and dies
if you try to draw the cell and it has no genes. The genome can grow
to as large or as small as you desire, and can have many copies of the same
gene. The bacterium can be drawn and undrawn from a graphical window.
Each Bacterium object has:
- A genome - a LinkedList containing all of the genes
in the bacterium cell. Each "gene" is represented by the color of its
fluorescent tag. So, there can be "yellow" genes, "red" genes, and for
a casual Friday, "blue" genes. (Oh boy, that was a bad joke)
- A cell body - a Circle object that is the physical cell.
When the cell is alive, the body is filled white. When it is dead, it is
filled black.
- Whether the cell is dead - a boolean variable that starts
off as False and becomes True when the bacterium is dead.
The decision to trigger cell death has already been coded in for you,
but you will need to use the status in your implementation.
- drawn - a LinkedList of all drawn objects. While
the genome is simply a color, you will need to draw circles to represent the
genes to the screen. drawn allows you to remove those circles at a
later point.
You will need to implement some methods to complete the class:
- __init__() - constructs a new Bacterium object.
This has been implemented for you. Be sure to understand this
method before moving on.
- __str__() - returns a string representation of the object.
You can implement this as you see fit, but it should provide information about
the state of the object, such as the number of genes it has, what gene it has,
the death status of the cell, etc. You must complete this method.
- insertGene(gene) - insert the given gene into the genome.
You should not be able to add genes to dead cells. You can add the gene
whereever you see fit. You must complete this method.
- deleteGene(gene) - remove a gene from the bacterium's genome.
You should randomly decide what end of the genome to delete the gene from
(we are using the simplistic model that insertions and deletions only
happen at the ends of the genome, eventhough bacteria genomes are circles).
You do not need to worry about whether this triggers cell death. But an already
dead bacterium cannot remove genes (because it has none!). You should return
the value the gene that was deleted, or an empty string if no gene was deleted.
You must complete this method.
- hasTrait(gene) - returns True if the genome contains
the given gene. You must complete this method.
- draw - draws the Bacterium object to the given window.
This has been implemented for you. It first decides if the cell is
dead. If the cell is dead, it draws a black circle and returns. Otherwise,
it draws the white cell body and adds a spot representing each gene
in the genome. There is some math in there for randomly sampling a location
in the cell to draw. All drawn spots are added to the drawn list.
- undraw() - undraws all spots and the cell itself. This has been implemented for you.
I have provided a test main for this class to help you validate your
implementation before moving in. It is by no means complete, so add more
tests as you see fit. Here is the series of you images you should see in the
window between mouse clicks (Note: there is some randomness in deleting genes,
so your images may have different colors for the spots).
$ python bacterium.py
Removed a yellow gene
Removed a green gene
Removed a blue gene
$
Testing your classes with colony.py
Once you have tested the other classes, you should move on to implementing
a main program. This portion of the assignment is largely open ended. I want
to see you use your the design skills you have developed throughout the course
to implement your own program. Feel free to implement additional
methods in your Bacterium class if you need them. For example,
it may be useful to have a zombify() method to bring you cell
back to life.
At a minimum, you should ensure your program does the following:
- Creates several instances of the Bacterium class. You should
easily be able to create 4 or 5 cells and draw them to the screen. You
can even store all of them in a LinkedList!
- Use every method avaiable in the Bacterium class.
- Interact with the user via a menu interface. This means your program
should have a main while-loop that allows the user to manipulate the bacteria
colony several times over.
See below for an example.
- Have some mechanism for altering the genomic sequences repeatedly. Don't
simply remove a gene and add a gene like in the test file. Be creative!
For example, you can create
some cells and then give the user a menu of options such as:
- Draw the cells
- Undraw the cells
- Randomly delete genes from the colony
- Randomly (or selectively) insert some genes
- Report how many bacterium have a certain genotypic trait. Or
how many copies of a gene are in each cell.
Feel free to ask myself or the ninjas for guidance if you want to do something
but aren't sure about some of the details.
Submit
Once you are satisfied with your program, hand it in by typing
handin21 in a terminal window.