AddAllele: AddAllele

Description Usage Arguments Examples

View source: R/functions.R

Description

Add an allele the members of a population. It is possible to add dominant and recessive alleles to each member of a population based on Hardy-Weinberg proportions. Moreover, it add that specific allele was added to the population in the form a geneSite object.

Usage

1
AddAllele(population, selectionAllele, alleleFreq)

Arguments

population

An object of type population.

selectionAllele

An object of type geneSite. Notice, here a selection coefficient should be specified.

alleleFreq

The frequency of the dominant allele in the population.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (population, selectionAllele, alleleFreq)
{
    alleleList = c(population@alleles, selectionAllele)
    indList = population@members
    nIndivid = length(indList)
    freq = GenotypeProportions(alleleFreq)
    alleleA = Allele(location = selectionAllele@location, type = toupper(selectionAllele@type))
    allelea = Allele(location = selectionAllele@location, type = tolower(selectionAllele@type))
    indPerPop = round(c(nIndivid * freq$fAA, nIndivid * freq$fAa,
        nIndivid * freq$faa))
    if (sum(indPerPop) != nIndivid) {
        warning("Not possible to plug an allele with these frequencies.\n      Rounding up the aa genotype individuals.")
        indPerPop[3] = nIndivid - (indPerPop[1] + indPerPop[2])
    }
    genot = rep(c("AA", "Aa", "aa"), times = indPerPop)
    genot = sample(genot)
    for (i in 1:nIndivid) {
        if (genot[i] == "AA") {
            indList[[i]]@chromosome1@alleles = c(indList[[i]]@chromosome1@alleles,
                alleleA)
            indList[[i]]@chromosome2@alleles = c(indList[[i]]@chromosome2@alleles,
                alleleA)
        }
        else if (genot[i] == "Aa") {
            indList[[i]]@chromosome1@alleles = c(indList[[i]]@chromosome1@alleles,
                alleleA)
            indList[[i]]@chromosome2@alleles = c(indList[[i]]@chromosome2@alleles,
                allelea)
        }
        else if (genot[i] == "aa") {
            indList[[i]]@chromosome1@alleles = c(indList[[i]]@chromosome1@alleles,
                allelea)
            indList[[i]]@chromosome2@alleles = c(indList[[i]]@chromosome2@alleles,
                allelea)
        }
        else {
            return("There is an unrecognized genotype")
        }
    }
    output = Population(members = indList, alleles = unlist(alleleList))
    validObject(output)
    return(output)
  }

alghul96/AdmSim documentation built on May 27, 2019, 3:29 p.m.