This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting Data From Vcf File

Hi from my vcf file, I have extracted the homozygous SNPs and got a new vcf file but it has no INFO section at the header. How can I keep the INFO section untouched? My commands: more file.vcf | grep "1/1" > homo.vcf What else do I need to add in the above arguments to protect the 13 lines INFO section at the header of vcf file?

vcftools gatk vcf samtools

3 answers

try to use a regular expression, with egrep and '^#' ( hash starting a line)

egrep '(^#|1/1)' file.vcf > homo.vcf

And then after you can do your previous command but make sure to append so as not to over write.

more file.vcf | grep "1/1" >> homo.vcf

Also if you know exactly how many lines are in your header that you want to keep (like say 13) you can do:

head -13 > homo.vcf to put the header in a file.

Great, it worked...thank you

testing how this works..

Log in to answer this question.