if (FALSE) {
## An example with a long run time due to the number of alleles
# create a dataset for this example
mygen <- new("genambig", samples=c(paste("A", 1:100, sep=""),
paste("B", 1:100, sep="")),
loci=c("loc1", "loc2"))
PopNames(mygen) <- c("PopA", "PopB")
PopInfo(mygen) <- c(rep(1, 100), rep(2, 100))
mygen <- reformatPloidies(mygen, output="one")
Ploidies(mygen) <- 4
Usatnts(mygen) <- c(2, 2)
Description(mygen) <- "An example for allele frequency calculation."
# create some genotypes at random for this example
for(s in Samples(mygen)){
Genotype(mygen, s, "loc1") <- sample(seq(120, 140, by=2),
sample(1:4, 1))
}
for(s in Samples(mygen)){
Genotype(mygen, s, "loc2") <- sample(seq(130, 156, by=2),
sample(1:4, 1))
}
# make one genotype missing
Genotype(mygen, "B4", "loc2") <- Missing(mygen)
# view the dataset
summary(mygen)
viewGenotypes(mygen)
# calculate the allele frequencies if the rate of selfing is 0.2
myfrequencies <- deSilvaFreq(mygen, self=0.2)
# view the results
myfrequencies
}
## An example with a shorter run time, for checking that the funciton
## is working. Genotype simulation is also a bit more realistic here.
# Create a dataset for the example.
mygen <- new("genambig", samples=paste("A", 1:100, sep=""), loci="loc1")
PopNames(mygen) <- "PopA"
PopInfo(mygen) <- rep(1, 100)
mygen <- reformatPloidies(mygen, output="one")
Ploidies(mygen) <- 4
Usatnts(mygen) <- 2
for(s in Samples(mygen)){
alleles <- unique(sample(c(122,124,126,0), 4, replace=TRUE,
prob = c(0.3, 0.2, 0.4, 0.1)))
Genotype(mygen, s, "loc1") <- alleles[alleles != 0]
if(length(Genotype(mygen, s, "loc1"))==0)
Genotype(mygen, s, "loc1") <- Missing(mygen)
}
# We have created a random mating populations with four alleles
# including one null. The allele frequencies are given in the
# 'prob' argument.
# Estimate allele frequencies
myfreq <- deSilvaFreq(mygen, self=0.01)
myfreq
Run the code above in your browser using DataLab