This is a test version of Biostars. For the public version, visit https://www.biostars.org.
add original filename using vcf-concat

Hello

I need to concatenate several hundreds of vcf files. When viewing the concatenated file I want to be able to know from which vcf file each row originated.

I thought about adding a column with the original file name but I'm:

  1. Not sure of its possible
  2. Never saw that it's been done.

I'm also rather new to working with vcf files so I don't want to reinvent the wheel, so I will really appreciate any advice to what is the standard way to do what I'm trying to accomplish.

Thanks in advance.

vcf

1 answer

Using awk add a INFO definition in the header, and add the filename in the snp. The awk script should be something like (not tested):

/^#CHROM/ {
     printf("##INFO=\n");
     }

/^#/ { print; next;}

    {
    for(i=1;i<=NF;++i) { if(i>1) printf("\t"); if(i==8) printf("F=%s;",FILENAME); printf("%s",$i); }
    printf("\n");
    }

and then

awk -F '\t' -f script.awk in.vcf > out.vcf

Log in to answer this question.