-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvcf2dapc.R
More file actions
46 lines (34 loc) · 1.24 KB
/
vcf2dapc.R
File metadata and controls
46 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/Rscript
# vcf2dapc.R performs an interactive DAPC analyses from a VCF input file
# This is not a standalone script, due to interactive queries of some adegenet
# functions. Use the interactive mode to run these commands.
suppressMessages(library("vcfR"))
suppressMessages(library("adegenet"))
args <- commandArgs(trailingOnly = T)
# Get arguments
vcf_file = args[1]
max_cl = args[2]
output_file = args[3]
# Reading VCF file
print("Reading VCF file")
vcf <- read.vcfR(vcf_file)
print("Converting VCF to GenInd format")
vcf_gi <- vcfR2genlight(vcf)
# Determine optimum number of clusters
print("Determining optimum number of clusters")
grp <- find.clusters(vcf_gi, choose.n.clust=F, criterion="diffNgroup")
# Compute DAPC
print("Computing DAPC")
dapc1 <- dapc(vcf_gi, grp$grp)
# Printing plot
print("Generating plot")
pdf(paste(output_file, "_assignments.pdf", sep=""))
assignplot(dapc1)
dev.off()
pdf(paste(output_file, "_dapc.pdf", sep=""))
scatter(dapc1, scree.da=F, bg="white", pch=20, cell=0, cstar=0,
solid=.4, cex=3, clab=0, leg=T,
txt.leg=paste("Cluster", 1:length(grp$size)))
# BW version
#scatter(dapc1, scree.da=F, bg="white", pch=c(5,7, 6), cell=0, cstar=0,
# solid=.4, cex=2, clab=0, leg=T, col="grey", lwd=2)