The bioinformatics file-format zoo

The bioinformatics file-format zoo · Subtopic 2 of 3 · 8 min

VCF: recording genetic variants

Scientists share a standard reference copy of the human DNA sequence, called the reference genome. Think of it as a master template that everyone compares their own DNA against. Your DNA is almost identical to it, but not exactly. A variant is simply a spot where a sample's DNA differs from that reference. (A sample just means one person or organism whose DNA was read.) DNA is spelled with only four letters, A, C, G, and T, called bases, so a variant is often just one letter swapped for another, for example an A where the reference has a G.

VCF: the list of differences

VCF stands for Variant Call Format. It is the standard text file that lists every one of those differences for a sample. Because it is plain text, you can open it in any text editor, it is just letters, numbers, and tabs. A VCF has two parts: header lines at the top that describe the file, and then one line for each variant found.

What the file looks like

The header lines all start with two hash marks (##) and hold metadata, which means information about the data itself, such as which reference genome was used. The very last header line starts with a single # and is the column header: it names the columns. After that, every remaining line is one variant, and its columns are separated by tabs (an invisible gap made by the Tab key). Here is a small example file named variants.vcf:

##fileformat=VCFv4.2
##reference=GRCh38
##contig=<ID=chr1,length=248956422>
##INFO=<ID=DP,Number=1,Type=Integer,Description="Read depth">
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO
chr1	14653	.	C	T	35	PASS	DP=18
chr1	17385	rs2691305	G	A	48	PASS	DP=25
chr2	47630	.	A	G	29	PASS	DP=14
chr3	89122	.	T	C	52	PASS	DP=31

Four columns tell the heart of the story. CHROM is the chromosome, one of the large separate pieces that DNA is packaged into, written here like chr1. POS is the position, the numbered spot along that chromosome. REF is the reference base, the letter the master template has there. ALT is the alternative base, the letter this sample has instead. So the line reading chr2, 47630, then A and G means: on chromosome 2, at position 47630, the reference has an A but this sample has a G. That single swap is the variant.

Counting your variants

A common first question is simply: how many variants are in this file? You cannot just count every line, because the header lines would inflate the number. The trick is to skip every line that starts with #. The tool grep searches text line by line; its -v option flips the search to mean show the lines that do NOT match. The pattern "^#" means starts with a # (the ^ symbol means beginning of the line). So grep -v "^#" hands back only the variant lines, and wc -l counts them (wc counts things in text, and the -l option tells it to count lines only).

bash
grep -v "^#" variants.vcf | wc -l
4

Try it yourself: Copy the example file above into a file named variants.vcf, then run grep -v "^#" variants.vcf | wc -l and confirm you get 4. Now add one more variant line at the bottom, typing it exactly like the others with a Tab between each column: chr5, then 90210, then a single dot for the ID, then T, then A, then 40, then PASS, then DP=20. Save the file and run the command again. If the count is now 5, you have just edited real bioinformatics data.