install.packages("slendr")Appendix B — Installation – slendr
The chapters of this book focused on population genomics and simulations rely pretty much exclusively on the R package slendr, plus an assortment of other useful R packages for data science (all of which will be automatically installed alongside slendr). Below are instructions how to prepare everything that will be needed before the start of our workshop.
Please don’t hesitate to get in touch with me over email at contact [snail sign] bodkan.net if you run into any problems with this setup procedure or anything else related to this! If you’re reading this in preparation for one of my in-person workshops, you can also catch me whenever you see me at the teaching venue.
Installation steps
Note: It will be great if you do this setup on your personal laptop. Getting everything to run locally is often much easier than trying to install things on shared clusters or other HPC environments.
I assume you already have R and RStudio installed on your computer (any version will do). RStudio is not strictly necessary, but convenient.
Open RStudio and copy this into the R console to install the slendr package:
Note: If you get an error during the installation, please copy-and-paste the entire output from this command and send it to me via email.
- Paste this little testing simulation script into the R console to make sure that everything works correctly. Don’t read too much into the meaning of the code, understanding (and being able to program) all this and more will be the point of our workshop.
Note: If you managed to successfully get through the steps 1-2 above, this simulation should finish running without any problems. If it does not work, please copy-and-paste the entire output this script produces in your R console (including the error) and send it to me via email.
library(slendr)
init_env(uv = TRUE)
A <- population("popA", time = 8000, N = 1000)
B <- population("popB", time = 4000, N = 1000, parent = A)
C <- population("popC", time = 4000, N = 1000, parent = A)
D <- population("popD", time = 3000, N = 1000, parent = C)
gf <- list(
gene_flow(from = B, to = D, start = 1000, end = 800, proportion = 0.2),
gene_flow(from = C, to = D, start = 1000, end = 800, proportion = 0.1)
)
model <- compile_model(
populations = list(A, B, C, D),
gene_flow = gf, generation_time = 30
)
ts <- msprime(model, sequence_length = 1e6, recombination_rate = 1e-8)
ts
## ╔═══════════════════════════╗
## ║TreeSequence ║
## ╠═══════════════╤═══════════╣
## ║Trees │ 907║
## ╟───────────────┼───────────╢
## ║Sequence Length│ 1,000,000║
## ╟───────────────┼───────────╢
## ║Time Units │generations║
## ╟───────────────┼───────────╢
## ║Sample Nodes │ 8,000║
## ╟───────────────┼───────────╢
## ║Total Size │ 1.4 MiB║
## ╚═══════════════╧═══════════╝
## ╔═══════════╤══════╤═════════╤════════════╗
## ║Table │Rows │Size │Has Metadata║
## ╠═══════════╪══════╪═════════╪════════════╣
## ║Edges │20,241│632.5 KiB│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Individuals│ 4,000│109.4 KiB│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Migrations │ 0│ 8 Bytes│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Mutations │ 0│ 16 Bytes│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Nodes │17,509│478.8 KiB│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Populations│ 4│343 Bytes│ Yes║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Provenances│ 1│ 3.4 KiB│ No║
## ╟───────────┼──────┼─────────┼────────────╢
## ║Sites │ 0│ 16 Bytes│ No║
## ╚═══════════╧══════╧═════════╧════════════╝The outcome of this script should approximately match what you see above (minus some statistical noise manifesting in your numbers in the summary being slightly different).
- Installing a couple of bonus R packages
In order to be able to run my solutions to some of the exercises (particularly some more advanced optional bonus exercises), a couple of additional R packages might be useful. Feel free to only install those if you run into them at a later point.
You can install those packages with this command:
install.packages(c("combinat", "cowplot", "smartsnp", "viridis", "ggrepel"))If you’ve made it this far, you’re good to go!