680 likes | 818 Views
Modelling Course in Population and Evolutionary Biology. Introduction. 3 June 2012, Z ürich. The Course Getting Started with R Level 1 Modules R continued Level 2 Modules Teams form (2 x 15 min break). 1. The Course. People. Prof. Sebastian Bonhoeffer Course Director.
E N D
Modelling Course in Population and Evolutionary Biology Introduction 3 June 2012, Zürich The Course Getting Started with R Level 1 Modules R continued Level 2 Modules Teams form (2 x 15 min break)
People Prof. Sebastian Bonhoeffer Course Director Viktor Müller Course Instructor
People: module developers • Martin Ackermann • Tobias Bergmiller • Sebastian Bonhoeffer • Lucy Crooks • Florence Debarre • David Fouchet • Nicole Freed • Roger Kouyos • Dusan Misevic • Viktor Müller • Roland Regoes • Olin Silander • Orkun Soyer
Goals • To get familiar with basic approaches in the modelling of biological processes • To learn to appreciate the excitement and utility of computational modelling in biology • To obtain conceptual insight into interesting biological questions • To learn team work • To see a project through from beginning to end
Focus: how to make these transitions? • Foreground: modelling • Background: biology + math computer implementation biological problem math model/ algorithm interpretation of model results
Time table Place: CHN F 46 Daily schedule: 8.30-12.30 Work on modules 12.30-13.30 Lunch break 13.30-17.30 Work on modules Last day (14 June): presentations in the afternoon • NOTES: • You are free to take short breaks during the work sessions. • Please, report your absence in advance. Breakdown 10 days total Introduction: 3/4 day Module 1: ~3 days Module 2: 5 days Finalizing presentations: ½ day Presentations: ½ day • Recommendation: • Switch to Module 2 on Thursday/Friday. • Prepare slides on the fly. flexible
Team and module choice • Each team should ideally have at least one member with some experience in programming • Teams should choose two modules that use different methods (topics might be connected) • The same module can be chosen by several teams • Extensive development of a level 1 module may be accepted as level 2 at the instructor’s decision.
Team work • Discuss the problems. • Consult about the implementation. • Discuss the results. BUT: write code independently (as well) • Keep a working script for the solution of each exercise and a record of the results to help us check and discuss your progress. • Instructors help as needed
Evaluation Marks will be based on • performance during the course • instructors monitor progress • completion of modules • model design • implementation (functionality of R code) • “scientific” results • final presentation • ppt or pdf slideshow on level 2 module results • get the message across Important note: to enable individual evaluation, each team member should be given responsibility for particular tasks and participate in the final presentation. Students with no prior knowledge of R should also be able to achieve the highest mark.
Webpage • modules • R resources • practical information http://www.tb.ethz.ch/education/model
How To • Connect to the net: • wi-fi network: public/eth • ETH or guest account to access external sites • VPN or website login • Print: • send to public printers (VPP) • vpp.ethz.ch (easy to remember central link) • http://idvpp01.ethz.ch/vpppdf.html (direct link for pdf printing) • the nearest printer is CHNF43.
2. Getting Started with R Note: this section focuses on getting started with R and on some useful tricks. You should certainly read the designated chapters of ‘Introduction to R’ and you are advised to have the R reference card at hand.
What is R? • R is an integrated suite of software facilities for data manipulation, calculation and graphical display. • It is often used for statistics, but it can do much more. • R is a free implementation of the S language.
Download and install R go to http://www.r-project.org/
Download and install RStudio go to http://rstudio.org/ available for all platforms: Win/Mac/Linux
Using R • Type commands directly at the prompt (command line/console) • separate commands by newline (<ENTER>) or semicolon (<;>) • use vertical arrows to recall previous commands • Load code from the file menu or with source(“filename”) • Code is written as a plain text file. • on Mac: use R’s internal editor or RStudio • on Windows: Rstudio • Linux: Rstudio or RKWard
Getting help • Type help(command) or ?command • Or: go to help menu. • Careful: versions might differ. If these approaches fail to help… • call us.
Exiting R • Type quit() or q() • or close window. • You can save all objects at quitting into .RData. Starting R from the same directory, the workspace is loaded and you can continue working where you stopped it. Keep in mind: if you do this, you may have objects (variables, functions) defined that you have long forgotten about. Recommendation: use this feature only for short interruptions in your work, but not on a day-to-day basis.
A sample session switch to R/RStudio download: http://www.tb.ethz.ch/education/model/sample.r
The organization of modules • Webpage: brief description + links for download • Reader (PDF) • biological and modelling background • instructions to develop the model • exercises (basic + advanced/additional) • Starting R script (not all modules) • Glossary • Literature & Weblinks (optional reading) • Unless otherwise stated in the reader, completion of a module requires solving all basic exercises.
List of modules • Level 1 • The logistic difference equation and the route to chaotic behaviour • SIR models of epidemics • Stochastic effects on the genetic structure of populations • Within-host HIV dynamics: estimation of parameters • Within-host HIV dynamics: the emergence of drug resistance • Level 2 • Discrete vs. continuous time models of malaria infections • Evolution of the sex ratio • Network models of epidemics • Rock-paper-scissors dynamics in space • Spatial cooperation games • Stability and complexity of model ecosystems: Are large ecosystems more stable than small ones? • Stochastic simulation of epidemics • Unstable oscillations and spatial structure: The Nicholson-Bailey model of host-parasitoid dynamics
The logistic difference equation andthe route to chaotic behaviour • Basic problem: • Many species have non-overlapping generations and may therefore be described better in discrete time • Logistic growth: self-limitation • Discrete steps allow for overshooting oscillations, chaos • General approach: iterate difference equation • Concepts • Chaos • Periodic behaviour • Bifurcations
The logistic difference equation and the route tochaotic behaviour • Methods • time plots • phase diagrams • bifurcation diagrams • Questions • What types of behaviour are possible in the LDE? • What defines chaotic behaviour? • Analyse bifurcation diagram • Introduce space
SIR models of epidemics • Basic problem: what factors govern the spread of infectious diseases? • General approach • numerical integration of ODE model • Concepts • basic reproductive ratio • herd immunity • Methods • time plot • phase portrait
SIR models of epidemics • Questions • What are the conditions for the outbreak of an epidemic? • What fraction of a population is going to be infected? • Can partial vaccination be protective? • Model treatment, drug resistance and birth-death dynamics
Stochastic effects on the geneticstructure of populations • Basic problem • Genetic drift can destroy variation, counteract selection and build up associations between loci. • General approach • Simple population genetic models with mutation, selection, recombination and random sampling of offspring • Concepts & methods • Iteration of discrete time population genetics model • Interplay of selection and drift • Benefits of recombination • Sampling from binomial/multinomial distribution • Questions • How does drift reduce the diversity that mutation builds up? • How does drift affect the elimination of detrimental alleles through selection? • How do bottlenecks affect the diversity at neutral and selected loci? • What do effective population sizes tell about the magnitude of stochastic effects?
Within-host HIV dynamics #1:estimation of parameters • Basic problem • The apparent latency of HIV infection conceals a highly dynamic steady state. Perturbation by drug treatment reveals the dynamics. • General approach • Estimation of decay parameters by fitting simple ODE models to real and simulated treatment data.
Within-host HIV dynamics #1:estimation of parameters • Concepts & methods • Model fitting – Parameter estimation by non-linear minimization. • Lesson: no such thing as an “objective” estimate. • Numerical simulation of ODEs. • Questions • What factors influence the quality of parameter estimation? • How does random noise (measurement error) affect the estimation? • What if treatment is not 100% effective? • What is the effect of long-lived virus-producing cells?
Within-host HIV dynamics #2:the emergence of drug resistance • Basic problem • Mutations in the enzymes of HIV can render the virus resistant to drugs. • General approach • ODE models to simulate wild-type and mutant virus.
Within-host HIV dynamics #2:the emergence of drug resistance • Concepts & methods • Numerical simulation of ODEs • Mutation-selection equilibrium • Questions • What are the conditions for the emergence of drug resistance? • How does the efficacy of the drugs affect the time to the emergence of resistance? • Resistance mutations can exist in a mutation-selection equilibrium even before treatment: how does this affect the emergence of resistance under therapy? • What is the advantage of administering a combination of different drugs? • Devise optimal treatment strategy
A sample session: function definition distance <- function(x,y){ diff1 = x[1] - y[1] diff2 = x[2] - y[2] diff = sqrt(diff1^2 + diff2^2) diff } > source(“distance.r”) > point1 <- c(5,3) > point2 <- c(1,6) > distance(point1,point2) Modify the function to calculate distance in n dimensions.
Demo: a simple reaction kinetics model k1 k3 E + S C E + P k2 E+C = constant : etot C = etot - E S+C+P = constant : stot P = stot – S – C = stot – etot – S + E
Demo: a simple reaction kinetics model k1 k3 E + S C E + P k2
Demo: a simple reaction kinetics model k1 k3 E + S C E + P k2
Demo: a simple reaction kinetics model • source and read reaction.r • tip: read the main program first, then the functions • create pdf figure • try: • simulation==copy • simulation-copy • comment pdf() and print on screen
Unstable oscillations and spatial structure: The Nicholson-Bailey model of host-parasitoid dynamics • Basic problem • A discrete-time model of host-parasite interactions is unstable. Can the implementation of space stabilize the system? • General approach • Model host-parasite interactions and dispersal on a 2D lattice.
Unstable oscillations and spatial structure: The Nicholson-Bailey model of host-parasitoid dynamics • Concepts & methods • Simulation of simple two-species difference equations • Simulate spatial structure and observe emerging patterns • Questions • Why is the simple NB model unstable? • What is the effect of spatial structure? • What is the effect of lattice size and boundary conditions? • Do initial conditions affect the outcome? • Can parasitoids facilitate the coexistence of different host types?
Spatial cooperation games • Basic problem: altruistic behaviour decreases the fitness of the actor. So how can it evolve and be maintained? • General approach: simulate iterated cooperation games in unstructured and spatially structured populations. • Concepts • Game theory: Prisoner’s dilemma and snowdrift games. • Spatial structure and the evolution of cooperation. • Methods • Spatially explicit simulation of population interactions on a lattice • Cellular automaton
Spatial cooperation games Questions • How does spatial structure affect the evolution of cooperation? • What is the effect of the payoff parameters (cost, benefit)? • Investigate the effects of: • neighbourhood size (3,4,6) • updating scheme (synchronous vs. asynchronous; pair-wise vs. multiple competitions) • population size (500, 1000, 2000) • heterogeneous environment … on the evolution of cooperation and the significance of spatial structure.
Rock-paper-scissors dynamics in space • Basic problem: can intransitive fitness interactions facilitate the maintenance of diversity? • General approach: model local competition in a cellular automaton • Concepts • intransitive interaction: A<B, B<C, C<A • density dependent selection < < <
Rock-paper-scissors dynamics in space Questions: • How does the maintenance of diversity depend on • the type and strength of fitness interactions • initial population size and species frequencies • The distance over which organisms interact/disperse? • What factors affect the magnitude of population fluctuations? • How do the dynamics of the system change when there are greater numbers of species interacting? • What is the effect of disturbance (e.g. local fires) on the maintenance of diversity?
Stability and complexity in model ecosystems • Basic problem: Does complexity help stability? • General approach: study stability of randomly generated multi-species Lotka-Volterra systems. • Concepts & methods • Connectivity, diversity and stability of an ecosystem/network • Numerical simulation of (large) systems of ordinary differential equations • Questions • How does ecosystem stability depend on the size (i.e. number of species) and connectivity of the ecosystem? • What are useful measures of ecosystem stability? • Does the coexistence of a set of species depend on the order in which they were introduced into an ecosystem? • How does the ecosystem respond to the removal or invasion of a species? • How does stability change if some interactions are predatory?
Discrete versus continuous-time modelsof malaria infections • Basic problem • Malaria parasites reproduce in discrete generations. What is the effect of simplifying this to continuous-time models?
Discrete versus continuous-time modelsof malaria infections • General approach • Compare discrete and continuous-time models of malaria. • Concepts & methods • Numerical simulation of ODEs and difference equations • Trade-offs and evolutionary optimum • Questions • How to parameterize the models to achieve maximal equivalence? • Can you obtain identical behaviour? • What level of gametocyte investment maximises transmission? • Model an immune function/compartments/variable investment
Evolution of the sex ratio • Basic problem: why is the typical sex ratio 1:1? • General approach • Simulate a population of males and females • Sex ratio of offspring determined by a diploid locus in the mother • Introduce sex ratio mutants and run until evolutionary equilibrium • Concepts & methods • Evolutionary optimization • Individual-based modelling • Stochastic simulation • Questions • Optimal sex ratio for various inheritance schemes of the SR gene • What happens if the sexes have different survival or cost? • What if the SR gene is located on a sex chromosome?
Stochastic simulation of epidemics • Basic problem • Introduce stochasticity and discrete populations into the SIR model • General approach • Stochastic modelling with the Gillespie algorithm • Concepts & methods • Comparison of deterministic and stochastic models • Basic reproductive ratio, herd immunity etc • Questions • What is the extinction probability of the infection for different values of R0? • Does the average dynamics of the stochastic model differ from the deterministic SIR model? • Are population sizes across runs normally distributed?