snpStats (version 1.22.0)

mean2g: Raw coding of posterior probabilities of SNP genotype

Description

An uncertain SNP genotype call is represented by the three posterior probabilities of the three possible calls. In the class SnpMatrix, an approximation to these is packed into a single 1-byte variable of type raw. These functions carry out this coding (and decoding).

Usage

post2g(p, transpose = FALSE) mean2g(m, maxE = FALSE) g2post(g, transpose = FALSE)

Arguments

p
A matrix of posterior probabilities. If transpose is FALSE this is Nx3, otherwise 3xN
m
A vector of posterior means
g
A raw vector of genotype codes
transpose
A logical flag indicating transposition of the matric of posterior probabilities (see Description)
maxE
A logical flag selecting the maximum entropy option in mean2g

Value

post2g and mean2g return a vector of type raw. g2post returns a numeric matrix.

Details

post2g and g2post convert from posterior probabilities to raw code and back respectively. If only the posterior expectation of the genotype (when numerically coded 0, 1, or 2) is available, no unique soultion exists in general and the behaviour of the function is determined by the value of maxE. If TRUE, then the maximum entropy solutions are returned while, if FALSE, an attempt is made to return the least uncertain solution, by setting the posterior probability of the BB genotype to zero when the posterior mean is less than 1.0 and the probability of AA to zero when the mean is greater than 1.0.

Examples

Run this code
data(testdata)
g <- Autosomes[1:10, 20] ## A vector of codes
p <- g2post(g)           ## Transform to probabilities ...
pg <- post2g(p)          ## ... and back to codes
m <- p[,2]+2*p[,3]       ## Posterior expectations
mg <- mean2g(m)          ## Transform to codes ...
pmg <- g2post(mg)        ## ... and transform to probabilities
## Write everything out
print(cbind(as(g, "numeric"), p, as.numeric(pg), m, as.numeric(mg), pmg))

Run the code above in your browser using DataLab