Replace ID column of vcf file with another column in the text file
0
0
Entering edit mode
2.7 years ago
seta ★ 1.5k

Hi all,

I have the standard vcf file (VCFv4.2) and would like to replace the ID column of vcf file with the column in the other text file. The text file (without header) is like below:

1 56782 1:56782:T:C

I used the below codes to edit the vcf file:

grep -P '^#' file.vcf > new.vcf
grep -v -P '^#' file.vcf | cut -f3- | paste newpos.txt - >> new.vcf

Although it worked and didn’t return any error, vcf-validator gave me the error. Could you please kindly tell me your way to do such an edit on the vcf file?

Thanks

vcf ID column edit manipulation • 2.6k views
ADD COMMENT
1
Entering edit mode
vcf-validator gave me the error

Which error, also please post a selection of the new VCF. Brief Reminder On How To Ask A Good Question

ADD REPLY
1
Entering edit mode

Hello seta ,

it looks like you are trying to add an ID that contain the CHROM, POS, REF and ALT of the variant. If I'm right than you can bcftools annotate for this:

$ bcftools annotate --set-id +'%CHROM:%POS:%REF:%FIRST_ALT' input.vcf

That's all. No extra file, no special text processing.

fin swimmer

ADD REPLY
0
Entering edit mode

The + is not required if one wishes to override existing ID values, which is what seta wants, I think.

ADD REPLY
0
Entering edit mode

Thank you for all your responses. At the moment, I don't access to our cluster and can't paste the error from vcf-validator. But, I think the RamRS's solution works as I have the ID column in the text file and want to replace it with the existing one. I try it.

ADD REPLY
0
Entering edit mode

bcftools annotate -a annotation_file.bed -c ID can do exactly this, just use a BED file with necessary information (chr, pos, ref, alt). Read the bcftools annotate manual carefully for all caveats and requirements.

ADD REPLY

Login before adding your answer.

Traffic: 1588 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6