Load the bundled demo dataset

Load the bundled demo dataset

Description

Returns a small, deterministic genomic dataset bundled with the package, intended for examples, vignettes, and tests.

Usage

load_data(size = c("small", "large"))

Arguments

size character, either “small” (default) or “large”.

Details

Two scales are bundled: size = “large” (n=200, p=500, n_qtl=20) and size = “small” (default; n=100, p=50, n_qtl=5) that runs during R CMD check –examples. Both have the same family structure (10 full-sib families) and the same 12-field shape, so consumer code does not have to branch on size.

The data simulates a small breeding-style population: 10 full-sib families (each from one sire-dam founder pair). The founders are kept in the pedigree only (no genotype, no phenotype). A within-family 80/20 train/test split is bundled so every test individual has its full-sibs in training – this is the regime where genomic prediction methods deliver high accuracy.

Value

A list with the following elements (dimensions shown for size = “large” / size = “small”):

snp
Integer matrix \(n \times p\) of biallelic SNP dosages (values 0/1/2). Rownames are individual IDs IND001..INDn; colnames are SNP001..SNPp. Passes directly into masreml(markers = list(snp_add = snp)) and build_G_snp(). Dimensions: 200 x 500 (large) / 100 x 50 (small).
mh
Integer matrix \(n \times (2 \cdot n_{blocks})\) of microhaplotype allele codes. Columns alternate strand 1 / strand 2 per block. The attr(mh, “block_id”) attribute maps each column to its block. Consumable directly by build_G_mh(mh_list = mh) via the haplotype-matrix auto-detection path. Dimensions: 200 x 500 with 250 blocks (large) / 100 x 50 with 25 blocks (small).
allele_freq
List with parallel vectors haplotype, allele, freq – the training-style allele frequency table used by masbayes’s construct_wah_matrix(). Provided for cross-package interoperability; build_G_mh() does not need it.
pheno
Data frame with n rows. Columns: id, sex (factor F/M, balanced 50/50), y_cont_qtl_snp, y_cont_qtl_mh (continuous traits under two QTL architectures), y_bin_qtl_snp, y_bin_qtl_mh (binary traits, threshold at median), tbv_qtl_snp, tbv_qtl_mh (true breeding values).
pedigree
Data frame with 220 (large) or 120 (small) rows: 10 sire founders + 10 dam founders (all NA parents) plus the offspring with their sire/dam recorded. Passes directly into build_A_ped(). Columns: id, sire, dam.
qtl
List with snp_idx, mh_idx, effects_snp, effects_mh (each length 20 for large, 5 for small; effects drawn from rnorm, unit-normalised).
meta
List with n, n_snp, n_blocks, n_snp_per_block, n_qtl, n_families, n_per_family, h2_target, sex_beta_snp, sex_beta_mh, seed, split_seed, size.
family_id
Character vector length n, values fam_01..fam_10.
train_idx
Integer vector – row indices into snp/mh/pheno for the training set. Length 160 (large) / 80 (small).
test_idx
Integer vector – row indices for the test set. Length 40 (large) / 20 (small). Every test individual has its full-sibs in train_idx.
map_snp
Data frame with one row per SNP. Columns: SNP (matches colnames(snp)), CHROM (integer chromosome id, 1..5), POS (integer base-pair position). Synthetic 5-chromosome layout with 100 kb intra-chromosome spacing; deterministic, no RNG. Passes directly into GWAS / Manhattan-plot consumers (e.g. CMplot). Dimensions: 500 x 3 (large) / 50 x 3 (small).
map_mh
Data frame with one row per microhaplotype block. Columns: block_id (matches unique(attr(mh, “block_id”))), chr, start_pos, end_pos, n_snps. Schema mirrors the maspipeline output microhaplotype_coordinates.csv so production pipelines can consume d$map_mh without translation. Dimensions: 250 x 5 (large) / 25 x 5 (small).
multigen
Nested list with the 3-generation forward-prediction extension. Generated by tools/make_demo_data_3gen.R (AlphaSimR + optiSel OCS) and merged into this RDS. See Multi-generation extension below for the sub-fields.

On the microhaplotype representation in d$mh

In production, microhaplotype genotypes are produced by the maspipeline preprocessing pipeline (genomic_prediction/maspipeline/): phasing with Beagle, conversion to phased haplotype alleles, LD- or window-based block discovery, then per-strand block encoding. The on-disk output is one tab-separated file per chromosome with header

