This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Manipulating header (and contents) of a vcf file

I want to manipulate (acutally add information to) the vcf file and its header information. I tried using sed in linux but just couldn't understand it.

It original vcf file looks like:

CHROM POS REF ALT

1 69 A G

1 75 C T

1 85 G A

I want to add the "ID" field after the 2nd column and replace the value for this field with "." Additionally I want to add other fields "QUAL", "FILTER" and "INFO" after the last column. All the columns should be tab separated and finally should look like.

CHROM POS ID REF ALT QUAL FILTER INFO

1 69 . A C . . .

1 75 . G A . . .

1 87 . C A . . .

1 88 . T C . . .

Thanks much in advance !

vcf variants sed

1 answer

You're looking to modify a stream of text. Substitution using sed works like this:

sed 's/old_text_or_regex/new_text_or_regex/modifiers/' input_file >output_file

But this scenario is better addressed using awk, where you can process individual columns and just add column at the appropriate position.

Once again, I'm providing no code because that would cripple learning.

Log in to answer this question.