gl.sim.crosses: Generates crosses between fathers and mothers

View source: R/gl.sim.crosses.r

gl.sim.crossesR Documentation

Generates crosses between fathers and mothers

Description

Crosses a cohort of fathers (in one genlight object) with a cohort of mothers (in a second genlight object), generating a brood of a specified size for each pair, then retains a random subset of the offspring.

Usage

gl.sim.crosses(
  fathers,
  mothers,
  broodsize = 10,
  sexratio = 0.5,
  n = NULL,
  error.check = TRUE,
  compliance.check = TRUE,
  verbose = NULL
)

Arguments

fathers

Genlight object of potential fathers [required].

mothers

Genlight object of potential mothers [required].

broodsize

Number of offspring per mother. Must be a positive integer; any other value is replaced by 10 with a warning [default 10].

sexratio

Expected proportion of female offspring. Must be in the range 0 to 1; any other value is replaced by 0.5 with a warning [default 0.5].

n

Number of offspring to retain, drawn at random from the full brood. If n exceeds the number of offspring generated, all of them are retained, with a warning [default NULL, resolving to 1000 or mothers*broodsize, whichever is the lesser].

error.check

If TRUE, also checks that the two parent cohorts are scored on identical loci [default TRUE].

compliance.check

If TRUE, will perform a compliance check on the resultant genlight object before returning it [default TRUE].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, adopting the global verbosity set by gl.set.verbosity(), or 2 if no global is set].

Details

Pairing is positional: father i is crossed with mother i, in every brood replicate. The two parent cohorts must therefore hold the same number of individuals, scored on the same loci. Randomising which male breeds with which female is the caller's responsibility, and is done by subsampling the parent cohorts before calling this function. Each parent contributes one gamete per offspring. A homozygous locus transmits its only allele; a heterozygous locus transmits one of its two alleles, drawn independently for every heterozygous call, in every parent, in every brood replicate. A locus scored as missing in either parent yields a missing call in the offspring. This script is to be used in conjunction with gl.subsample.ind() applied initially to a base genlight object containing male and female genotypes. The workflow is: (a) Select the males from the base genlight object using gl.keep.pop() with pop.list set to the label used for males in the sex metadata and the as.pop parameter set to "sex". Note that gl.keep.pop() restores the original population assignments afterwards, and that gl.subsample.ind() subsamples within populations, so assign a single population to the result before subsampling. (b) Select the females in the same way. (c) Subsample a cohort of males and an equally sized cohort of females for breeding using gl.subsample.ind() and the replace parameter as follows. To enforce monogamy – subsample both cohorts with replace=FALSE. To admit polygyny – subsample the fathers with replace=TRUE and the mothers with replace=FALSE, so that a male can appear more than once. To admit polyandry – subsample the fathers with replace=FALSE and the mothers with replace=TRUE. To admit promiscuity – subsample both cohorts with replace=TRUE. These are simple scenarios that leave the number of mates per individual to chance, depending on the random selection of parents with replacement. (d) Cross the two cohorts using gl.sim.crosses(), retaining a subset of the offspring at random.

  males <- gl.keep.pop(testset.gl, pop.list = "Male",
                       as.pop = "sex", verbose = 0)
  females <- gl.keep.pop(testset.gl, pop.list = "Female",
                         as.pop = "sex", verbose = 0)
  pop(males) <- rep("males", nInd(males))
  pop(females) <- rep("females", nInd(females))
  fathers <- gl.subsample.ind(males, n = 10, replace = TRUE, verbose = 0)
  mothers <- gl.subsample.ind(females, n = 10, replace = FALSE, verbose = 0)
  offspring <- gl.sim.crosses(fathers, mothers, broodsize = 5, n = 20)

The offspring object records its parentage in @other$ind.metrics$mother and @other$ind.metrics$father. Set error.check to FALSE if using this script in simulations. The structural checks (parameter ranges, matching cohort sizes and locus counts) always run; error.check governs only the comparison of the two locus panels for identity, which scales with the number of loci.

Value

A genlight object with n offspring of both sexes.

Author(s)

Author(s): Bernd Gruber. Custodian: Bernd Gruber – Post to https://groups.google.com/d/forum/dartr

See Also

gl.subsample.ind, gl.keep.pop

Examples

males <- gl.keep.pop(testset.gl, pop.list = "Male",
                     as.pop = "sex", verbose = 0)
females <- gl.keep.pop(testset.gl, pop.list = "Female",
                       as.pop = "sex", verbose = 0)
pop(males) <- rep("males", nInd(males))
pop(females) <- rep("females", nInd(females))
fathers <- gl.subsample.ind(males, n = 5, replace = FALSE, verbose = 0)
mothers <- gl.subsample.ind(females, n = 5, replace = FALSE, verbose = 0)
offspring <- gl.sim.crosses(fathers, mothers, broodsize = 4, n = 10,
                            verbose = 0)
nInd(offspring)
head(offspring@other$ind.metrics)

dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.