ID         hap_1_1 hap_1_1 hap_1_2 hap_1_2 hap_2_1 hap_2_1 hap_2_2 hap_2_2 ...
IND00001        1       1       2       2       1       1       2       2 ...
IND00002        1       1       1       1       2       2       1       1 ...

Each block contributes 4 columns: hap_<b>1 hap<b>1 hap<b>2 hap<b>_2 (the per-strand block name repeated twice, with per-SNP allele codes 1 or 2 inside). Block coordinates and allele frequencies live in companion CSVs (e.g. mh_info_ld_haploblock_G0/stats/microhaplotype_coordinates.csv).

The d$mh stored here is a compact in-memory equivalent for demos: instead of per-SNP allele codes, each strand of each block is collapsed into a single integer haplotype id via a base-3 polynomial encoding of its SNP alleles. Shape becomes \(n \times (2 \cdot n_{blocks})\) (two columns per block, not four). build_G_mh() auto-detects this matrix layout and re-encodes the sparse integer ids internally; users do not need to convert back to the per-SNP file representation.

Multi-generation extension (d$multigen)

For forward-prediction examples (examples/05_forward_prediction.R), d$multigen bundles a 3-generation breeding lineage:

  • Gen-1 phenotyped (training pool).

  • Gen-2 produced by OCS selection on gen-1, one cohort per QTL architecture (gen2_snp, gen2_mh).

  • Gen-3 produced by OCS on gen-2, also per architecture (gen3_snp, gen3_mh).

Two evaluation scenarios are supported:

Scenario A
Train on gen-1, predict gen-2. Build the full G across gen-1 + gen-2 (passing the gen-1 slice as ref_W / ref_mh so allele frequencies come from training only), fit masreml() on the gen-1 block, then call predict.masreml() with train_ids = gen-1, test_ids = gen-2 ids.
Scenario B
Train on gen-1 + gen-2 (per architecture), predict gen-3. Same pattern but the full G spans all three generations and ref_W / ref_mh comes from the gen-1 + gen-2 training slice.

Sub-fields under d$multigen:

gen1
List(snp, mh, allele_freq, pheno, sire_of, dam_of). pheno carries both y_cont_qtl_snp and y_cont_qtl_mh plus matching tbv_qtl_* columns.
gen2_snp, gen2_mh
Gen-2 cohort lists; same shape as gen1 but pheno only carries the architecture-matching trait + tbv_qtl_*_true ground truth.
gen3_snp, gen3_mh
Gen-3 cohort lists, same pattern as gen-2; allele_freq is the gen-1 + gen-2 combined frequency table.
reference_structure_gen1, reference_structure_gen1_gen2_snp, reference_structure_gen1_gen2_mh
Full construct_wah_matrix() return values (from masbayes) for cross-package interoperability; masreml’s build_G_mh() does not need them.
qtl
QTL info: mh_idx, effects_mh, beta_mh, and SNP centring-mean vectors for Scenario A / B.
pedigree
Combined pedigree across founders + gen-1 + two gen-2 cohorts + two gen-3 cohorts. Passes directly to build_A_ped().
ocs
Diagnostics for all four OCS calls.
meta
Per-cohort sizes, realised \(h^2\) per generation, target \(\Delta F\), seed, and package versions.

Examples

Code
library("masreml")

d <- load_data()
str(d, max.level = 1)
dim(d$snp)
head(d$pheno)

# Smaller dataset for fast examples / unit tests:
d_small <- load_data("small")
dim(d_small$snp)

# Multi-generation extension: forward-prediction layout
d3 <- d$multigen
str(d3, max.level = 1)
dim(d3$gen1$mh); dim(d3$gen2_mh$mh); dim(d3$gen3_mh$mh)
# Scenario A: train gen-1, predict gen-2 with a leakage-safe G
ids_tr  <- d3$gen1$pheno$id
ids_te  <- d3$gen2_mh$pheno$id
mh_full <- rbind(d3$gen1$mh, d3$gen2_mh$mh)
rownames(mh_full) <- c(ids_tr, ids_te)
G_full  <- build_G_mh(mh_full, ref_mh = mh_full[ids_tr, ],
                      ids = c(ids_tr, ids_te))