polysat-internal: Internal Functions in polysat

Internal FunctionsR Documentation

Internal Functions in polysat


The internal functions G, INDEXG, GENLIST, RANMUL, and SELFMAT are used for calculating genotype probabilities under partial selfing. The internal function .unal1loc finds all unique alleles at a single locus. The internal function fixloci converts locus names to a format that will be compatible as column headers for allele frequency tables.


G(q, n)
INDEXG(ag1, na1, m2)
GENLIST(ng, na1, m2)
RANMUL(ng, na1, ag, m2)
SELFMAT(ng, na1, ag, m2)
.unal1loc(object, samples, locus)
fixloci(loci, warn = TRUE)







A vector representing an unambiguous genotype.


Integer. The number of alleles, including a null.


Integer. The ploidy.


Integer. The number of genotypes.


An array of genotypes such as that produced by .genlist.


A "genambig" object.


Optional, a numeric or character vector indicating which samples to use.


A character string or number indicating which locus to use.


A character vector of locus names.


Boolean indicating whether a warning should be issued if locus names are changed.


G returns

(n+q)!/((q+1)! * (n-1)!)

INDEXG returns an integer indicating the row containing a particular genotype in the matrix produced by GENLIST.

GENLIST returns an array with dimensions ng, m2, containing all possible unambiguous genotypes, one in each row. The null allele is the highest-numbered allele.

RANMUL returns a list. The first item is a vector of polynomial coefficients for calculating genotype frequencies under random mating. The second is an array showing how many copies of each allele each genotype has.

SELFMAT returns the selfing matrix. Parental genotypes are represented in rows, and offspring genotypes in columns. The numbers indicate relative amounts of offspring genotypes produced when the parental genotypes are self-fertilized.

.unal1loc returns a vector containing all unique alleles, not including Missing(object).

fixloci returns a character vector of corrected locus names.


Lindsay V. Clark


De Silva, H. N., Hall, A. J., Rikkerink, E., and Fraser, L. G. (2005) Estimation of allele frequencies in polyploids under certain patterns of inheritance. Heredity 95, 327–334

See Also

deSilvaFreq, meandistance.matrix2, genotypeProbs, genambig.to.genbinary, alleleDiversity


# Calculation of genotype probabilities in a tetraploid with four
# alleles plus a null, and a selfing rate of 0.5.  This is a translation
# of code in the supplementary material of De Silva et al. (2005).
m2 <- 4
m <- m2/2
na1 <- 5
self <- 0.5
ng <- na1
for(j in 2:m2){
    ng <- ng*(na1+j-1)/j
ag <- polysat:::GENLIST(ng, na1, m2)
temp <- polysat:::RANMUL(ng, na1, ag, m2)
rmul <- temp[[1]]
arep <- temp[[2]]
smat <- polysat:::SELFMAT(ng, na1, ag, m2)
smatdiv <- (polysat:::G(m-1,m+1))^2
p1 <- c(0.1, 0.4, 0.2, 0.2, 0.1) # allele frequencies

# GPROBS subroutine
rvec <- rep(0,ng)
for(g in 1:ng){
    rvec[g] <- rmul[g]
    for(j in 1:m2){
        rvec[g] <- rvec[g]*p1[ag[g,j]]
id <- diag(nrow=ng)
smatt <- smat/smatdiv
s3 <- id - self * smatt
s3inv <- solve(s3)
gprob <- (1-self) * s3inv %*% rvec
# gprob is a vector of probabilities of the seventy genotypes.

polysat documentation built on Aug. 23, 2022, 5:07 p.m.