Advertisement
Guest User

Untitled

a guest
May 5th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.05 KB | None | 0 0
  1. {
  2. "metadata": {
  3. "name": "",
  4. "signature": "sha256:1889ae534f956f32624c02e522e8e5297f5e9d774edf3b710640080737c63479"
  5. },
  6. "nbformat": 3,
  7. "nbformat_minor": 0,
  8. "worksheets": [
  9. {
  10. "cells": [
  11. {
  12. "cell_type": "markdown",
  13. "metadata": {},
  14. "source": [
  15. "#Biofilm Model\n",
  16. "\n",
  17. "###Defining the Model\n",
  18. "Biofilms are clusters of bacteria cells that grow together on surface, creating a three dimensional film-like matrix, but little is known about what environmental conditions are needed for them to form. For my project, I hope to use an ABM to explore what environmental factors are necessary in order to create a biofilm. \n",
  19. "\n",
  20. "###Goal\n",
  21. "My main question would be to discover the main environmental/growth factors that can alter biofilm formation, as well as to determine correlation functions between similar cells and cross-correlation functions between different types of cells. I believe this question can be answered by an ABM, since all my cells have similar features, but each act as their own agent. \n",
  22. "\n",
  23. "###Justification\n",
  24. "Using an ABM, I will be able to control different environmental factors by creating them as a different set of agents and bring all my agents together in my model to see how they interact.\n",
  25. "\n",
  26. "###Processes and Mechanisms of Interest\n",
  27. "I am interested in discovering what concentration of nutrients helps the cells to have the ideal growth. Obviously, more nutrients will help the cells grow, but if there are too many the cells will not adhere and form a biofilm. My goal is to run my simulation with different amounts of inital nutrients and also possibly different rates of replenishing the nutrients, corresponding to different media used to grow my cells in (inital nutirents) and also how quickly the cells can break down the nutrients in the media (rate of replenished nutrients). By changing amount of nutrients provided to the cell, I hope to determine the ideal amount of nutrients to grow a biofilm. \n",
  28. "\n",
  29. "###Outline\n",
  30. "For an individual run:\n",
  31. " * Initalize a set amount of cells so they do not overlap\n",
  32. " * Initalize a set amount of nutrients \n",
  33. " * Pick a cell and see if it is close to nutrients\n",
  34. " * If it isn't, continue (maybe make the cell die a little? After multiple checks with no nutrients?)\n",
  35. " * If it is, have radius grow by 1\n",
  36. " * If it is surrounded on 3 of 4 sides by nutrients, the cell will 'die' and be taken from the simulation- essentially there are too many nutrients and there is no reason for the cells to clump and form a biofilm \n",
  37. " * Check radius, if above a max radius, have cell divide\n",
  38. " * Record cell positions\n",
  39. " * Add 1 to sweep count, repeat for next cell/next sweep\n",
  40. " \n",
  41. "After a set amount of steps (or all cells are dead), I will check to see a visual representation of what the grid of cells looks like as well as record their positions. From that information, I should be able to find correlation functions for the variables. Below is a breakdown of some of the specifics of the model "
  42. ]
  43. },
  44. {
  45. "cell_type": "code",
  46. "collapsed": false,
  47. "input": [
  48. "from __future__ import print_function\n",
  49. "import copy\n",
  50. "from math import *\n",
  51. "import sys\n",
  52. "import random\n",
  53. "import string\n",
  54. "\n",
  55. "import numpy \n",
  56. "import matplotlib.pyplot as plt\n",
  57. "import pandas\n",
  58. "import seaborn; seaborn.set()"
  59. ],
  60. "language": "python",
  61. "metadata": {},
  62. "outputs": [],
  63. "prompt_number": 52
  64. },
  65. {
  66. "cell_type": "markdown",
  67. "metadata": {},
  68. "source": [
  69. "####I. Space\n",
  70. "Consider the space to be a 2D square grid for now. (Ideally, it will eventually be a 3D grid.) Possibly an overlay of 2 different 2D grids- This way one grid will be for the cells and the other grid will be for the nutrients. It will be very large in x, but discontinous at the boundries. Also for the y direction it should be large enough that it never reaches the top. For right now, I am only looking at one grid, but by my final model, hopefully I can have these 2 grids.\n",
  71. "\n",
  72. "####II. Model \n",
  73. "#####A. Parameters\n",
  74. "Based on my plans for the model, the follow parameters are needed:\n",
  75. " * gridX- length of the 2D grid\n",
  76. " * gridY- height of the 2D grid, much larger than gridX\n",
  77. " * numCells- intial number of cells to place at time 0\n",
  78. " * concentrationNutrients- inital amount of nutrients to place at time 0 as a concentration compared to numCells\n",
  79. " * numNutrients- intial number of nutrients, product of numCells and concentrationNutrients\n",
  80. " * isOccupied- True or false based on whether or not a cell is already in the grid at that space\n",
  81. " * cellList- a list (dictionary?) that keeps track of the x and y position of each cell at each time step. This list can be used to both visualize my grid/biofilm and the positions can be used for correlation functions\n",
  82. " * nutrientList- same as cellList, except it keeps track of the nutrients \n",
  83. " * cellSpace- the representation of the cell grid\n",
  84. " * nutrientSpace- the representation of nutrients on the grid\n",
  85. "\n",
  86. "#####B. Functions\n",
  87. " * Constructor- set up parameters/grid values\n",
  88. " * setupSpace- initalize the cellSpace and nutrientSpace\n",
  89. " * createCells- initalize cells onto cellSpace, based on numCells set in constructor\n",
  90. " * createNutrients- initalize nutrients onto nutrientSpace, based on numNutrients set in constructor\n",
  91. " * findCell- return the cells x and y position in the grid\n",
  92. " * countNutrients- call find Cells, see if there are nutrients on/around the cell grid space and count them\n",
  93. " * cellSplit- Divide the cell into two, with the second cell going to a position in the Moore neighborhood around the cell\n",
  94. " * step- go through the list of cells, see if a cell should grow/divide/die, place new nutrients\n",
  95. " * correlationFunction- after all the steps, run this function to figure out the correlaton fucntion\n",
  96. " \n",
  97. " ** I think I need some plotting function, but I'm not sure what yet- look at that as one of the next steps once I get this code to work\n",
  98. " \n"
  99. ]
  100. },
  101. {
  102. "cell_type": "code",
  103. "collapsed": false,
  104. "input": [
  105. "class biofilmModel(object):\n",
  106. " '''Model class, what will be executed with one run of the Biofilm model'''\n",
  107. " def __init__(self, gridX = 30, gridY = 100, numCells = 10, concentrationNutrients = 0.4):\n",
  108. " '''model constructor'''\n",
  109. " # set up grid info\n",
  110. " self.gridX = gridX\n",
  111. " self.gridY = gridY\n",
  112. " \n",
  113. " #initalize info for the cells/nutrients\n",
  114. " self.numCells = numCells\n",
  115. " self.concentrationNutrients = concentrationNutrients\n",
  116. " self.numNutrients = int(self.numCells*self.concentrationNutrients)\n",
  117. " self.cellList = []\n",
  118. " self.nutrientList = []\n",
  119. " \n",
  120. " \n",
  121. " def setupSpace(self):\n",
  122. " '''set up our grid space based on the self.gridX and self.gridY given'''\n",
  123. " self.cellSpace = numpy.full((self.gridY, self.gridX), numpy.nan)\n",
  124. " self.nutrientSpace = numpy.full((self.gridY, self.gridX), numpy.nan)\n",
  125. " #print(self.cellSpace)- error checks, don't need to print every time\n",
  126. " #print(self.nutrientSpace)\n",
  127. " \n",
  128. " def createCells(self):\n",
  129. " '''Place cells in grid, number of cells corresponding to self.numCells'''\n",
  130. " for x in xrange(self.numCells):\n",
  131. " #check that there is an empty space? Otherwise this will be an infinite loop- DONE\n",
  132. " isOccupied = True\n",
  133. " cell.cellID = x\n",
  134. " if self.numCells > self.gridX:\n",
  135. " print('Too many cells- cannot place them')\n",
  136. " return\n",
  137. " else:\n",
  138. " while isOccupied == True:\n",
  139. " self.cellList.append(cell(self))\n",
  140. " locY = 0\n",
  141. " locX = numpy.random.randint(0, self.gridX)\n",
  142. " cell.locationX = locX\n",
  143. " cell.locationY = locY\n",
  144. " #print(locX, locY)\n",
  145. " #print(self.cellSpace[locY][locX])\n",
  146. " if numpy.isnan(self.cellSpace[locY, locX]):\n",
  147. " isOccupied = False\n",
  148. " else:\n",
  149. " isOccupied = True\n",
  150. " #cell.color = cellColorDecide()\n",
  151. " self.cellSpace[cell.locationY, cell.locationX] = cell.cellID\n",
  152. " \n",
  153. " def createNutrients(self):\n",
  154. " '''Place nutrients in grid, number of nutrients corresponding to self.numNutrients\n",
  155. " Initalize nutrients along 1st and second row- right by the cells'''\n",
  156. " for x in xrange(self.numNutrients):\n",
  157. " isOccupied = True\n",
  158. " nutrient.nutrientID = x\n",
  159. " while isOccupied == True:\n",
  160. " self.nutrientList.append(nutrient(self))\n",
  161. " locY = numpy.random.randint(0, 2)\n",
  162. " locX = numpy.random.randint(0, self.gridX)\n",
  163. " nutrient.locationX = locX\n",
  164. " nutrient.locationY = locY\n",
  165. " #print(locX, locY)\n",
  166. " #print(self.nutrientSpace[locY][locX])\n",
  167. " if numpy.isnan(self.nutrientSpace[locY, locX]):\n",
  168. " isOccupied = False\n",
  169. " else:\n",
  170. " isOccupied = True\n",
  171. " self.nutrientSpace[nutrient.locationY, nutrient.locationX] = nutrient.nutrientID\n",
  172. "\n",
  173. " def findCell(self, cellID):\n",
  174. " '''Return cell position'''\n",
  175. " # Find the value that matches cellID in self.cellSpace, then reshape to a 2-element list.\n",
  176. " return numpy.reshape(numpy.where(m.cellSpace == cellID), (1, 2))[0].tolist()\n",
  177. " \n",
  178. " def countNutrient(self, y, x, distance=1):\n",
  179. " ''' Return where nutrients are- need the cell location, use this to figure out if there are nutrients by the cells'''\n",
  180. " nutrientCount = 0\n",
  181. " #growth is related to how many nutrients are around the cell- keep track of how many we have \n",
  182. " neighborPosition = [ ( y % self.gridY, x % self.gridX)\n",
  183. " for y, x in itertools.product(xrange(y-distance, y+distance+1),\n",
  184. " xrange(x-distance, x+distance+1))]\n",
  185. " neighbor_list = []\n",
  186. " nutrientPosition = []\n",
  187. " for pos in neighborPosition:\n",
  188. " #if we go off the grid make sure it doesn't return an error\n",
  189. " if pos[0] < 0 or pos[0] >= self.gridY:\n",
  190. " pass\n",
  191. " elif pos[1] < 0 or pos[1] >= self.gridX:\n",
  192. " pass\n",
  193. " else:\n",
  194. " nutrientPosition += [(pos[0],pos[1])]\n",
  195. " for pos in nutrientPosition: \n",
  196. " # Check if empty\n",
  197. " if not numpy.isnan(self.nutrientSpace[pos[0], pos[1]]):\n",
  198. " neighbor_list.append(int(self.nutrientspace[pos[0], pos[1]]))\n",
  199. " nutrientCount +=1\n",
  200. " return neighbor_list, nutrientCount\n",
  201. " \n",
  202. " def cellSplit(self, y, x, radius):\n",
  203. " '''Split the cell into two, with the new cell moving to one of the moore positions'''\n",
  204. " #figure out what to do if the neighborhood if full. Move all cells? \n",
  205. " newRadius = radius/2.0\n",
  206. " radius = newRadius\n",
  207. " #Place a new cell\n",
  208. " #check that there is an empty space? Otherwise this will be an infinite loop\n",
  209. " isOccupied = True\n",
  210. " cell.cellID = len(self.cellList)\n",
  211. " neighborPosition = [ ( y % self.gridY, x % self.gridX)\n",
  212. " for y, x in itertools.product(xrange(y-distance, y+distance+1),\n",
  213. " xrange(x-distance, x+distance+1))]\n",
  214. " while isOccupied == True:\n",
  215. " self.cellList.append(cell(self))\n",
  216. " pickSpace = numpy.random.randint(0, len(neighborPosition))\n",
  217. " #print(locX, locY)\n",
  218. " #print(self.cellSpace[locY][locX])\n",
  219. " if numpy.isnan(self.cellSpace[pickSpace[0], pickSpace[1]]):\n",
  220. " isOccupied = False\n",
  221. " else:\n",
  222. " isOccupied = True\n",
  223. " cell.locationY = pickSpace[0]\n",
  224. " cell.locationX = pickSpace[1]\n",
  225. " cell.radius = radius\n",
  226. " self.cellSpace[cell.locationY, cell.locationX] = cell.cellID\n",
  227. " # Work on this code- figure out how to move some of the cells if they are dividing but have a full Moore neighborhood\n",
  228. " \n",
  229. " \n",
  230. "\n",
  231. " def step(self):\n",
  232. " ''' see if a cell should grow, see if a cell should split or die, replenish nutrients'''\n",
  233. " for cell in self.cellList:\n",
  234. " cellPosition = findCell(cell)\n",
  235. " nutrients = countNutrient(cellPosition[0], cellPosition[1], distance = 1)[1]\n",
  236. " #check that there are nutrients either at the cell position or in the moore neighborhood of the cellPosition\n",
  237. " if nutrients > 0:\n",
  238. " cell.radius += 1\n",
  239. " #make this be an increase based on the nutrients around the cell.\n",
  240. " #get rid of the nutrients that are used? Use pop? \n",
  241. " else:\n",
  242. " #for a speicifc cell with no nutrients, it cannot grow- add one to that cell's noGrowthCount\n",
  243. " #if noGrowthCount equals cellDeathCount, cell will die/remove it from the grid\n",
  244. " cell.noGrowthCount +=1\n",
  245. " if cell.noGrowthCount == cell.cellDeathCount:\n",
  246. " #set the position in our grid to a nan again- cell dies- Do I need to remove the cell from cell list?\n",
  247. " self.cellSpace[cell.locationX, cell.locationY] = nan\n",
  248. " \n",
  249. " for cell in self.cellList:\n",
  250. " if cell.radius > cell.maxRadius:\n",
  251. " #split the cells if there are enough nutrients\n",
  252. " nutrientAmount = countNutrient(self, cellPosition[0], cellPosition[1])\n",
  253. " if nutrientAmount > 2:\n",
  254. " cellSplit(cellPosition[0],cellPosition[1],cell.radius)\n",
  255. " \n",
  256. " # Want my step to return my grid to me/my cellList and maybe my nutrientList- possibly in a results folder. Then use \n",
  257. " # this to graph and/or run my correlation function\n",
  258. " \n",
  259. " \n",
  260. " def correlationFunction(self):\n",
  261. " '''Take the positions of the cells (from cell list) at the end of the sweeps and find relevant correlation fucntions'''\n",
  262. " ##Figure out what correlations I'm looking for. Talk to Dr. Wood about this...\n",
  263. "\n",
  264. "\n"
  265. ],
  266. "language": "python",
  267. "metadata": {},
  268. "outputs": [],
  269. "prompt_number": 106
  270. },
  271. {
  272. "cell_type": "markdown",
  273. "metadata": {},
  274. "source": [
  275. "####III. Actors\n",
  276. "#####A. Cells\n",
  277. "The cell class represents E. Faecalis, which I am modeling as circles. Each cell should be initialized with their specific set of parameters:\n",
  278. " * radius- Their starting radius, a generated random number from a set minimum and set maximum radius\n",
  279. " * colorDecide- Cells will either be red or green, again randomly chosen with the color assigned based on whether the random number is greater or less than a set number (50% off to start, may change depending on the system I want to simulate). I also plan on starting them with the ability to set one group of cells red and the other group green to see how the cells move and diffuse as they grow\n",
  280. " * maxRadius- Set maximum radius a cell can have. Once the cell reaches this radius or greater, it either needs to divide or die\n",
  281. " * locationX- The x position on the grid where the cell is, will update with each time step\n",
  282. " * locationY- The y position on the grid where the cell is, again will update with each time step\n",
  283. " * noGrowthCount- For each time step the cell does not grow (ie nearNutrients == False), the count will increase by 1. When the count reaches too high (the cell has not had nutrients for a certain amount of time) the cell will die\n",
  284. " * cellDeathCount- compare noGrowthCount to this: if they are equal, the cell will die since it has not had nutrients in too long of a time period\n",
  285. " * color- cell color, either red or green. Set to green, use the function color decide to see if it changes\n",
  286. " * cellID - number of the cell, used to keep track of which one is where in the cell list\n",
  287. "\n",
  288. " \n",
  289. "#####B. Nutrients\n",
  290. "For the cells to be able to grow, there need to be nutrients for them. In acutal biofilms, an extracellular matrix arises where the cells share their nutrients. To try to mimic this, I plan to initalize the nutrients initally randomly between the inital cells. As the cells grow and consume the nutrients, the nutrients will be replenished at some standard rate assuming there are still cells in that area. I am still trying to figure out the best way to distribute more nutrients as the cells grow/expand.\n",
  291. " * locationX and locationY- Same as above for the cells, the place on the grid where the nutrients are placed\n",
  292. " * nutrientID - number of the nutrient, used to keep track of which one in the nutrient list\n",
  293. "\n",
  294. "####IV. Initial Conditions\n",
  295. "#####A. Cells\n",
  296. " * At time 0, ten cells will be intially placed in our grid\n",
  297. " * All cells initialized with a locationY of 0, since they need to start on my substrate\n",
  298. " * The locationX will be chosen randomly from the length of the grid\n",
  299. " * Similarly, radius will be chosen randomly between the min and max radius\n",
  300. " * Each cell will be assigned a color- red or green- based on the random number. This color will not effect how the cells interact, but rather show how cells move by being able to track the colors\n",
  301. " * All cells will originally set nearNutrients to False and noGrowthCount to 0- until the first time step where they check to see if they are close to nutrients\n",
  302. " \n",
  303. "#####B. Nutrients\n",
  304. " * At time 0, after the cells are placed, nutrients will be randomly distributed based along the first few rows. \n",
  305. " "
  306. ]
  307. },
  308. {
  309. "cell_type": "code",
  310. "collapsed": false,
  311. "input": [
  312. "class cell(object):\n",
  313. " '''\n",
  314. " Cell class, each individual cell acts as its own agent\n",
  315. " Initalize all cells with similar basic parameters- the maximums for certain variables are consistent among the cells \n",
  316. " even if specific cells have different size radius or nutrient counts\n",
  317. " '''\n",
  318. " \n",
  319. " def __init__(self, model, maxRadius = 2.5, cellDeathCount = 10, noGrowthCount = 0, \n",
  320. " locationX = 0, locationY = 0, color = \"green\", cellID = 0):\n",
  321. " \"\"\"\n",
  322. " Constructor for cell class. By default,\n",
  323. " * starts at origin of grid\n",
  324. " * cell color is green\n",
  325. " * random radius, with a max radius of 2.5\n",
  326. " \"\"\"\n",
  327. " self.model = model\n",
  328. " self.radius = numpy.random.normal(0.5,1.5)\n",
  329. " self.color = color\n",
  330. " self.maxRadius = maxRadius\n",
  331. " self.cellDeathCount = cellDeathCount\n",
  332. " self.noGrowthCount = noGrowthCount\n",
  333. " self.locationX = locationX\n",
  334. " self.locationY = locationY\n",
  335. " self.cellID = cellID\n",
  336. " \n",
  337. " def cellColorDecide(self):\n",
  338. " ''' Change cell color- 50% of cells green, 50% red- change to red from defaulted green if colorDecide >=50%'''\n",
  339. " self.colorDecide = numpy.random.normal(0,1)\n",
  340. " if self.colorDecide >= 0.5:\n",
  341. " self.color = \"red\"\n",
  342. " \n",
  343. " def getPosition(self):\n",
  344. " ''' Return where in the grid this specific cell is'''\n",
  345. " return self.model.findCell(self.cellID)\n",
  346. " \n"
  347. ],
  348. "language": "python",
  349. "metadata": {},
  350. "outputs": [],
  351. "prompt_number": 107
  352. },
  353. {
  354. "cell_type": "code",
  355. "collapsed": false,
  356. "input": [
  357. "class nutrient(object):\n",
  358. " '''Nutrient class, randomly distributed throughout cells to help them grow'''\n",
  359. " def __init__(self,model, locationX = 0, locationY= 0, nutrientID = 0):\n",
  360. " \"\"\"\n",
  361. " Constructor for cell class. By default,\n",
  362. " * starts at a randomly generated x and y\n",
  363. " * always set nutrient placed to True \n",
  364. " ***Figure out a way to set the x and y of where the nutrient placed is to true?\n",
  365. " Maybe put this in the createNutrients function in the model? Also need to create nutrients if as the cells grow\n",
  366. " \"\"\"\n",
  367. " self.locationX = locationX\n",
  368. " self.locationY = locationY\n",
  369. " self.nutrientID = nutrientID"
  370. ],
  371. "language": "python",
  372. "metadata": {},
  373. "outputs": [],
  374. "prompt_number": 108
  375. },
  376. {
  377. "cell_type": "code",
  378. "collapsed": false,
  379. "input": [
  380. "model = biofilmModel()\n",
  381. "model.setupSpace()"
  382. ],
  383. "language": "python",
  384. "metadata": {},
  385. "outputs": [],
  386. "prompt_number": 109
  387. },
  388. {
  389. "cell_type": "code",
  390. "collapsed": false,
  391. "input": [
  392. "model.createCells()\n",
  393. "model.createNutrients()"
  394. ],
  395. "language": "python",
  396. "metadata": {},
  397. "outputs": [],
  398. "prompt_number": 110
  399. },
  400. {
  401. "cell_type": "code",
  402. "collapsed": false,
  403. "input": [
  404. "print(model.cellSpace[0])\n",
  405. "print(model.nutrientSpace[0])\n",
  406. "print(model.nutrientSpace[1])\n",
  407. "#check to see where cells are placed, where nutrients are placed"
  408. ],
  409. "language": "python",
  410. "metadata": {},
  411. "outputs": [
  412. {
  413. "output_type": "stream",
  414. "stream": "stdout",
  415. "text": [
  416. "[ 27. 8. 16. 5. 12. 10. 29. 23. 14. 28. 6. 20. 4. 0. 25.\n",
  417. " 19. 2. 17. 22. 11. 18. 15. 24. 13. 3. 26. 1. 7. 21. 9.]\n",
  418. "[ nan nan nan nan nan nan nan 1. 5. nan nan nan nan 3. nan\n",
  419. " nan nan 0. nan nan nan nan nan 6. nan 9. nan nan nan nan]\n",
  420. "[ nan nan nan nan 7. 11. nan nan 8. nan nan nan nan nan 10.\n",
  421. " nan 4. nan 2. nan nan nan nan nan nan nan nan nan nan nan]\n"
  422. ]
  423. }
  424. ],
  425. "prompt_number": 111
  426. },
  427. {
  428. "cell_type": "markdown",
  429. "metadata": {},
  430. "source": [
  431. "###Results \n",
  432. "####Overview\n",
  433. "Once this program is finished, I hope to be able to examine how biofilms grow in the presence of different concentrations of nutrients=[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]. Once I know the idea nutrient concentration, I plan to also scan through different ratios of red to green cells and see how or if the cells diffuse. I plan to have plots showing the different growth at each concentration as well as correlation fucntions when looking at the ratios of the red to green cells.\n",
  434. "\n",
  435. "####Hypothetical Results\n",
  436. "As the nutrient concentration increases, I expect to see an increase in biofilm growth as there becomes enough nutrients to grow. This should be followed by a decrease when the concentration becomes to high- with a high amount of nutrient I expect the cells to no longer clump and begin to grow to quickly to form a biofilm. As far as the different colored cells, I do not expect them to diffuse and expect there to be a very low cross correlation."
  437. ]
  438. }
  439. ],
  440. "metadata": {}
  441. }
  442. ]
  443. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement