# utilities: Utily Functions for pegas In pegas: Population and Evolutionary Genetics Analysis System

## Description

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.

## Usage

 ```1 2 3 4 5 6 7``` ```getPloidy(x) getAlleles(x) getGenotypes(x) expand.genotype(n, alleles = NULL, ploidy = 2, matrix = FALSE) proba.genotype(alleles = c("1", "2"), p, ploidy = 2) is.snp(x) is.phased(x) ```

## Arguments

 `x` an object of class `"loci"`. `n` an integer giving how many alleles to consider (ignored if `alleles` is used). `alleles` the allele names as a vector of mode character. `ploidy` an integer giving the ploidy level (either 2 or 4 for the moment). `matrix` a logical specifying whether to return the genotypes in a matrix or as a character vector. `p` a vector of allele probabilities; if missing, equal probabilities are assumed.

## Details

`expand.genotype` and `proba.genotype` accept any level of ploidy and any number of alleles.

For `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).

## Value

`getPloidy` returns the ploidy level of all loci in an object of class `"loci"` as a numeric vector.

`getAlleles` and `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 argument `alleles` is given.

`proba.genotype` returns a numeric vector with names set as the genotypes.

`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.

## Author(s)

 ``` 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[[1]]\$allele ## expected probabilities for the 136 possible genotypes... proba.genotype(names(p), p/sum(p)) ## ... to be compared with s[[1]]\$genotype ```