R: Convert Allele Frequencies for Adegenet

freq.to.genpop {polysat} | R Documentation

## Convert Allele Frequencies for Adegenet

### Description

Given a data frame of allele frequencies such as that produced by `simpleFreq` or `deSilvaFreq`, `freq.to.genpop` creates a data frame of allele counts that can be read by the `as.genpop` function in the package adegenet.

### Usage

    freq.to.genpop(freqs, pops = row.names(freqs),
                   loci =
                    unique(as.matrix(as.data.frame(strsplit(names(freqs),
                    split = ".", fixed = TRUE), stringsAsFactors = FALSE))[1, ]))

### Arguments

`freqs` | A data frame of allele frequencies. Row names are population names. The first column is called `"Genomes"` and indicates the size of each population in terms of number of haploid genomes. All other column names are the locus and allele separated by a period. These columns contain the frequencies of each allele in each population. For each locus and population, all frequencies should total to 1.
`pops` | An optional character vector indicating the names of populations to use.
`loci` | An optional character vector indicating the names of loci to use.

### Details

adegenet expects one ploidy for the entire dataset. Therefore, data frames of allele frequencies with multiple “Genomes” columns, such as those produced when ploidy varies by locus, are not allowed as the `freqs` argument.

### Value

A data frame with row and column names identical to those in `freqs`, minus the `"Genomes"` column and any columns for loci not included in `loci`. Allele frequencies are converted to counts by multiplying by the values in the `"Genomes"` column and rounding to the nearest integer.

### Author(s)

Lindsay V. Clark

### References

Jombart, T. (2008) adegenet: a R package for the multivariate analysis of genetic markers. Bioinformatics 24, 1403-1405.

### See Also

`simpleFreq`, `deSilvaFreq`, `write.freq.SPAGeDi`, `gendata.to.genind`

### Examples

    # create a simple allele frequency table
    # (usually done with simpleFreq or deSilvaFreq)
    myfreq <- data.frame(row.names=c("popA","popB"), Genomes=c(120,100),
                         locG.152=c(0.1,0.4), locG.156=c(0.5, 0.3),
                         locG.160=c(0.4, 0.3), locK.179=c(0.15, 0.25),
                         locK.181=c(0.35, 0.6), locK.183=c(0.5, 0.15))
    myfreq

    # convert to adegenet format
    gpfreq <- freq.to.genpop(myfreq)
    gpfreq

    ## Not run:
    # If you have adegenet installed, you can now make this into a
    # genpop object.
    require(adegenet)
    mygenpop <- genpop(gpfreq, ploidy=as.integer(4), type="codom")

    # examine the object that has been created
    mygenpop
    popNames(mygenpop)
    mygenpop@tab
    mygenpop@all.names

    # Perform a distance calculation with the object
    dist.genpop(mygenpop)

    ## End(Not run)

[Package polysat version 1.7-6 Index]