I am currently asking myself how to rename samples in a vcf file. This is necessary, because the naming of several samples included in thr vcf file was unfortunately not be chosen by me.
I am loading the vcf file via readVcf()
from the VariantAnnotation
package in R.
To check the sample names, i can use samples(header(vcf.file))
, which will give me the names as characters.
It looks like this:
and so on..
(I am actually very sorry that i cannot give a reproducible example here :( )
I also have a vector with all the new names. For example
new.names <- c("1","2","3","4")
I tried to exchange the "old names" with the new.names vector:
samples(header(vcf.file)) <- new.names
which leads to the error Error in samples(header(data.vcf)) <- names.sample : could not find function "samples<-"
I also tried to use the rutilstimflutre
package, which has a already designed function for this, but unfortunately the package is outdated and not available for the newest R version.
Is there a way to do this? Perhaps a better way to assign the new names to the old ones?
Thanks a lot.