| 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.5 |
| Built: | 2026-11-24 01:17:33 UTC |
| Source: | https://github.com/bioc/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, tol = 1e-08, ...)alleleFrequency(x, ...) ## S4 method for signature 'BreedingExperiment' alleleFrequency(x, tol = 1e-08, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
tol |
How far a dosage may sit from a whole number and still count as
a genotype call when |
freq and maf use every dosage that is present, so an expected dosage
from imputation contributes to them on the same footing as a call.
callRate is the proportion of dosages that are not NA; after
imputeMarkers() that is 1 for every marker, so take call rates before
imputing if you need them.
heterozygosity is different, because a heterozygote is a genotype rather
than a quantity. A cell counts towards it only if it is a genotype call:
its dosage must be a whole number, and it must not be marked in the
imputed assay that imputeMarkers() writes. Everything else is left out
of both the numerator and the denominator. Without those two checks an
imputed cell would be counted as a non-heterozygote and heterozygosity
would appear to fall every time a data set was imputed. A marker with no
genotype call at all gets NA.
Dosages imputed by other software arrive without the imputed assay, so
only the whole-number check applies to them; pass such dosages in as
fractional values, or carry your own mask as an extra assay, if observed
heterozygosity matters to you.
A S4Vectors::DataFrame with one row per marker and columns freq,
maf, callRate and heterozygosity.
filterMarkers(), imputeMarkers()
set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 50) head(alleleFrequency(be)) # imputation does not change the observed heterozygosity of a marker, # because imputed cells are not counted as genotype calls bem <- simulateBreeding(n_ind = 30, n_marker = 50, missing = 0.2) all.equal(alleleFrequency(bem)$heterozygosity, alleleFrequency(imputeMarkers(bem))$heterozygosity)set.seed(1) be <- simulateBreeding(n_ind = 30, n_marker = 50) head(alleleFrequency(be)) # imputation does not change the observed heterozygosity of a marker, # because imputed cells are not counted as genotype calls bem <- simulateBreeding(n_ind = 30, n_marker = 50, missing = 0.2) all.equal(alleleFrequency(bem)$heterozygosity, alleleFrequency(imputeMarkers(bem))$heterozygosity)
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.
If phenotypes has row names, they are treated as individual identifiers:
they must be the same set as the column names of genotypes, and the rows
are reordered to match. If it has no row names, or only the automatic
1, 2, 3, ... of a freshly built data frame, the rows are taken in the
order given. Row names that are neither absent nor matching are an error
rather than something to be overwritten, because the one thing worse than
refusing a phenotype table is silently attaching each phenotype to the
wrong individual.
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) # phenotypes given in a different order are matched by row name shuffled <- data.frame(yield = rnorm(12), row.names = rev(colnames(geno))) identical(colnames(BreedingExperiment(geno, phenotypes = shuffled)), colnames(geno))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) # phenotypes given in a different order are matched by row name shuffled <- data.frame(yield = rnorm(12), row.names = rev(colnames(geno))) identical(colnames(BreedingExperiment(geno, phenotypes = shuffled)), colnames(geno))
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 |
Allow missing dosages, giving them a dominance contribution
of zero. 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 and others code the genotypes AA, Aa and aa as ,
and . Those three values lie on a single quadratic in
the dosage ,
which is what this function evaluates. At dosages 2, 1 and 0 it returns the three published values exactly, and an expected dosage from imputation falls between them rather than being forced into one genotype class.
A missing call is given a dominance contribution of zero, which is the
weight that mean imputation already gives it in Gmatrix().
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.
min_maf and min_call_rate are judgement calls, not constants of nature.
Common starting points are a minor allele frequency of 0.01 to 0.05 and a
call rate of 0.90 to 0.95. Raise min_maf when the panel is large and the
sample small, because a rare allele seen in one or two individuals carries
almost no information about relationships but still adds noise; lower it
when rare variants are the point of the study. Run this before
imputeMarkers(), so that imputation is not asked to rescue markers that
should simply be discarded.
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, which gives a missing call no weight in the result. 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. Genotyped individuals that are absent
from the pedigree cannot be placed in and are dropped with a
warning.
Leave tune = TRUE unless you have already put on the scale of
yourself. Untuned, the two matrices usually disagree about the
average level of relationship, and that disagreement is passed straight
into the ungenotyped block, where it shows up as breeding values that are
biased between the genotyped and ungenotyped groups.
blend has two jobs. A small weight on makes
invertible, which matters whenever there are fewer markers than genotyped
individuals, and it pulls the markers back towards the pedigree where the
marker estimate is noisy. Values between 0.01 and 0.10 are usual and 0.05
is a reasonable default; 0.05 to 0.10 suits a small marker panel, and 0.01
to 0.02 a dense one on many individuals. blend = 0 keeps as it is
and will fail if is singular. blend = 1 discards the markers
altogether and returns the pedigree matrix, which is useful only as the
check shown in the examples.
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, drop_uncalled = TRUE, ...)imputeMarkers(x, ...) ## S4 method for signature 'BreedingExperiment' imputeMarkers(x, drop_uncalled = TRUE, ...)
x |
A BreedingExperiment object. |
... |
Unused. |
drop_uncalled |
Drop markers with no genotype calls at all, with a
warning. If |
Mean imputation leaves an expected dosage rather than a whole number of
copies, which the container accepts. Note what that costs: an imputed cell
is no longer a genotype call, and its value alone no longer says so, since
a marker whose mean dosage is exactly 1 imputes to exactly 1. The cells
that were filled in are therefore recorded in a logical assay named
imputed, reachable with assay(x, "imputed") and carried through
subsetting with everything else. alleleFrequency() consults it, so
observed heterozygosity is unchanged by imputing. callRate, on the other
hand, counts dosages that are present and so becomes 1 for every marker;
record call rates before imputing if you need them.
A marker with no calls at all has no frequency to impute from. Such markers
are dropped with a warning rather than being filled in, because filling
them would invent a genotype for every individual at that marker.
filterMarkers() removes them too, and running it first is the better
habit.
A BreedingExperiment object with no missing genotypes and
an imputed assay marking the cells that were filled in.
filterMarkers(), alleleFrequency()
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. Capped at |
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, between 0 and 1. |
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 genotyped individuals are the
most recent ones, so the ungenotyped are the earlier generations, as in a
programme that began genotyping part way through.
Note that n_founder defaults to 10 and is capped at n_ind, so a call
such as simulateBreeding(n_ind = 8) returns eight unrelated founders and
no pedigree structure at all. Ask for more individuals than founders to get
relatives.
The trait is scaled so that the genetic variance is h2 and the residual
variance is 1 - h2, and trueBV in the column data is the genetic
component on that scale.
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.
BreedingExperiment(), Hmatrix()
set.seed(1) be <- simulateBreeding(n_ind = 25, n_marker = 100) be head(as.data.frame(colData(be))) # a population where only the recent individuals were genotyped part <- simulateBreeding(n_ind = 30, n_marker = 100, n_founder = 6, genotyped = 20) c(pedigree = nrow(pedigree(part)), genotyped = ncol(part))set.seed(1) be <- simulateBreeding(n_ind = 25, n_marker = 100) be head(as.data.frame(colData(be))) # a population where only the recent individuals were genotyped part <- simulateBreeding(n_ind = 30, n_marker = 100, n_founder = 6, genotyped = 20) c(pedigree = nrow(pedigree(part)), genotyped = ncol(part))
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)