Bio 14 Lab 2 model 1

Bio 14 Lab 2 model 1 preview image

1 collaborator

Default-person James Johnson (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.2 • Viewed 42 times • Downloaded 1 time • Run 0 times
Download the 'Bio 14 Lab 2 model 1' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; this is the most up-to-date version



globals [
  regions ; a list of regions definitions, where each region is a list of its min pxcor and max pxcor
]

breed [ blue-strains blue-strain ]

breed [ red-strains red-strain ]

;;red-strains-own [red-resistance-cost]
;;blue-strains-own [blue-resistance-cost] ; removing cost of resistance as a paramter for now

turtles-own [ resistant? energy mutation-rate cost-of-repair benefit? benefit-gain] ;; some variables that apply to both strains, ;resistance-cost removed

patches-own [
  region ; the region that the patch is in, patches outside all regions have region = 0
  antibiotic ;
]

to setup ; this procedure sets up the "world" into 2 different regions. It contains a few subprocedures described next
  clear-all
  setup-regions 2
  color-regions
  ; Finally, distribute the turtles in the different regions
  setup-turtles
  if (resistance + lethal + metabolic-benefit) > 100.00 [user-message ("Mutation rates should not sum to more than 100%")] ; this message appears to warn users about mutation rate settings
  reset-ticks
end 

to color-regions ;this subprocedure colors the regions
  ; The patches with region = 0 act as dividers and are
  ; not part of any region. All other patches get colored
  ; according to the region they're in.
  ask patches with [ region != 0 ] [
    set pcolor 1 ;; what color is this - started at  times 10
    set plabel-color pcolor + 0
    ;set plabel region
    check-antibiotic
  ]
end 

to setup-turtles ; this subprocedure creates the strains

  foreach n-values length regions [ [?1] -> ?1 + 1 ] [ [?1] ->
    let region-patches patches with [ region = ?1 ]
    create-blue-strains initial-blue-strain-population [
      move-to one-of region-patches
      if (count other turtles-here > 1) [move-to one-of region-patches]
      set shape "circle"
      set size 0.15
      set color blue
      set resistant? false ;; they all start not resistant
      ;;if ( show-resistance? ) [ show-resistance ]
      set energy random blue-life-span ;;they all start out with some amt of energy - a random value between 0 and blue-life-span
      set mutation-rate blue-mutation-rate
      set benefit? false ; they all start without beneficial mutations
    ]
    create-red-strains initial-red-strain-population [
      move-to one-of region-patches
      set shape "circle"
      set size 0.15
      set color red
      set resistant? false ;; they all start not resistant
      ;;if ( show-resistance? ) [ show-resistance ]
      set energy random red-life-span ;;they all start out with some amt of energy
      set mutation-rate red-mutation-rate
      set benefit? false
    ]
  ]
end 

to go
  every 0.1 [ ; can be manipulated to make things happen faster
    ask turtles [ ; below are the things turtles do every half tick
      move ; see details under this procedure
      metabolize ; see details under this procedure
      mutate ; see details under this procedure
      if ( count other turtles-here > 20) [ die ] ;; this is where carrying capacity is specified at the moment
      if ( [antibiotic] of patch-here = true and not resistant? ) [ die ] ;; womp womp...notice antibiotic is 100% lethal
      if (energy <= 0) [die] ;; so tired...
      reproduce ;; see details under this procedure
    ;;if ( show-resistance? ) [ show-resistance ]
    ;if ( show-benefit?) [show-benefit] ;; obviously
    ;set-resistance-values
    ;]

   ; ifelse (resistant?)
  ; [
 ; if cost-of-resistance = "high" [set resistance-cost 5]
 ; if cost-of-resistance = "low" [set resistance-cost 2]
 ; if cost-of-resistance = "none" [set resistance-cost 0]
 ; ]
 ;  [set resistance-cost 0]
show-resistance
  ]
    check-antibiotic ; this checks the status of the antibiotic so that it can be changed mid run
    check-mutation-rates ; this checks to see if the mutation rate has been changed mid-run
  if ( count turtles = 0 ) [ stop ] ; the simulation stops if all the turtles die
  update-plots
  display
    ;if vid:recorder-status = "recording" [ vid:record-interface ]
  tick
  ]
