Question: Replace ID column of vcf file with another column in the text file
0
gravatar for seta
8 days ago by
seta1.1k
Sweden
seta1.1k wrote:

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

ADD COMMENTlink modified 8 days ago • written 8 days ago by seta1.1k
1
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 REPLYlink written 8 days ago by ATpoint13k

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 REPLYlink written 8 days ago by RamRS20k

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 REPLYlink modified 8 days ago • written 8 days ago by finswimmer9.9k

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

ADD REPLYlink written 8 days ago by RamRS20k

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 REPLYlink modified 8 days ago • written 8 days ago by seta1.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1938 users visited in the last hour