This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename sample id in vcf header

I have different vcf file with header

 # #CHROM    POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  **20**

I tried to follow this post: Change sample names in vcf

but not able to succeed.

I want to change this 20 in header file from the vcf with different naming.

Any lead will be highly appreciated.

vcf bcftools

1 answer

After little-bit of homework I found one way of doing this. I am posting this way if anyone could get help in future.

Extracted the header by

bcftools view --header-only raw_variants.vcf | sed 's/##contig=<ID=/##contig=<ID=chr/' | sed 's/##contig=<ID=chrMT/##contig=<ID=chrM/' > hello.vcf

Followed by

hello.vcf -> hello

Edited the name accordingly and run:

tabix -r hello raw_variants.vcf > raw7.vcf.gz

or

bcftools reheader -h hello raw_variants.vcf > output.vcf

Works well for me.

Log in to answer this question.