end 

to move ; turtle procedure

  ; First, save the region that the turtle is currently in:
  let current-region region
  ; Then, after saving the region, we can move the turtle:
  right random 30
  left random 30
  forward 0.25
  ; Finally, after moving, make sure the turtle
  ; stays in the region it was in before:
  keep-in-region current-region
end 

to check-mutation-rates
  ask red-strains [if red-mutation-rate != mutation-rate [user-message ("You cannot change the mutation rate in the middle of a run. Restart the model!")]]
  ask blue-strains [if blue-mutation-rate != mutation-rate [user-message ("You cannot change the mutation rate in the middle of a run. Restart the model!")]]
end 

to show-resistance ;; turtle procedure that colors bacteria to show resistance
 ifelse resistant?
 [ifelse (breed = red-strains) [ set color red + 3] [set color blue + 3]] ; if resistant set to lighter colors
 [ifelse (breed = red-strains) [ set color red ] [set color blue]] ; otherwise keep original colors
end 

to show-benefit ;; turtle procedure that colors bacteria to show resistance
 ifelse benefit?
 [ifelse (breed = red-strains) [ set color yellow] [set color green]] ; if resistant set to lighter colors
 [ifelse (breed = red-strains) [ set color red ] [set color blue]] ; otherwise keep original colors
end 

