Utily Functions for pegas
The first three functions extract information on loci,
expand.genotype creates a table of all possible genotypes given
a set of alleles,
proba.genotype calculates expected
probabilities of genotypes under Hardy–Weinberg equilibrium, and the
last two functions test whether a locus is a SNP or whether a
gentotype is phased.
1 2 3 4 5 6 7
an object of class
an integer giving how many alleles to consider (ignored if
the allele names as a vector of mode character.
an integer giving the ploidy level (either 2 or 4 for the moment).
a logical specifying whether to return the genotypes in a matrix or as a character vector.
a vector of allele probabilities; if missing, equal probabilities are assumed.
proba.genotype accept any level of
ploidy and any number of alleles.
is.snp, a locus is defined as a SNP if it has two alleles
and their labels are made of a single character (e.g., A and T, or 1
and 2, but not A and AT).
getPloidy returns the ploidy level of all loci in an object of
"loci" as a numeric vector.
getGenotypes return the alleles and
genotypes, respectively, observed in all loci in an object of class
"loci" as a list.
expand.genotype returns a character vector (the default) or a
matrix where the rows are the genotypes and the columns are the
alleles. The matrix is numeric by default, or character if the
alleles is given.
proba.genotype returns a numeric vector with names set as the
is.snp returns a logical vector specifying whether each locus
is a SNP.
is.phased returns a matrix of the same size than the original
data specifying whether each genotype is phased or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
data(jaguar) X <- jaguar[, 1:2] getAlleles(X) getGenotypes(X) expand.genotype(2) expand.genotype(2, LETTERS[1:3]) expand.genotype(3, ploidy = 4) proba.genotype() # classical HWE with 2 alleles ## an octoploid with a six-allele locus (1287 possible genotypes): length(p <- proba.genotype(alleles = LETTERS[1:6], ploidy = 8)) max(p) # ~ 0.006 ## back to the jaguar data: s <- summary(X) ## allele counts from the first locus: p <- s[]$allele ## expected probabilities for the 136 possible genotypes... proba.genotype(names(p), p/sum(p)) ## ... to be compared with s[]$genotype