In-Class Assignment: Simulating Superbugs using agent-based modeling#

Day 8#

CMSE 202#

Image from: https://sites.psu.edu/siowfa16/2016/10/18/what-are-superbugs/comment-page-1/

Put your name here

#

✅ Put your group member names here

#

Learning Goals:#

By the end of this assignment you should have:

  • Become more comfortable with writing a custom class from scratch

  • Practiced using stub functions to sketch out the methods needed by a new class

  • Designed a plan for implementing an agent-based model to simulate bacteria evolution

    • Note: Design decisions early on can have a large impact on the final outcome. Try to make design decisions that are flexible. Do not be afraid to refactor your code (i.e. start over with the design).

Agenda#

  1. Pre-class assignment review and discussion

  2. Problem Description (simulating bacteria evolution)

  3. Building code stubs for your model (using classes and methods)

  4. Preview Visualization

Assignment instructions#

Instructions for submitting this assignment are at the end of the notebook. The assignment is due at the end of class.


1. Pre-class assignment review and discussion#

Did anyone have any specific issues with the pre-class assignment?

Let’s take a moment to highlight some key concepts. Discuss with your group the following prompts and write down a some brief notes from your discussion.

Question 1: What data structures did you think you might need to simulate the petri-dish experiment? What would these data structures be used to represent or keep track of?

Do This - Make note of anything that comes up in your discussion that you didn’t originally think or any ideas that you had based on your discussion.

Question 2: What classes did you think you would need to define and what were some of the methods you came up with?

Do This - Make note of anything that comes up in your discussion that you didn’t originally think or any ideas that you had based on your discussion.


2. Problem Description (simulating bacteria evolution)#

In this assignment we are going to start to build an agent based model to simulate the evolution of bacteria to become resistant to antibiotics. If you need to refresh your memory, re-watch the following video that was in your pre-class assignment. Our goal is to build a simulation that reconstructs this real world experiment.

Here’s the link to the original article as well: http://www.the-scientist.com/?articles.view/articleNo/46993/title/Giant-Petri-Dish-Displays-Evolution-in-Space-and-Time/

from IPython.display import YouTubeVideo
YouTubeVideo("yybsSqcB7mE",width=640,height=360)

To make this ABM work we would like you to build a system with the following assumptions.

  1. Assume a random rectangular petri dish of N locations wide and M locations tall (e.g. 90 x 45).

  2. Assume that each location on the board is given three (3) different types of antibiotics which each can have continuous values from min to max (e.g. 0 to 1).

  3. Assume that bacteria on the board do not move.

  4. Assume each bacteria has a genome sequence of three genes of continuous number (e.g. 0 to 1) that provide immunity to the antibiotics. Each gene will correspond to one of the antibiotic elements deposited on the petri dish

  5. Assume that at each iteration of the simulation each bacteria can randomly copy itself once to a random neighboring empty cell (up, down, left, or right).

  6. Assume that during the copy there is a chance of mutating each gene (randomly selecting a new value between zero and one) by some mutation rate (e.g. 20%).

  7. Assume that a bacteria will “die” if the value of it’s gene does not contain resistance to any one of the three antibacteria. For example, if the gene is a number less than the value of it’s corresponding antibiotic it will die.

NOTE: Assumptions are very important. Make sure you document any major changes, clarifications or deviations from the above. Instead of asking your instructor for clarification, try looking at the end goal (simulate the petri dish experiment) and make your own clarification. There are many right answers.

Question 3: What additional assumptions do you think you need to make for this project? Do you need to modify or add to any of the above assumptions to make the problem more tractable?

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

Consider the following example simulation as one possible solution to this problem:

from IPython.display import YouTubeVideo
YouTubeVideo("p_wGHmNYE_0",width=800,height=450)

This video was created with the following settings:

  • The bugs were initialized in the first and last column of the petri dish with randomly generated bacteria

  • Equal amounts of all three antibiotics in 9 different bins using the following pattern:
    | 0.0 | 0.50 | 0.75 | 0.80 | 0.95 | 0.80 | 0.75 | 0.5 | 0.0 |

  • The cells copied with a mutation rate of 20% (i.e. there is a 20% chance each gene will randomly mutate during each copy).


3. Building code stubs for your model (using classes and methods)#

✅ Do This: As a group, decide on what classes and functions that will be needed for the simulation and create stub functions for your classes. Focus on the inputs, outputs and data types, but don’t worry about trying to code up all of your methods yet! You just need the stub functions.

Here are some hints:

  • you can use the pass keyword to create an empty class or an empty method. However, in creating an empty method you can still specify the input parameters which can be useful

  • you might think about some class variables, values that can be stored and utilized by all instances

# Put your stub functions here

4. Initialize and draw your “world” for the model (i.e. the petri dish and initial bacteria)#

Lets start filling in the stub functions by focusing on the visualization. Try considering the following:

  • Use colors to indicate the level of antibiotics in the petri dish. Since there are three antibiotics you can use the Red, Green and Blue Channels to indicate the amount of each of the three antibiotics. The imshow function can process a 2D array of RGB values.

  • Use colors to differentiate the types of the bugs. Since there are three genes for each bug, you can use the Red, Green and Blue color channels to differentiate them. The scatter function can take in a list of RGB values to color a point.

You should come up with a method (or couple of methods) in your class (or classes) to draw the petri dish and the bugs. Should bug be able to draw themselves on the petri dish given their location? Or should the petri dish handling all of the drawing given a list of bugs? You get to choose how to do this!

✅ Do This: Try to implement some of your stub functions to initialize the problem and see if you can come up with a method to visualize the starting state. See if you can create a board that looks similar to the following:

example-dish
# Put your code here


Congratulations, we’re done!#

Now, you just need to submit this assignment by uploading it to the course Desire2Learn web page for today’s submission folder (Don’t forget to add your names in the first cell).

© Copyright 2024, Department of Computational Mathematics, Science and Engineering at Michigan State University