vcfR documentation

by
Brian J. Knaus and Niklaus J. Grünwald

The R packages adegenet and poppr are popular tools for population genetic analysis. Here we describe how to convert a vcfR object to a genind and genclone object.

Data import

We will use the example dataset provided by vcfR.

library(vcfR)
data(vcfR_example)

Creating genind objects

The packages adegenet and poppr use objects of class genind. We can create genind objects with the function vcfR2genind().

my_genind <- vcfR2genind(vcf)
## Loading required namespace: adegenet
class(my_genind)
## [1] "genind"
## attr(,"package")
## [1] "adegenet"
my_genind
## /// GENIND OBJECT /////////
## 
##  // 18 individuals; 2,533 loci; 5,083 alleles; size: 1.9 Mb
## 
##  // Basic content
##    @tab:  18 x 5083 matrix of allele counts
##    @loc.n.all: number of alleles per locus (range: 1-5)
##    @loc.fac: locus factor for the 5083 columns of @tab
##    @all.names: list of allele names for each locus
##    @ploidy: ploidy of each individual  (range: 2-2)
##    @type:  codom
##    @call: adegenet::df2genind(X = t(x), sep = sep)
## 
##  // Optional content
##    - empty -

The function vcfR2genind() calls extract.gt() to create a matrix of genotypes. This matrix is converted into a genind object with the adegenet function df2genind().

Currently, this function does not scale well to large quantities of data. This appears to be due a call to the function adegenet::df2genind (this function was produced prior to high throughput sequencing). The genlight object is designed to perform better for larger datasets.

Creating genclone objects

The package poppr uses objects of class genclone as well as genind. Once a genind object has been created, it is fairly straight forward to create a genclone object.

my_genclone <- poppr::as.genclone(my_genind)
## Registered S3 method overwritten by 'pegas':
##   method      from
##   print.amova ade4
class(my_genclone)
## [1] "genclone"
## attr(,"package")
## [1] "poppr"
my_genclone
## 
## This is a genclone object
## -------------------------
## Genotype information:
## 
##      16 original multilocus genotypes 
##      18 diploid individuals
##    2533 codominant loci
## 
## Population information:
## 
##       0 strata. 
##       0 populations defined.

Copyright © 2017, 2018 Brian J. Knaus. All rights reserved.

USDA Agricultural Research Service, Horticultural Crops Research Lab.