Learn R Programming

polysat (version 0.1)

write.GenoDive: Write a File in GenoDive Format

Description

write.GenoDive takes the standard genotype object used by polysat and creates a file formatted for the software GenoDive.

Usage

write.GenoDive(gendata, popnames = "onebigpop",
commentline = "file description goes here", digits = 2, file = "",
samples = dimnames(gendata)[[1]], loci = dimnames(gendata)[[2]],
popinfo = rep(1, times = length(samples)),
usatnts = rep(2, times = length(loci)), missing=-9)

Arguments

gendata
A two-dimensional list of vectors representing genotypes, in the standard polysat format. Samples are the first dimension of the list and loci are the second dimension. Dimensions are named accordingly. Each vector is numerical and contains all uniqu
popnames
A character vector of population names, ordered by the population numbers used in popinfo.
commentline
Character string. The first line of the file, containing a description of the data.
digits
Integer. How many digits to use to represent each allele (usually 2 or 3).
file
A character string of the file path to which to write.
samples
A character vector of samples to include in the file. A subset of dimnames(gendata)[[1]].
loci
A character vector of loci to include in the file. A subset of dimnames(gendata)[[2]].
popinfo
A numeric or integer vector containing the population number of each individual. names(popinfo) should include all of samples. If the vector is unnamed, it is assumed to be in the same order as samples.
usatnts
A numeric or integer vector, with one element for each locus. names(usatnts) should include all of loci, or if the vector is unnamed it is assumed to be in the same order as loci. Each element represents the leng
missing
The symbol used to indicate missing data in the input.

Value

  • A file is written but no value is returned.

Details

The number of individuals, number of populations, number of loci, and maximum ploidy of the sample are calculated automatically and entered in the second line of the file. If the maximum ploidy needs to be reduced by random removal of alleles, it is possible to do this in the software GenoDive after importing the data. Population names and population identies of individuals can optionally be entered as arguments in the file. If you do not already have this data readily available in R, you may prefer to enter it manually using a text editor or spreadsheet software after the file is written by write.GenoDive. Several steps happen in order to convert alleles to the right format. First, all instances of the missing data symbol are replaced with zero. Alleles are then divided by the numbers provided in usatnts (and rounded down if necessary) in order to convert them from nucleotides to repeat numbers. If the alleles are still too big to be represented by the number of digits specified, write.GenoDive repeatedly subtracts a number (10^(digits-1), so 10 if digits=2) from all alleles at a locus until the alleles are small enough. Alleles are then converted to characters, and a leading zero is added to an allele if it does not have enough digits. These alleles are concatenated at each locus so that each sample*locus genotype is an uninterrupted string of numbers.

References

Meirmans, P. G. and Van Tienderen P. H. (2004) GENOTYPE and GENODIVE: two programs for the analysis of genetic diversity of asexual organisms Molecular Ecology Notes 4, 792-794. http://www.bentleydrummer.nl/software/software/GenoDive.html

See Also

read.GenoDive, write.Structure, write.ATetra, write.Tetrasat, write.GeneMapper, codominant.to.dominant, write.SPAGeDi

Examples

Run this code
# set up the genotype object (usually done by reading a file)
mysamples <- c("Mal", "Inara", "Kaylee", "Simon", "River", "Zoe",
               "Wash", "Jayne", "Book")
myloci <- c("loc1", "loc2")
mygendata <- array(list(-9), dim=c(9,2), dimnames=list(mysamples,
                                                       myloci))
mygendata[,"loc1"] <- list(c(304,306), c(302,310), c(306), c(312,314),
c(312,314), c(308,310), c(312), c(302,308,310), c(-9))
mygendata[,"loc2"] <- list(c(118,133), c(121,130), c(122,139),
c(124,133), c(118,124), c(121,127), c(124,136), c(124,127,136),
c(121,130))

# make the vector of nucleotide repeat lengths
myusatnts <- c(2,3)
names(myusatnts) <- myloci

# set up population info (some or all of this might also be read from a file)
mypopnames <- c("Core","Outer Rim")
mypopinfo <- c(rep(1,4) ,rep(2,6))
names(mypopinfo) <- c("Simon", "River", "Inara", "Book", "Kaylee",
                      "Mal", "Wash", "Zoe", "Badger", "Jayne")

# write files (use file="" to display in console instead)
write.GenoDive(mygendata, usatnts=myusatnts, popnames=mypopnames,
  popinfo=mypopinfo, digits=2, commentline="Serenity crew",
  file="testGenoDive2.txt")
write.GenoDive(mygendata, usatnts=myusatnts, popnames=mypopnames,
  popinfo=mypopinfo, digits=3, commentline="Serenity crew",
  file="testGenoDive3.txt")

Run the code above in your browser using DataLab