knausb / vcfR

Tools to work with variant call format files
248 stars 54 forks source link

changing chromosome ID into numeric or integer #145

Closed treebreeder closed 5 years ago

treebreeder commented 5 years ago

Hi Brian, I am wondering if I can change the IDs of my chromosomes in my vcf into something else and save this as a new vcf file! The background is that some functions such as SnpAnnotationDataFrame take only integer values, but my chromosome ids look like this:

[5] "##contig="
[6] "##contig="
[7] "##contig="
[8] "##contig="
[9] "##contig="
[10] "##contig="
[11] "##contig="
[12] "##contig="
[13] "##contig="
[14] "##contig="
[15] "##contig="

Is it possible to translate them into numbers for instance?

treebreeder commented 5 years ago

I figured out how to do it! Thanks a lot anyway!

cheers

knausb commented 5 years ago

Just thought I'd document a solution.

library(vcfR)
data("vcfR_test")
vcfR_test@fix[,1:8]
vcfR_test@fix[,1] <- 1:5
vcfR_test@fix[,1:8]