第一种方法
#参考这个(https://cloud.tencent.com/developer/article/1369842)
library(vcfR)
vcf_file='yourdir/merge.dbsnp.vcf'
vcf <- read.vcfR( vcf_file, verbose = F, checkFile=F )
第二种方法
# read two times the vcf file, first for the columns names, second for the data
tmp_vcf<-readLines("test.vcf")
tmp_vcf_data<-read.table("test.vcf", stringsAsFactors = FALSE)
# filter for the columns names
tmp_vcf<-tmp_vcf[-(grep("#CHROM",tmp_vcf)+1):-(length(tmp_vcf))]
vcf_names<-unlist(strsplit(tmp_vcf[length(tmp_vcf)],"\t"))
names(tmp_vcf_data)<-vcf_names
网友评论