Copy a column of a VCF to another column within file
1
1
Entering edit mode
21 months ago
jomagrax ▴ 40

I have multiple VCF files, and I need to copy the elements of column 12 to column 13 while keeping the column names.

From this

$ cut -f12,13  sample_file.vcf | grep -v "##" | head
 VD_SCLC_1  VCFM_SCLC_1
 0/1:17,17:.:.:34,13:.:.:.:7,6:.:0.2766:.:13:.:47   0/1:.:.:.:.:.:.:.:.:.:.:.:.:.:.
 0/1:111:.:39:.:0.3514:.:21,18:.:.:41,31:.:.:72,39:.    0/1:.:.:.:.:.:.:.:.:.:.:.:.:.:.
 0/1:.:0.4118:.:.:.:28,22:50,35:.:.:19,16:85:.:.:35 0/1:.:.:.:.:.:.:.:.:.:.:.:.:.:.
 0/1:.:.:.:9,12:.:21,20:.:7,13:.:0.4878:.:20:41:.   0/1:.:.:.:.:.:.:.:.:.:.:.:.:.:.
0/1:0.3654:.:10,9:.:.:18,15:.:33,19:.:.:.:52:19:.   0/1:.:.:.:.:.:.:.:.:.:.:.:.:.:.

To this

$ cut -f12,13  sample_file.vcf | grep -v "##" | head
 VD_SCLC_1  VCFM_SCLC_1
 0/1:17,17:.:.:34,13:.:.:.:7,6:.:0.2766:.:13:.:47   0/1:17,17:.:.:34,13:.:.:.:7,6:.:0.2766:.:13:.:47
 0/1:111:.:39:.:0.3514:.:21,18:.:.:41,31:.:.:72,39:.    0/1:111:.:39:.:0.3514:.:21,18:.:.:41,31:.:.:72,39:.
 0/1:.:0.4118:.:.:.:28,22:50,35:.:.:19,16:85:.:.:35 0/1:.:0.4118:.:.:.:28,22:50,35:.:.:19,16:85:.:.:35  
 0/1:.:.:.:9,12:.:21,20:.:7,13:.:0.4878:.:20:41:.   0/1:.:.:.:9,12:.:21,20:.:7,13:.:0.4878:.:20:41:.
0/1:0.3654:.:10,9:.:.:18,15:.:33,19:.:.:.:52:19:.   0/1:0.3654:.:10,9:.:.:18,15:.:33,19:.:.:.:52:19:.   
vcf bash • 473 views
ADD COMMENT
3
Entering edit mode
21 months ago
Jeremy ▴ 910

Try this:

grep -v '^##' sample_file.vcf | awk '$13=$12' > <output.vcf>
ADD COMMENT

Login before adding your answer.

Traffic: 1725 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