R/draw_allele_given_anc.R

Defines functions draw_allele_given_anc

# Draw an allele given ancestry 
# and vector of ancestry-specific allele frequencies.

draw_allele_given_anc <- function(anc, freqs){

    if(anc == 0){
        allele <- sample(x = 0:1, size = 1, prob = c(1 - freqs[1], freqs[1]))
    }else if(anc == 1){
        allele <- sample(x = 0:1, size = 1, prob = c(1 - freqs[2], freqs[2]))
    }else if(anc == 2){
        allele <- sample(x = 0:1, size = 1, prob = c(1 - freqs[3], freqs[3]))
    }else{
        stop('anc must be 0, 1, or 2')
    }

    return(allele)
}

Try the ASAFE package in your browser

Any scripts or data that you put into this service are public.

ASAFE documentation built on Nov. 8, 2020, 10:59 p.m.