📄 ---colicin_diversity_0.22_ln(growth)indication.nlogo
字号:
globals [ time ; counts number of time steps calculated R ; random variable for comparison of growth rates active_patch ; x and y coordinates of selected patch add_deathrate ; additional death rate max_growthrate_8 ; maximum growth rate in moore neighborhood of active patch max_growth_8_xcoor ; x-coordinate of patch in moore neighborhood with maximum growthrate max_growth_8_ycoor ; y-coordinate of patch in moore neighborhood with maximum growthrate color_bgcolor ; background color color_wildtype ; color of wild-type bacteria color_hyperimmune ; color of hyper-immune bacteria color_neutral ; color of bacteria with few active (i.e. neutral) genes color_multitoxic ; color of multi-toxic bacteria #total ; actual number of occupied patches, i.e. total bacteria ]patches-own [ occupied ; indicates if the patch is occupied by a bacteria strain. tox_genes ; number of toxicity genes of bacterium [0,9] immune_genes ; number of immunity genes of bacterium growthrate ; growth rate of bacterium, according to number of and penalty for toxicity and immunity genes ] to setup locals [setup_R] clear-all-plots set time 0 set color_bgcolor 9 set color_wildtype 3 set color_hyperimmune blue set color_neutral green set color_multitoxic red ask patches [ set tox_genes 0 set immune_genes 0 set setup_R (random 10000 / init_bact) ifelse setup_R > 1 [ set occupied false ] [ set occupied true ifelse random 2 < 1 [ set tox_genes 3 set immune_genes 3 ] [ set tox_genes 0 set immune_genes 3 ] ] colorize ]endto go set R random 1.0 set active_patch (patch (50 - random 100) (50 - random 100)) ask active_patch [ ifelse occupied [ patch_occupied ] [ patch_empty ] colorize ] set time (time + 1) if time mod 10000 = 0 [ do-plot ] endto patch_occupied ifelse mutation_g > R [ gen_mutation ] [ ifelse (mutation_g + mutation_d) > R [ degen_mutation ] [ ifelse (mutation_g + mutation_d + deathrate) > R [ kill ] [ calc_growthrate ifelse (R > (1 - growthrate / 8)) and not ((count neighbors with [occupied]) > 7) [ grow ] [ calc_add_deathrate if (mutation_g + mutation_d + add_deathrate) > R [ kill ] ] ] ] ] endto patch_empty if (count neighbors with [occupied]) > 0 [ select_max_growthrate_8 if (max_growthrate_8) / 8 > R [ duplicate_patch ] ] endto gen_mutation ifelse random 2 = 1 [ if immune_genes < 9 [ set immune_genes (immune_genes + 1) ] ] [ if (tox_genes < 9) and (tox_genes < immune_genes) [ set tox_genes (tox_genes + 1) ] ] endto degen_mutation ifelse random 2 = 1 [ if immune_genes > 0 and immune_genes > tox_genes [ set immune_genes (immune_genes - 1) ] ] [ if tox_genes > 0 [ set tox_genes (tox_genes - 1) ] ] endto kill set occupied false set immune_genes 0 set tox_genes 0endto grow ask random-one-of neighbors with [occupied = false] [ set occupied true set pcolor pcolor-of active_patch set tox_genes tox_genes-of active_patch set immune_genes immune_genes-of active_patch ]endto select_max_growthrate_8 ask neighbors with [occupied = true] [ calc_growthrate ] set max_growthrate_8 (max values-from neighbors with [occupied = true] [ growthrate ])endto duplicate_patch set occupied true set tox_genes (value-from (one-of patches in-radius 2 with [(occupied = true and growthrate = max_growthrate_8)]) [tox_genes] ) set immune_genes (value-from (one-of patches in-radius 2 with [(occupied = true and growthrate = max_growthrate_8)]) [immune_genes]) endto calc_growthrate set growthrate (1 - (tox_genes)*(penalty_tox) - (immune_genes)*(penalty_imm))endto calc_add_deathrate set add_deathrate (deathrate * ( 1 + ADR_per_toxin ) ^ ((sum values-from neighbors [tox_genes]) - immune_genes))endto colorize ifelse not occupied [ set pcolor color_bgcolor ] [ ifelse immune_genes = 0 and tox_genes = 0 [ set pcolor color_wildtype ] [ ifelse immune_genes < 7 and immune_genes > 3 and tox_genes < 7 and tox_genes > 3 [ set pcolor color_multitoxic ] [ ifelse immune_genes > 5 and tox_genes < 4 [ set pcolor color_hyperimmune ] [ set pcolor color_neutral ] ] ] ] end;;;plotting proceduresto do-plot locals [#neutrals #hyperimmunes #multitoxids #wildtypes mean_immune mean_tox] set-current-plot "Bacteria Growth" set-current-plot-pen "Hyperimmunes" set #hyperimmunes count_hyperimmunes plot #hyperimmunes set-current-plot-pen "Multitoxids" set #multitoxids count_multitoxids plot #multitoxids set-current-plot-pen "Wildtypes" set #wildtypes count_wildtypes plot #wildtypes set-current-plot-pen "Total" set #total count_total plot ln (#total) set-current-plot "Mean Plasmid-No." set-current-plot-pen "MeanImmunity" set mean_immune avg_immune_genes plot mean_immune set-current-plot-pen "MeanToxicity" set mean_tox avg_tox_genes plot mean_tox endto-report count_hyperimmunes locals [#hyperimmunes ] set #hyperimmunes count patches with [immune_genes > 5 and tox_genes < 4] report ln (#hyperimmunes + 0.01)endto-report count_multitoxids locals [#multitoxids ] set #multitoxids count patches with [immune_genes < 7 and immune_genes > 3 and tox_genes < 7 and tox_genes > 3] report ln (#multitoxids + 0.01)endto-report count_wildtypes locals [#wildtypes] report ln (count patches with [ occupied = true and tox_genes = 0 and immune_genes = 0 ])endto-report count_total report count patches with [ occupied = true ]endto-report avg_immune_genes locals [mean_immune] report sum values-from patches [immune_genes] / #totalendto-report avg_tox_genes locals [mean_tox] report sum values-from patches [tox_genes] / #totalend@#$#@#$#@GRAPHICS-WINDOW2831046719450502.188118811881188311000CC-WINDOW282260466395Command CenterSLIDER191026243init_bactinit_bact10001000080001001NILSLIDER19245263278deathratedeathrate0.00.50.10.011NILSLIDER20130261163penalty_toxpenalty_tox0.020.170.060.011NILSLIDER19169262202penalty_immpenalty_imm0.020.20.020.011NILBUTTON195379112SetupsetupNIL1TOBSERVERBUTTON90
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -