Skip to main content

Appendix A — Installation instructions

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 (most 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

  1. I assume you already have R and RStudio installed on your computer (any reasonably recent version will do).

  2. Open RStudio and copy this into the R console to install the slendr package:

install.packages("slendr")

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.

  1. Paste this little testing simulation script into the R console to make sure that everything works correctly.
library(slendr)
init_env(uv = TRUE)

pop <- population("pop", time = 1, N = 1000)
model <- compile_model(list(pop), generation_time = 1, simulation_length = 1000)
ts <- msprime(model, sequence_length = 1e6, recombination_rate = 1e-8)

ts
## ╔═══════════════════════════╗
## ║TreeSequence               ║
## ╠═══════════════╤═══════════╣
## ║Trees          │        282║
## ╟───────────────┼───────────╢
## ║Sequence Length│  1,000,000║
## ╟───────────────┼───────────╢
## ║Time Units     │generations║
## ╟───────────────┼───────────╢
## ║Sample Nodes   │      2,000║
## ╟───────────────┼───────────╢
## ║Total Size     │  351.9 KiB║
## ╚═══════════════╧═══════════╝
## ╔═══════════╤═════╤═════════╤════════════╗
## ║Table      │Rows │Size     │Has Metadata║
## ╠═══════════╪═════╪═════════╪════════════╣
## ║Edges      │5,039│157.5 KiB│          No║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Individuals│1,000│ 27.4 KiB│          No║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Migrations │    0│  8 Bytes│          No║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Mutations  │    0│ 16 Bytes│          No║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Nodes      │4,239│115.9 KiB│          No║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Populations│    1│222 Bytes│         Yes║
## ╟───────────┼─────┼─────────┼────────────╢
## ║Provenances│    1│  1.5 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).


If the above script fails during the init_env(uv = TRUE) step, do the following.

First, go to Session -> Restart R in the RStudio menu.

Then paste this command into the R console:

slendr::setup_env(agree = TRUE)

When the command finishes running, copy-paste the following version of the above-mentioned testing script into the R console (note that the uv = TRUE is missing in the init_env() function — I’m happy to explain during the workshop).

library(slendr)
init_env()

pop <- population("pop", time = 1, N = 1000)
model <- compile_model(list(pop), generation_time = 1, simulation_length = 1000)
ts <- msprime(model, sequence_length = 1e6, recombination_rate = 1e-8)

ts

  1. 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", "cowplot", "forcats", "readr"))

If you’ve made it this far, you’re good to go!

Optional

The following isn’t something you need to do before the start of the workshop. It’s something we can deal with towards the end of the workshop (if it even becomes necessary).

Running heavy slendr simulations

If you decide you’d like to run some really big simulations (perhaps during the open-ended sessions at the end of the workshop) it might be necessary to run your models on a bigger computing server. I suspect you have some remote computing facilities available for doing heavy bioinformatics work, etc.

If that’s the case, you’ll want to also install and setup slendr and the R packages mentioned above on this remote server as well. Just repeat the same instructions and you should be good to go.

Running third-party software

Similarly, in the open-ended workshop sessions, you will have the opportunity to apply the modeling techniques learned throughout the exercises in a practical context of your own research. As you work on the exercises, you might get an inspiration for applying this or that technique to study a particular aspect of your research question, which might involve third-party software such as qpAdm, IBDSeq, DATES, ADMIXTURE/STRUCTURE etc. If that ends up being the case, I suggest you try to install slendr on the (again, probably remote?) computer you normally use to do your research.