# Set path to folder containing the .tar.gz files
pkg_dir <- "C:/Users/yourname/mobps-pkgs" # adjust to your download folder
install.packages(
file.path(pkg_dir, "RandomFieldsUtils_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)
install.packages(
file.path(pkg_dir, "miraculix_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)1 Introduction to MoBPS
1.1 Learning Objectives
By the end of this chapter, you will:
- Understand what MoBPS is and what it can do
- Know how to install MoBPS and its dependencies
- Be able to load the package and verify installation
- Understand the basic workflow of a MoBPS simulation
1.2 What is MoBPS?
MoBPS (Modular Breeding Program Simulator) is an R package for stochastic simulation of breeding programs (Pook et al. 2020). It provides a flexible framework to:
- Create realistic founder populations with complex genetic architectures
- Simulate multiple generations of breeding actions (selection, mating, culling)
- Analyze genetic gain, diversity, inbreeding, and population structure
- Compare different breeding strategies
- Optimize breeding programs for specific goals
1.2.1 Why Simulate Breeding Programs?
Breeding program simulation allows you to:
- Test strategies before implementing them in reality
- Understand trade-offs between genetic gain and diversity
- Optimize selection and mating decisions
- Predict long-term outcomes over many generations
- Train future breeders in a risk-free environment
1.2.2 Key Features
MoBPS offers exceptional flexibility:
- ✅ Works with both plant and animal breeding
- ✅ Supports single or multiple traits
- ✅ Handles additive, dominance, and epistatic effects
- ✅ Simulates realistic genomic data or uses real data
- ✅ Integrates with external prediction software (BLUP, GBLUP, Bayesian)
- ✅ Provides rich visualization and analysis tools
- ✅ Scales from small experiments to large commercial programs
1.3 Installation
1.3.1 System Requirements
MoBPS requires:
- R version 3.0 or higher (R 4.0+ recommended)
- For large-scale simulations:
RandomFieldsUtilsandmiraculix(optional but highly recommended)
1.3.2 Step 1: Platform-Specific Prerequisites
1.3.2.1 Windows Users
Some Windows systems require Rtools:
- Download from: https://cran.r-project.org/bin/windows/Rtools/
- Install the version matching your R version
- Verify with:
pkgbuild::find_rtools()orSys.which("make")
If Rtools exists on Windows you will see the following from Sys.which("make")
"C:\\rtools44\\usr\\bin\\make.exeRemember: You do NOT load
Rtoolswithlibrary()like other packages,Rtoolsis just the compilers needed for your machine
To further test if Rtools is read to go, run the following in the R console:
pkgbuild::check_build_tools(debug = TRUE)If this is not working, you need to add Rtools to your PATH with
Sys.setenv(PATH = paste(
"C:/rtools44/usr/bin",
Sys.getenv("PATH"),
sep = ";"
))However, replace the rtools44 to your version.
Also remember, you can add it to your PATH on Windows using .Rprofile
# Make Rtools available
if (dir.exists("C:/rtools44/usr/bin")) {
Sys.setenv(PATH = paste(
"C:/rtools44/usr/bin",
Sys.getenv("PATH"),
sep = ";"
))
}And remember to replace your version (44 vs 45 or future version).
1.3.2.2 Mac Users
Mac users need Xcode Command Line Tools and gfortran (the Mac equivalent of Rtools). The easiest path is via Homebrew.
Step 1 — Install Xcode Command Line Tools:
xcode-select --installA dialog will appear asking you to install. Click “Install” and wait for it to complete. Verify with:
xcode-select -p
# Should print: /Library/Developer/CommandLineToolsStep 2 — Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"For Apple Silicon (M1/M2/M3) Macs, follow any post-install instructions to add Homebrew to your PATH:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"Step 3 — Install gfortran via Homebrew:
brew install gccThis installs gfortran (bundled with GCC), which R needs to compile packages with Fortran code (including miraculix). Verify:
gfortran --version
# Should print: GNU Fortran (Homebrew GCC ...) ...Step 4 — Optional: Install R via Homebrew (if not already installed):
brew install --cask rOr download the .pkg installer from https://cran.r-project.org/bin/macosx/ if you prefer.
1.3.2.3 Linux Users
Linux setup varies depending on whether you have admin (sudo) privileges or are working on a shared HPC/cluster system.
1.3.2.3.1 Option 1: Desktop/Server with sudo Access
Install build tools, gfortran, and supporting libraries:
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install build-essential gfortran liblapack-dev libblas-dev \
libcurl4-openssl-dev libssl-dev libxml2-dev
# Fedora / RHEL / Rocky Linux / AlmaLinux
sudo dnf install gcc gcc-gfortran gcc-c++ lapack-devel blas-devel \
libcurl-devel openssl-devel libxml2-devel make
# openSUSE / SLES
sudo zypper install gcc gcc-fortran gcc-c++ lapack-devel blas-devel \
libcurl-devel libopenssl-devel libxml2-develInstall R (if not already installed):
# Ubuntu / Debian — add CRAN repo for latest R
sudo apt-get install --no-install-recommends r-base r-base-dev
# Fedora / RHEL
sudo dnf install R1.3.2.3.2 Option 2: HPC / Cluster (module system, no sudo required)
Most HPC systems use Environment Modules (module command). Load R and the required compiler toolchain before starting R or submitting jobs.
Check what’s available:
module avail R
module avail gcc
module avail intel # Intel compilers also workLoad the modules (adjust version numbers to what your cluster provides):
module load R/4.3.1 # or whatever version is available
module load gcc/12.2.0 # provides gfortran
module load openblas # BLAS/LAPACK for linear algebra performanceMake it persistent — add to your ~/.bashrc or ~/.bash_profile so modules load automatically:
echo 'module load R/4.3.1' >> ~/.bashrc
echo 'module load gcc/12.2.0' >> ~/.bashrc
source ~/.bashrcIn SLURM job scripts, load modules at the top of the script:
#!/bin/bash
#SBATCH --job-name=mobps_sim
#SBATCH --cpus-per-task=4
#SBATCH --mem=16G
#SBATCH --time=02:00:00
module load R/4.3.1
module load gcc/12.2.0
Rscript my_simulation.R1.3.2.3.3 Option 3: HPC / Cluster (no sudo, no module system)
If your cluster lacks the needed modules, use Conda/Mamba to install R and compilers entirely in your home directory — no admin privileges needed.
Install Miniforge (lightweight Conda with conda-forge defaults):
# Download and install Miniforge
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash Miniforge3-Linux-x86_64.sh -b -p ~/miniforge3
~/miniforge3/bin/conda init bash
source ~/.bashrcCreate an environment with R and compilers:
conda create -n mobps -c conda-forge r-base r-devtools gfortran_linux-64 \
openblas lapack -y
conda activate mobpsInstall R packages inside the environment (same as normal — no sudo needed):
install.packages("devtools")
devtools::install_github("tpook92/MoBPS", subdir="pkg")Set a personal R library path (useful even outside Conda, e.g. if R is already on the cluster but you want to install your own packages):
# Add to ~/.bashrc
export R_LIBS_USER=~/R/library
mkdir -p ~/R/libraryThen in R, verify it’s on your search path:
.libPaths()
# ~/R/library should appear firstIf MoBPS or its dependencies fail to compile, ask your HPC support team to load or install gcc with Fortran support (gfortran). Most clusters already have this — it may just need a module load gcc to activate it.
1.3.3 Step 2: Install Performance Packages (Optional but Recommended)
RandomFieldsUtils and miraculix provide significant performance improvements for large simulations by using SIMD CPU instructions and OpenMP multi-threading for genomic matrix operations. For serious simulations — especially on HPC — these are effectively required.
- Always install
RandomFieldsUtilsfirst, thenmiraculix - Use exactly version 1.6.0.2 of both — this is the version Torsten currently recommends and that is known to work with MoBPS 1.13.x
- Both packages compile C++ code, so a working compiler toolchain is required (see Step 1 above)
Both packages are distributed as source tarballs from the public MoBPS GitHub repository. Download them first, then install from the local files.
1.3.3.1 Get the Tarballs
Option A — Download via browser:
Go to https://github.com/tpook92/MoBPS and download these two files from the root of the repository:
RandomFieldsUtils_1.6.0.2.tar.gzmiraculix_1.6.0.2.tar.gz
Option B — Download via curl (Mac / Linux / HPC):
mkdir -p ~/mobps-pkgs && cd ~/mobps-pkgs
curl -L -o RandomFieldsUtils_1.6.0.2.tar.gz \
https://raw.githubusercontent.com/tpook92/MoBPS/master/RandomFieldsUtils_1.6.0.2.tar.gz
curl -L -o miraculix_1.6.0.2.tar.gz \
https://raw.githubusercontent.com/tpook92/MoBPS/master/miraculix_1.6.0.2.tar.gzOption C — Download via wget (common on HPC clusters):
mkdir -p ~/mobps-pkgs && cd ~/mobps-pkgs
wget https://raw.githubusercontent.com/tpook92/MoBPS/master/RandomFieldsUtils_1.6.0.2.tar.gz
wget https://raw.githubusercontent.com/tpook92/MoBPS/master/miraculix_1.6.0.2.tar.gz1.3.3.2 Installing on Windows
Windows users need Rtools installed (see Step 1). Then install from the tarballs in R:
Or equivalently from a terminal (Command Prompt or PowerShell):
R CMD INSTALL RandomFieldsUtils_1.6.0.2.tar.gz
R CMD INSTALL miraculix_1.6.0.2.tar.gz1.3.3.3 Installing on Mac
Mac’s default Apple Clang compiler does not support OpenMP, which both packages require. You must first configure R to use GCC (installed via Homebrew in Step 1) and install libomp.
Step 1 — Install OpenMP support via Homebrew:
brew install libompHomebrew will warn that libomp was not symlinked and may suggest setting LDFLAGS and CPPFLAGS in your shell profile. You can ignore this warning for our purposes.
libomp is Apple Clang’s OpenMP library. The warning exists because Homebrew intentionally doesn’t symlink it to avoid conflicts with Xcode. However, the ~/.R/Makevars setup below routes R through Homebrew GCC, which uses its own OpenMP library (libgomp) — it never looks for libomp at all. The LDFLAGS/CPPFLAGS Homebrew suggests are only needed if you were using Apple Clang with OpenMP, which we are not.
Step 2 — Configure R to use Homebrew GCC:
Create (or edit) the file ~/.R/Makevars to override the default compiler:
mkdir -p ~/.RThen create ~/.R/Makevars with the following content (adjust GCC version number to match what brew install gcc installed — check with ls /opt/homebrew/bin/gcc*):
# ~/.R/Makevars
CC=/opt/homebrew/bin/gcc-14
CXX=/opt/homebrew/bin/g++-14
CXX11=/opt/homebrew/bin/g++-14
CXX14=/opt/homebrew/bin/g++-14
CXX17=/opt/homebrew/bin/g++-14
FC=/opt/homebrew/bin/gfortran-14
F77=/opt/homebrew/bin/gfortran-14
OBJC=/opt/homebrew/bin/gcc-14
# OpenMP flags
SHLIB_OPENMP_CFLAGS=-fopenmp
SHLIB_OPENMP_CXXFLAGS=-fopenmp
SHLIB_OPENMP_FFLAGS=-fopenmpls /opt/homebrew/bin/gcc-*
# e.g. /opt/homebrew/bin/gcc-14 → use 14Step 3 — Install from tarballs in R:
pkg_dir <- "~/mobps-pkgs" # adjust to your path
install.packages(
file.path(pkg_dir, "RandomFieldsUtils_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)
install.packages(
file.path(pkg_dir, "miraculix_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)Or from the terminal:
cd ~/mobps-pkgs
R CMD INSTALL RandomFieldsUtils_1.6.0.2.tar.gz
R CMD INSTALL miraculix_1.6.0.2.tar.gzThe packages use x86 SIMD instructions (AVX/SSE) that are not natively available on Apple Silicon. The configure.ac in both packages detects the architecture and falls back to a non-SIMD build automatically — you will still get a working install, just without the maximum SIMD speedup. The OpenMP parallelism still works and provides meaningful gains.
1.3.3.4 Installing on Linux with sudo
# Ubuntu/Debian — ensure build tools are present (see Step 1)
sudo apt-get install libgomp1
# Fedora/RHEL
sudo dnf install libgompThen install from tarballs in R:
pkg_dir <- "~/mobps-pkgs" # adjust to your path
install.packages(
file.path(pkg_dir, "RandomFieldsUtils_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)
install.packages(
file.path(pkg_dir, "miraculix_1.6.0.2.tar.gz"),
repos = NULL, type = "source"
)Or from bash directly:
cd ~/mobps-pkgs
R CMD INSTALL RandomFieldsUtils_1.6.0.2.tar.gz
R CMD INSTALL miraculix_1.6.0.2.tar.gz1.3.3.5 Installing on HPC / Cluster (module system)
Load the required modules first, then install into your personal R library:
module load R/4.3.1
module load gcc/12.2.0 # must include gfortran
# Ensure personal library exists
mkdir -p ~/R/library
export R_LIBS_USER=~/R/libraryThen install from the tarballs:
cd ~/mobps-pkgs
R CMD INSTALL --library=~/R/library RandomFieldsUtils_1.6.0.2.tar.gz
R CMD INSTALL --library=~/R/library miraculix_1.6.0.2.tar.gzAdd the library path to your ~/.bashrc so R always finds these packages:
echo 'export R_LIBS_USER=~/R/library' >> ~/.bashrcAnd add the same to the top of your SLURM job scripts:
#!/bin/bash
#SBATCH --job-name=mobps_sim
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
module load R/4.3.1
module load gcc/12.2.0
export R_LIBS_USER=~/R/library
Rscript my_simulation.R1.3.3.6 Installing on HPC without sudo or modules (Conda)
If your cluster uses Conda/Mamba (see Option 3 in Step 1), the compilers and OpenMP support are already bundled in the environment. Just activate it and install:
conda activate mobps
cd ~/mobps-pkgs
R CMD INSTALL RandomFieldsUtils_1.6.0.2.tar.gz
R CMD INSTALL miraculix_1.6.0.2.tar.gz1.3.3.7 Verify the Installation
In R, confirm both packages load without errors:
library(RandomFieldsUtils)
library(miraculix)
# Check versions
packageVersion("RandomFieldsUtils") # should be 1.6.0.2
packageVersion("miraculix") # should be 1.6.0.2If miraculix loads successfully, MoBPS will automatically detect and use it for faster genomic computations — no extra configuration needed.
1.3.4 Step 3: Install MoBPS
Install the latest MoBPS from GitHub (recommended over CRAN for latest features):
# Install MoBPS from GitHub
devtools::install_github("tpook92/MoBPS", subdir="pkg")Why GitHub over CRAN? - GitHub has the latest features and bug fixes - Regular updates and improvements - CRAN version may be outdated (last update: November 2021)
1.3.5 Step 4: Install Genetic Maps (Optional)
For working with real species data:
# Install MoBPS maps package (includes Ensembl maps)
devtools::install_github("tpook92/MoBPS", subdir="pkg-maps")This package includes genetic maps for common species from Ensembl.
1.3.6 Step 5: Verify Installation
Load the package and check version:
# Load MoBPS
library(MoBPS)
# Check version
packageVersion("MoBPS")
# Should see something like: '1.13.0' or higher1.3.7 Additional Packages
MoBPS can integrate with various prediction software. These are optional and only needed for specific analyses:
# For genomic prediction
install.packages("rrBLUP") # GBLUP
install.packages("BGLR") # Bayesian methods
install.packages("sommer") # Mixed models
# For visualization
install.packages("ggplot2") # Advanced plotting
install.packages("viridis") # Color palettes1.4 Basic Workflow Overview
Every MoBPS simulation follows the same basic structure:
1.4.1 1. Create a Founder Population
Use creating.diploid() to initialize your population:
population <- creating.diploid(
nsnp = 1000, # Number of SNP markers
nindi = 100, # Number of individuals
n.additive = 100, # Number of QTLs
mean.target = 100 # Mean breeding value
)1.4.2 2. Simulate Breeding Actions
Use breeding.diploid() to perform selection, mating, and other actions:
population <- breeding.diploid(
population,
selection.size = c(10, 10), # 10 males, 10 females
breeding.size = c(50, 50) # Generate 50 male, 50 female offspring
)# phenotype generation 2
population <- breeding.diploid(
population,
phenotyping.gen = 2
)1.4.3 3. Extract and Analyze Results
Use get.*() functions to extract information:
# Get breeding values of gen 2
bv <- get.bv(population, gen = 2)
# Get phenotypes of gen 2
pheno <- get.pheno(population, gen = 2)
# Calculate inbreeding for gen 2
inbreeding <- inbreeding.exp(population, gen = 2)1.4.4 4. Visualize Results
Use built-in plotting functions:
# Track genetic gain
bv.development(population)
# PCA plot
get.pca(population, gen = 1:2)
# Kinship development
kinship.development(population, gen = 1:2)1.5 The Population Object
The core of MoBPS is the population object (usually called population or pop):
- It’s an R list containing all simulation data
- Stores genotypes, phenotypes, pedigrees, trait architectures
- Updated by each
breeding.diploid()call - Can be saved/loaded for reproducibility
Think of it as a complete database of your breeding program.
1.6 Getting Help
1.6.1 Within R
# Function documentation
?creating.diploid
?breeding.diploid
# See all MoBPS functions
help(package = "MoBPS")1.6.2 Online Resources
- GitHub: https://github.com/tpook92/MoBPS
- Web Interface: https://www.mobps.de
- Email Support: Torsten.pook@wur.nl
1.6.3 Important Notes
MoBPS won’t stop you from making biologically impossible settings (e.g., collecting milk records from bulls). Always validate your simulation setup makes biological sense!
MoBPS has many parameters, but you only need a few for most simulations. Start simple, then add complexity as needed. Use Ctrl+F to search the documentation for specific features.
1.7 What’s Next?
In the next chapter, we’ll dive into core concepts that are essential for understanding how MoBPS works:
- Individual grouping (generations, databases, cohorts)
- The population list structure
- How traits are represented
- Time flow in simulations
Let’s continue to Chapter 2: Core Concepts!
1.8 Summary
- MoBPS is a flexible R package for breeding program simulation
- Install from GitHub for latest features
- Optional performance packages (
miraculix) are highly recommended - Basic workflow: Create → Breed → Analyze → Visualize
- The population object stores all your simulation data
- Help is available through documentation and direct contact