vcfR_conversion: Convert vcfR objects to other formats

Format conversionR Documentation

Convert vcfR objects to other formats

Description

Convert vcfR objects to objects supported by other R packages

Usage

vcfR2genind(x, sep = "[|/]", return.alleles = FALSE, ...)

vcfR2loci(x, return.alleles = FALSE)

vcfR2genlight(x, n.cores = 1)

Arguments

x

an object of class chromR or vcfR

sep

character (to be used in a regular expression) to delimit the alleles of genotypes

return.alleles

should the VCF encoding of the alleles be returned (FALSE) or the actual alleles (TRUE).

...

pass other parameters to adegenet::df2genlight

n.cores

integer specifying the number of cores to use.

Details

After processing vcf data in vcfR, one will likely proceed to an analysis step. Within R, three obvious choices are: pegas, adegenet and poppr. The package pegas uses objects of type loci. The function vcfR2loci calls extract.gt to create a matrix of genotypes which is then converted into an object of type loci.

The packages adegenet and poppr use the genind object. The function vcfR2genind uses extract.gt to create a matrix of genotypes and uses the adegenet function df2genind to create a genind object. The package poppr additionally uses objects of class genclone which can be created from genind objects using poppr::as.genclone. A genind object can be converted to a genclone object with the function poppr::as.genclone.

The function vcfR2genlight calls the 'new' method for the genlight object. This method implements multi-threading through calls to the function parallel::mclapply. Because 'forks' do not exist in the windows environment, this will only work for windows users when n.cores=1. In the Unix environment, users may increase this number to allow the use of multiple threads (i.e., cores).

The parameter ... is used to pass parameters to other functions. In vcfR2genind it is used to pass parameters to adegenet::df2genind. For example, setting check.ploidy=FALSE may improve the performance of adegenet::df2genind, as long as you know the ploidy. See ?adegenet::df2genind to see these options.

Note

For users of poppr

If you wish to use vcfR2genind(), it is strongly recommended to use it with the option return.alleles = TRUE. The reason for this is because the poppr package accomodates mixed-ploidy data by interpreting "0" alleles in genind objects to be NULL alleles in both poppr::poppr.amova() and poppr::locus_table().

See Also

extract.gt, alleles2consensus, adegenet::df2genind, adegenet::genind, pegas, adegenet, and poppr. To convert to objects of class DNAbin see vcfR2DNAbin.

Examples

adegenet_installed <- require("adegenet")
if (adegenet_installed) {
  data(vcfR_test)
  # convert to genlight (preferred method with bi-allelic SNPs)
  gl <- vcfR2genlight(vcfR_test)
  
  # convert to genind, keeping information about allelic state
  # (slightly slower, but preferred method for use with the "poppr" package)
  gid <- vcfR2genind(vcfR_test, return.alleles = TRUE) 

  # convert to genind, returning allelic states as 0, 1, 2, etc.
  # (not preferred, but slightly faster)
  gid2 <- vcfR2genind(vcfR_test, return.alleles = FALSE)
}


vcfR documentation built on May 29, 2024, 10:57 a.m.