Converting .vcf.gz file to genlight object

5 views
Skip to first unread message

Matthew Holen

unread,
8:59 AM (6 hours ago) 8:59 AM
to dartR
Good morning, 

I'm working on realigning our data to a new reference genome, and so far have a small subsample in a final .vcf.gz format only containing biallelic snps. 

If I try to use the gl.read.vcf I get the following error: 
Error in as.vector(data) : no method for coercing this S4 class to a vector In addition: Warning message: In (function (..., deparse.level = 1) : number of columns of result is not a multiple of vector length (arg 1)I can somewhat load it in with vcfR2genlight, but get the same error after checking with gl.compliance.check() :
Error in as.vector(data) : no method for coercing this S4 class to a vector

Any tips/ideas how I can convert this file to a genlight object for using in the dartRverse?

Jose Luis Mijangos

unread,
3:09 PM (4 minutes ago) 3:09 PM
to dartR
Hi Matt,

Can you please try the below code.

Cheers,
Luis 

# before installing development version of dartR.base, do
# Menu > Session > Clear Workspace
# Menu > Session > Restart R
# Install the development version of dartR.base from GitHub
devtools::install_github("green-striped-gecko/dartR.base@dev")
# Load the dartRverse
library(dartRverse)
# Read a VCF file and individual metadata
t1 <- gl.read.vcf(
  "final_biallelic_snps.vcf",
  ind.metafile = "pilot_metadata.csv"
)
# Number of SNPs
nLoc(t1)
# Number of individuals
nInd(t1)
# Tabulate individuals by population
table(pop(t1))
# Inspect locus metrics
head(t1$other$loc.metrics)
# Inspect individual metrics
head(t1$other$ind.metrics)
# PCA
pca <- gl.pcoa(t1)
# Plot the PCA 
gl.pcoa.plot(
  pca,
  t1,
  zaxis = 3,
  pt.size = 3
)
Reply all
Reply to author
Forward
0 new messages