to mutate ;; turtle procedure

  if random-float 100 < mutation-rate [ ;; random float chooses a number between 0-100. If that number is less than mutation-rate (set by a slider on the interface) then...

    if random-float 100 < resistance ;; roll the resistant dice (this used to be ifelse for some reason)
    [ ;; this is the if part
      if ( not resistant? ) [ ;; toggle the resistance
      set resistant? true ] ;; YOUR POISON IS FUTILE!!
      ;[set resistant? false]
        ;[ if random-float 100 < 20 [set resistant? false ]
         ;] ;; back mutations set to 20%
    ]

     ;this is the else part
      if random-float 100 < lethal [ ;; roll the lethal dice...switch the greater than to less than
        die ;; end of the line :(
      ]


    ifelse benefit? [set benefit-gain random 2] [set benefit-gain 0] ; make this a random value - this specifies the value of benefit from beneficial mutation
    if random-float 100 > ( 100 - metabolic-benefit)
    [if ( not benefit?)
      [set benefit? true]
    ]


  ]
end 

to metabolize ;; turtle procedure that sucks your life away
  let total-cost ( cost-of-repair  + 1) ;; metabolic cost is sum of all costs, + resistance-cost removed
  set energy (energy - total-cost + benefit-gain)
end 

to reproduce ;; turtle procedure
  ;; i guess we'll make all the bacteria reproduce all the time.
  set energy energy / 2 ;; takes money to make money - but what is the point of this? sets effective lifespan to half so changed it to same energy as parents
  hatch 1 [ ;; they're cloning, so inherits any mutation including resistance (or not) and they are the same strain as parent
    rt random 360
    let current-region region
    fd random-float .5 ;; move a bit
    keep-in-region current-region
    ifelse breed = red-strains [set energy red-life-span] [set energy blue-life-span] ;; so lively
  ]
end 

to check-antibiotic
  ifelse antibiotic? [
    ask patches with [pxcor >= 0] [set pcolor grey set antibiotic true]
    ask patches with [pxcor < 0] [set antibiotic false]
  ]
  [
  ask patches with [pxcor >= 0] [set pcolor 22 set antibiotic false]
    ask patches with [pxcor < 0] [set antibiotic false]
  ]
end 

;;to plate-on-agar
 ;; let blue-plated-cells round concentration / 100 * count blue-strains
 ;;set blue-plated-cells count blue-strains - blue-plated-cells
 ;; ask n-of blue-plated-cells blue-strains [
;;    die]
;;  let red-plated-cells round concentration / 100 * count red-strains
;; set red-plated-cells count red-strains - red-plated-cells
;;  ask n-of red-plated-cells red-strains [
;;    die]
;;end

;;to plate-on-antibiotic
 ;; let blue-plated-cells round concentration / 100 * count blue-strains
;; set blue-plated-cells count blue-strains - blue-plated-cells
;;  ask n-of blue-plated-cells blue-strains [
;;    die
;;  ]
;;  ask blue-strains [
;;    if not resistant? [die]]
;;  let red-plated-cells round concentration / 100 * count red-strains
;; set red-plated-cells count red-strains - red-plated-cells
;;  ask n-of red-plated-cells red-strains [
;;    die]
;;  ask red-strains [
;;    if not resistant? [die]]
;;end

to setup-regions [ n ]
  ; First, draw some dividers at the intervals reported by `region-divisions`:
  foreach region-divisions n draw-region-division
  ; Store our region definitions globally for faster access:
  set regions region-definitions n
  ; Set the `region` variable for all patches included in regions:
  (foreach regions (n-values n [ [?1] -> ?1 + 1 ]) [ [?1 ?2] ->
    ; We're looping through region definitions (?1) and region numbers (?2)
    ask patches with [ pxcor >= first ?1 and pxcor <= last ?1 ] [ set region ?2 ]
  ])
end 

to-report region-definitions [ n ]
  ; The region definitions are built from the region divisions:
  let divisions region-divisions n
  ; Each region definition lists the min-pxcor and max-pxcor of the region.
  ; To get those, we use `map` on two "shifted" copies of the division list,
  ; which allow us to scan through all pairs of dividers
  ; and built our list of definitions from those pairs:
  report (map [ [?1 ?2] -> list (?1 + 1) (?2 - 1) ] (but-last divisions) (but-first divisions))
end 

to-report region-divisions [ n ]
  ; This procedure reports a list of pxcor that should be outside every region.
  ; Patches with these pxcor will act as "dividers" between regions.
  report n-values (n + 1) [ [?1] ->
    [ pxcor ] of patch (min-pxcor + (?1 * ((max-pxcor - min-pxcor) / n))) 0
  ]
end 

to draw-region-division [ x ]
  ; This procedure makes the division patches grey
  ; and draw a vertical line in the middle. This is
  ; arbitrary and could be modified to your liking.
  ask patches with [ pxcor = x ] [
    set pcolor grey + 1.5
  ]
  create-turtles 1 [
    ; use a temporary turtle to draw a line in the middle of our division
    setxy x max-pycor + 0.5
    set heading 0
    set color grey - 3
    pen-down
    forward world-height
    set xcor xcor + 1 / patch-size
    right 180
    set color grey + 3
    forward world-height
    die ; our turtle has done its job and is no longer needed
  ]
end 

to keep-in-region [ which-region ] ; turtle procedure

  ; This is the procedure that make sure that turtles don't leave the region they're
  ; supposed to be in. It is your responsability to call this whenever a turtle moves.
  if region != which-region [
    ; Get our region boundaries from the global region list:
    let region-min-pxcor first item (which-region - 1) regions
    let region-max-pxcor last item (which-region - 1) regions
    ; The total width is (min - max) + 1 because `pxcor`s are in the middle of patches:
    let region-width (region-max-pxcor - region-min-pxcor) + 1
    ifelse xcor < region-min-pxcor [ ; if we crossed to the left,
      set xcor xcor + region-width   ; jump to the right boundary
    ] [
      if xcor > region-max-pxcor [   ; if we crossed to the right,
        set xcor xcor - region-width ; jump to the left boundary
      ]
    ]
  ]
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There is only one version of this model, created 8 months ago by James Johnson.

Attached files

File Type Description Last updated
Bio 14 Lab 2 model 1.png preview Preview for 'Bio 14 Lab 2 model 1' 8 months ago, by James Johnson Download

This model does not have any ancestors.

This model does not have any descendants.