| Title: | Container and Relationship Matrices for Breeding and Quantitative Genomics |
|---|---|
| Description: | Provides the BreedingExperiment class, a container that keeps marker genotypes, phenotypes, pedigree and marker coordinates together in one object, extending RangedSummarizedExperiment so that markers are addressable as genomic ranges. Relationship matrices central to quantitative genetics are computed as methods on the container: the pedigree numerator relationship matrix of Henderson (1976) <doi:10.2307/2529339>, the genomic relationship matrix of VanRaden (2008) <doi:10.3168/jds.2007-0980>, the dominance relationship matrix of Vitezica, Varona and Legarra (2013) <doi:10.1534/genetics.113.155176>, and the single-step matrix combining pedigree and genomic information of Legarra, Aguilar and Misztal (2009) <doi:10.3168/jds.2009-2061> and Christensen and Lund (2010) <doi:10.1186/1297-9686-42-2>, which allows genotyped and ungenotyped individuals to be analysed together as in Aguilar and others (2010) <doi:10.3168/jds.2009-2730>. Marker quality control, imputation, inbreeding coefficients and allele frequency summaries are included. |
| Authors: | Muhammad Farooqi [aut, cre] (ORCID: <https://orcid.org/0000-0003-4918-9791>) |
| Maintainer: | Muhammad Farooqi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.4 |
| Built: | 2026-09-29 07:19:45 UTC |
| Source: | https://github.com/BiocStaging/BreedingExperiment |
Computes, for every marker, the frequency of the counted allele, the minor allele frequency, the call rate and the observed heterozygosity.
alleleFrequency(x, ...) ## S4 method for signature 'BreedingExperiment' alleleFrequency(x, ...)alleleFrequency(x, ...) ## S4 method for signature 'BreedingExperiment' alleleFrequency(x, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
A S4Vectors::DataFrame with one row per marker and columns freq,
maf, callRate and heterozygosity.
set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 50) head(alleleFrequency(be))set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 50) head(alleleFrequency(be))
Builds the additive relationship matrix from the pedigree using the
tabular method. Element is twice the coefficient of kinship
between individuals and , so a diagonal entry is
where is the inbreeding coefficient.
Amatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Amatrix(x, ids = NULL, ...)Amatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Amatrix(x, ids = NULL, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
ids |
Optional character vector of identifiers to return, in that order. Defaults to every individual in the pedigree. |
The matrix is built recursively over a pedigree sorted so that parents come
first: an individual's relationship to an earlier individual is the average
of its parents' relationships to that individual, and its diagonal is
.
A symmetric numeric matrix with dimnames taken from the pedigree.
Henderson, C. R. (1976) "A simple method for computing the inverse of a numerator relationship matrix used in prediction of breeding values." Biometrics 32, 69-83. doi:10.2307/2529339
Gmatrix(), Hmatrix(), inbreeding()
set.seed(1) be <- simulateBreeding(n_ind = 12, n_marker = 30) A <- Amatrix(be) round(A[1:5, 1:5], 3)set.seed(1) be <- simulateBreeding(n_ind = 12, n_marker = 30) A <- Amatrix(be) round(A[1:5, 1:5], 3)
Builds a BreedingExperiment from a marker genotype matrix, with optional phenotypes, pedigree and marker coordinates.
BreedingExperiment( genotypes, phenotypes = NULL, pedigree = NULL, rowRanges = NULL, ... )BreedingExperiment( genotypes, phenotypes = NULL, pedigree = NULL, rowRanges = NULL, ... )
genotypes |
A numeric matrix of allele dosages, markers in rows and individuals in columns, with column names identifying the individuals. |
phenotypes |
Optional data frame or S4Vectors::DataFrame of
individual-level variables, with one row per column of |
pedigree |
Optional data frame with columns |
rowRanges |
Optional GenomicRanges::GRanges giving the position
of each marker, of the same length as |
... |
Further assays, passed to
|
Genotypes are allele dosages: usually the integers 0, 1 and 2, with NA for
missing calls. Fractional values in between are accepted, so expected dosages
from imputation can be stored directly. Markers are rows and individuals are
columns, matching the Bioconductor convention that features are rows.
If rowRanges is not supplied, markers are given placeholder coordinates on
a single sequence so that the object is still a valid ranged experiment; pass
real coordinates whenever you have them, because that is what allows a data
set to be subset by genomic region.
The pedigree may name ancestors that were never genotyped. Those extra
individuals are exactly what Hmatrix() needs in order to combine pedigree
and genomic information.
A BreedingExperiment object.
Gmatrix(), Amatrix(), Hmatrix(), simulateBreeding()
set.seed(1) geno <- matrix(rbinom(40 * 12, 2, 0.3), nrow = 40, ncol = 12, dimnames = list(paste0("snp", 1:40), paste0("ind", 1:12))) pheno <- data.frame(yield = rnorm(12)) be <- BreedingExperiment(geno, phenotypes = pheno) be dim(be)set.seed(1) geno <- matrix(rbinom(40 * 12, 2, 0.3), nrow = 40, ncol = 12, dimnames = list(paste0("snp", 1:40), paste0("ind", 1:12))) pheno <- data.frame(yield = rnorm(12)) be <- BreedingExperiment(geno, phenotypes = pheno) be dim(be)
A BreedingExperiment keeps everything a quantitative-genetic analysis needs
in one object: marker genotypes, the phenotypes and design variables of the
individuals, the pedigree, and the position of every marker on the genome.
## S4 method for signature 'BreedingExperiment' show(object)## S4 method for signature 'BreedingExperiment' show(object)
object |
A BreedingExperiment object. |
The class extends
SummarizedExperiment::RangedSummarizedExperiment, so markers are rows
and individuals are columns, and the familiar accessors work as usual:
assay() returns the genotype matrix, rowRanges() the marker coordinates
as a GenomicRanges::GRanges, and colData() the phenotypes. Because
marker positions are genomic ranges, a breeding data set can be subset by
region, overlapped with annotation, and otherwise handled with the standard
Bioconductor vocabulary.
One slot is added to the parent class:
pedigreeA S4Vectors::DataFrame with columns id, sire and
dam, giving the parents of each individual. Unknown parents are NA.
It may contain ancestors that were never genotyped, which is what makes
single-step analysis possible.
Genotypes are stored as allele dosages: 0, 1 or 2 copies of the counted
allele, with NA for missing calls.
A class definition, so nothing is returned by the class itself. The
constructor BreedingExperiment() returns a BreedingExperiment object,
and the show method is called for the summary it prints, returning
object invisibly.
Use BreedingExperiment(); see its help page for examples.
The show method prints the size of the object, the assays it holds, the
phenotype columns, the sequences the markers lie on, and a summary of the
pedigree including how many individuals are genotyped.
BreedingExperiment(), Amatrix(), Gmatrix(), Hmatrix()
data(demoBreeding) demoBreedingdata(demoBreeding) demoBreeding
A small, five-generation breeding population supplied so that every function in the package can be tried on data that behaves like a real programme.
data(demoBreeding)data(demoBreeding)
A BreedingExperiment with 900 markers and 120 genotyped
individuals, and a pedigree of 180. colData holds:
Generation number, 3 to 5 for genotyped individuals.
"F" or "M".
A moderately heritable trait (),
recorded on females only.
A more heritable trait (), recorded
on everyone.
The simulated true breeding values.
The data are simulated, not observed. They are built to have the awkward features that real breeding data has and that tidy textbook examples lack:
Only part of the population is genotyped. The two earliest
generations were born before genotyping began, so 60 of the 180
individuals in the pedigree have no markers. This is the situation
Hmatrix() exists for.
Unequal family sizes, because a few sires are used heavily.
A trait recorded on one sex only. yield is missing for males,
as a milk trait would be.
Missing genotype calls, at about one per cent, as any chip has.
Markers on ten chromosomes with irregular spacing, so subsetting by genomic region is meaningful.
Because the data are simulated, the true breeding values are known and are
kept in colData, which makes the object useful for checking that a
prediction method recovers what it should.
Simulated by data-raw/make_demo.R in the package sources.
simulateBreeding() to generate your own, Hmatrix() for the
analysis this data set is shaped for.
data(demoBreeding) demoBreeding # 60 of the 180 individuals in the pedigree were never genotyped nrow(pedigree(demoBreeding)) - ncol(demoBreeding) # the single-step matrix covers all of them H <- Hmatrix(demoBreeding) dim(H)data(demoBreeding) demoBreeding # 60 of the 180 individuals in the pedigree were never genotyped nrow(pedigree(demoBreeding)) - ncol(demoBreeding) # the single-step matrix covers all of them H <- Hmatrix(demoBreeding) dim(H)
Builds the dominance relationship matrix from marker dosages using the
genotypic parameterisation of Vitezica, Varona and Legarra (2013).
Heterozygotes and the two homozygotes are coded so that the resulting matrix
captures dominance deviations, orthogonal to the additive relationships
returned by Gmatrix().
Dmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Dmatrix(x, min_maf = 0, impute = TRUE, ...)Dmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Dmatrix(x, min_maf = 0, impute = TRUE, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
min_maf |
Markers with a minor allele frequency below this are dropped. |
impute |
Replace missing dosages by twice the allele frequency before
computing. If |
Fitting additive and dominance effects together lets a model separate the part of the genetic variance that is inherited predictably from the part that is not, which matters for crossbreeding and for predicting the performance of specific crosses.
A symmetric numeric matrix over the genotyped individuals.
Vitezica, Z. G., Varona, L. & Legarra, A. (2013) "On the additive and dominant variance and covariance of individuals within the genomic selection scope." Genetics 195, 1223-1230. doi:10.1534/genetics.113.155176
set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 200) D <- Dmatrix(be) round(D[1:4, 1:4], 3)set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 200) D <- Dmatrix(be) round(D[1:4, 1:4], 3)
Removes markers that are uninformative or poorly genotyped: those below a minor allele frequency threshold, those called in too few individuals, and optionally those that are monomorphic.
filterMarkers(x, ...) ## S4 method for signature 'BreedingExperiment' filterMarkers( x, min_maf = 0.01, min_call_rate = 0.9, drop_monomorphic = TRUE, ... )filterMarkers(x, ...) ## S4 method for signature 'BreedingExperiment' filterMarkers( x, min_maf = 0.01, min_call_rate = 0.9, drop_monomorphic = TRUE, ... )
x |
A BreedingExperiment object. |
... |
Unused. |
min_maf |
Minimum minor allele frequency to keep. |
min_call_rate |
Minimum proportion of individuals with a call. |
drop_monomorphic |
Drop markers with no variation. |
A BreedingExperiment object with fewer rows.
imputeMarkers(), alleleFrequency()
set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 100, missing = 0.05) nrow(be) nrow(filterMarkers(be, min_maf = 0.05, min_call_rate = 0.9))set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 100, missing = 0.05) nrow(be) nrow(filterMarkers(be, min_maf = 0.05, min_call_rate = 0.9))
Returns the identifiers that appear in the genotype matrix. In a single-step
analysis the pedigree usually names more individuals than this, and the
difference is what Hmatrix() reconciles.
genotyped(x, ...) ## S4 method for signature 'BreedingExperiment' genotyped(x, ...)genotyped(x, ...) ## S4 method for signature 'BreedingExperiment' genotyped(x, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
A character vector of individual identifiers.
set.seed(1) be <- simulateBreeding(n_ind = 8, n_marker = 20) genotyped(be)set.seed(1) be <- simulateBreeding(n_ind = 8, n_marker = 20) genotyped(be)
Gets or sets the matrix of allele dosages, a shorthand for the genotype
assay. Markers are rows and individuals are columns.
genotypes(x, ...) genotypes(x) <- value ## S4 method for signature 'BreedingExperiment' genotypes(x, ...) ## S4 replacement method for signature 'BreedingExperiment' genotypes(x) <- valuegenotypes(x, ...) genotypes(x) <- value ## S4 method for signature 'BreedingExperiment' genotypes(x, ...) ## S4 replacement method for signature 'BreedingExperiment' genotypes(x) <- value
x |
A BreedingExperiment object. |
... |
Unused. |
value |
A numeric matrix of dosages coded 0, 1 or 2. |
genotypes() returns a numeric matrix; the replacement form returns
the updated object.
set.seed(1) be <- simulateBreeding(n_ind = 6, n_marker = 10) genotypes(be)[1:5, 1:4]set.seed(1) be <- simulateBreeding(n_ind = 6, n_marker = 10) genotypes(be)[1:5, 1:4]
Builds the additive genomic relationship matrix from marker dosages
using VanRaden's first method: with the marker matrix centred by
twice the allele frequency, .
Gmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Gmatrix(x, min_maf = 0, impute = TRUE, ...)Gmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Gmatrix(x, min_maf = 0, impute = TRUE, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
min_maf |
Markers with a minor allele frequency below this are dropped. |
impute |
Replace missing dosages by twice the allele frequency before
computing. If |
plays the same role as the pedigree matrix but is estimated
from markers, so it captures Mendelian sampling that a pedigree cannot: full
sibs have an expected pedigree relationship of exactly 0.5, whereas their
genomic relationship varies around it.
A symmetric numeric matrix over the genotyped individuals.
VanRaden, P. M. (2008) "Efficient methods to compute genomic predictions." Journal of Dairy Science 91, 4414-4423. doi:10.3168/jds.2007-0980
Amatrix(), Dmatrix(), Hmatrix()
set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 200) G <- Gmatrix(be) round(G[1:4, 1:4], 3)set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 200) G <- Gmatrix(be) round(G[1:4, 1:4], 3)
Builds the matrix that combines pedigree and genomic information, so
that genotyped and ungenotyped individuals can be analysed in a single
model. This is the relationship structure behind single-step genomic
prediction (ssGBLUP).
Hmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Hmatrix(x, blend = 0.05, tune = TRUE, min_maf = 0, impute = TRUE, ...)Hmatrix(x, ...) ## S4 method for signature 'BreedingExperiment' Hmatrix(x, blend = 0.05, tune = TRUE, min_maf = 0, impute = TRUE, ...)
x |
A BreedingExperiment object with both a pedigree and genotypes. |
... |
Unused. |
blend |
Weight |
tune |
Rescale |
min_maf, impute
|
Passed to |
Real breeding programmes genotype only part of the population. Using only
throws away every ungenotyped relative; using only throws
away the markers. keeps both: relationships among genotyped
individuals come from the markers, relationships among ungenotyped
individuals are those from the pedigree corrected by what the markers reveal
about their genotyped relatives, and the two groups are connected through the
pedigree.
Writing 1 for ungenotyped and 2 for genotyped individuals,
Because and are estimated on different scales,
is first made compatible with in two standard steps. Tuning
rescales so that its mean diagonal and mean off-diagonal match those
of . Blending then mixes in a small share of ,
, which also makes the result invertible when
markers are fewer than individuals.
A symmetric numeric matrix over every individual in the pedigree,
ungenotyped individuals first, with an attribute genotyped giving the
identifiers of the genotyped group.
Legarra, A., Aguilar, I. & Misztal, I. (2009) "A relationship matrix including full pedigree and genomic information." Journal of Dairy Science 92, 4656-4663. doi:10.3168/jds.2009-2061
Christensen, O. F. & Lund, M. S. (2010) "Genomic prediction when some animals are not genotyped." Genetics Selection Evolution 42, 2. doi:10.1186/1297-9686-42-2
Aguilar, I., Misztal, I., Johnson, D. L., Legarra, A., Tsuruta, S. & Lawlor, T. J. (2010) "Hot topic: A unified approach to utilize phenotypic, full pedigree, and genomic information for genetic evaluation of Holstein final score." Journal of Dairy Science 93, 743-752. doi:10.3168/jds.2009-2730
# only some of the individuals are genotyped set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 300, genotyped = 20) H <- Hmatrix(be) dim(H) attr(H, "genotyped")# only some of the individuals are genotyped set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 300, genotyped = 20) H <- Hmatrix(be) dim(H) attr(H, "genotyped")
Fills missing dosages with twice the allele frequency of the marker, the simple mean imputation that relationship matrices assume. It is adequate for the low rates of missingness left after quality control; for anything more, impute with dedicated software before building the object.
imputeMarkers(x, ...) ## S4 method for signature 'BreedingExperiment' imputeMarkers(x, ...)imputeMarkers(x, ...) ## S4 method for signature 'BreedingExperiment' imputeMarkers(x, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
A BreedingExperiment object with no missing genotypes.
set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 50, missing = 0.1) anyNA(genotypes(be)) anyNA(genotypes(imputeMarkers(be)))set.seed(1) be <- simulateBreeding(n_ind = 20, n_marker = 50, missing = 0.1) anyNA(genotypes(be)) anyNA(genotypes(imputeMarkers(be)))
Returns the inbreeding coefficient of each individual, obtained from the
diagonal of the pedigree relationship matrix as .
inbreeding(x, ...) ## S4 method for signature 'BreedingExperiment' inbreeding(x, ...)inbreeding(x, ...) ## S4 method for signature 'BreedingExperiment' inbreeding(x, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
A named numeric vector of inbreeding coefficients.
set.seed(1) be <- simulateBreeding(n_ind = 12, n_marker = 30) round(inbreeding(be), 4)set.seed(1) be <- simulateBreeding(n_ind = 12, n_marker = 30) round(inbreeding(be), 4)
Gets or sets the pedigree, a table with columns id, sire and dam. The
pedigree may include ancestors that were never genotyped; those individuals
are what allow Hmatrix() to combine pedigree and genomic information.
pedigree(x, ...) pedigree(x) <- value ## S4 method for signature 'BreedingExperiment' pedigree(x, ...) ## S4 replacement method for signature 'BreedingExperiment' pedigree(x) <- valuepedigree(x, ...) pedigree(x) <- value ## S4 method for signature 'BreedingExperiment' pedigree(x, ...) ## S4 replacement method for signature 'BreedingExperiment' pedigree(x) <- value
x |
A BreedingExperiment object. |
... |
Unused. |
value |
A data frame with columns |
pedigree() returns a S4Vectors::DataFrame; the replacement form
returns the updated object.
set.seed(1) be <- simulateBreeding(n_ind = 8, n_marker = 20) head(pedigree(be))set.seed(1) be <- simulateBreeding(n_ind = 8, n_marker = 20) head(pedigree(be))
Generates a pedigreed population with markers and a heritable trait, for examples, tests and teaching. Founders are unrelated; later generations are produced by mating sampled parents, and each offspring inherits one allele from each parent at every marker, so the simulated genotypes and the pedigree agree with each other.
simulateBreeding( n_ind = 50, n_marker = 200, n_founder = 10, genotyped = NULL, n_qtl = 20, h2 = 0.4, missing = 0 )simulateBreeding( n_ind = 50, n_marker = 200, n_founder = 10, genotyped = NULL, n_qtl = 20, h2 = 0.4, missing = 0 )
n_ind |
Number of individuals in total. |
n_marker |
Number of markers. |
n_founder |
Number of unrelated founders. |
genotyped |
Number of individuals with genotypes, taken from the most recent ones. Defaults to all of them. |
n_qtl |
Number of markers with an effect on the trait. |
h2 |
Narrow-sense heritability of the simulated trait. |
missing |
Proportion of genotype calls set to |
Set genotyped below n_ind to leave some individuals ungenotyped, which is
the situation Hmatrix() is designed for.
The function draws random numbers but does not set the seed itself. Call
set.seed() beforehand if you need the same population twice.
A BreedingExperiment object with a phenotype column and the
true breeding value in colData.
set.seed(1) be <- simulateBreeding(n_ind = 25, n_marker = 100) be head(as.data.frame(colData(be)))set.seed(1) be <- simulateBreeding(n_ind = 25, n_marker = 100) be head(as.data.frame(colData(be)))
The tabular method for building a relationship matrix requires that every individual appears after both of its parents. This performs that topological sort and reports a cycle if the pedigree contains one.
sortPedigree(ped)sortPedigree(ped)
ped |
A data frame or S4Vectors::DataFrame with columns |
A data frame with the same columns, reordered.
ped <- data.frame(id = c("c", "a", "b"), sire = c("a", NA, NA), dam = c("b", NA, NA)) sortPedigree(ped)ped <- data.frame(id = c("c", "a", "b"), sire = c("a", NA, NA), dam = c("b", NA, NA)) sortPedigree(ped)