Genetic variation data is typically stored in variant call format (VCF) files (Danecek et al., 2011). This format is the preferred file format obtained from genome sequencing or high throughput genotyping. One advantage of using VCF files is that only variants (e.g., SNPs, indels, etc.) are reported which economizes files size relative to a format that may included invariant sites. Variant callers typically attempt to aggressively call variants with the perspective that a downstream quality control step will remove low quality variants. Note that VCF files come in different flavors and that each variant caller may report a slightly different information. A first step in working with this data is to understand their contents.
The VCF file specification is flexible. This means that there are slots for certain types of data, but any particular software which creates a VCF file does not necessarily use them all. Similarly, authors have the opportunity to include new forms of data, forms which may not have been foreseen by the authors of the VCF specification. The result is that all VCF files do not contain the same information.
For this example, we will use example data provided with the R package vcfR (Knaus & Grünwald, 2017).
The function library() loads libraries, in this case the package vcfR. The function data() loads datasets that were included with R and its packages. Our usage of data() loads the objects ‘gff’, ‘dna’ and ‘vcf’ from the ‘vcfR_example’ dataset. Here we’re only interested in the object ‘vcf’ which contains example VCF data. When we call the object name with no function it invokes the ‘show’ method which prints some summary information to the console.
##   "##source=\"GATK haplotype Caller, phased with beagle4\""
##   "for the ref and alt alleles in the order listed\">"
##   "read depth (reads with MQ=255 or with bad mates are filtered)\">"
The first line contains the version of the VCF format used in the file. This line is required. The second line specifies the software which created the VCF file. This is not required, so not all VCF files include it. When they do, the file becomes self documenting. Note that the alignment software is not included here because it was used upstream of the VCF file’s creation (aligners typically create *.SAM or *.BAM format files). Because the file can only include information about the software that created it, the entire pipeline does not get documented. Some VCF files may contain a line for every chromosome (or supercontig or contig depending on your genome), so they may become rather long. Here, the remaining lines contain INFO and FORMAT specifications which define abbreviations used in the fix and gt portions of the file.
The meta region may include long lines that may not be easy to view. In vcfR we’ve created a function to help press this data.
##  "1 contig=<IDs omitted from queryMETA"
When the function queryMETA() is called with only a vcfR object as a parameter, it attempts to summarize the meta information. Not all of the information is returned. For example, ‘contig’ elements are not returned. This is an attempt to summarize information that may be most useful for comprehension of the file’s contents.
##  "Description=Approximate read depth (reads with MQ=255 or with bad mates are filtered)"
##  "Description=Approximate read depth; some reads may have been filtered"
When an element parameter is included, only the information about that element is returned. In this example the element ‘DP’ is returned. We see that this acronym is defined as both a ‘FORMAT’ and ‘INFO’ acronym. We can narrow down our query by including more information in the element parameter.
Here we’ve isolated the definition of ‘DP’ as a ‘FORMAT’ element. Note that the function queryMETA() includes the parameter nice which by default is TRUE and attempts to present the data in a nicely formatted manner. However, our query is performed on the actual information in the ‘meta’ region. It is therefore sometimes appropriate to set nice = FALSE so that we can see the raw data. In the above example the angled bracket (‘<’) is omitted from the nice = TRUE representation but is essential to distinguishing the ‘FORMAT’ element from the ‘INFO’ element.
The fix region contains information for each variant which is sometimes summarized over all samples. The first eight columns of the fixed region are titled CHROM, POS, ID, REF, ALT, QUAL, FILTER and INFO. This is per variant information which is ‘fixed’, or the same, over all samples. The first two columns indicate the location of the variant by chromosome and position within that chromosome. Here, the ID field has not been used, so it consists of missing data (NA). The REF and ALT columns indicate the reference and alternate allelic states for a diploid sample. When multiple alternate allelic states are present they are delimited with commas. The QUAL column attempts to summarize the quality of each variant over all samples. The FILTER field is not used here but could contain information on whether a variant has passed some form of quality assessment.
The eigth column, titled INFO, is a semicolon delimited list of information. It can be rather long and cumbersome. The function getFIX() will suppress this column by default. Each abbreviation in the INFO column should be defined in the meta section. We can validate this by querying the meta portion, as we did in the ‘meta’ section above.
The gt (genotype) region contains information about each variant for each sample. The values for each variant and each sample are colon delimited. Multiple types of data for each genotype may be stored in this manner. The format of the data is specified by the FORMAT column (column nine). Here we see that we have information for GT, AD, DP, GQ and PL. The definition of these acronyms can be referenced by querying the the meta region, as demonstrated previously. Every variant does not necessarily have the same information (e.g., SNPs and indels may be handled differently), so the rows are best treated independently. Different variant callers may include different information in this region.
Using the R package vcfR, we can read VCF format files into memory using the function read.vcfR(). Once in memory we can use the head() method to summarize the information in the three VCF regions.
## Scanning file to determine attributes.
Meta line 29 read in.
## All meta lines processed.
## Character matrix gt created.
##  "***** Object of class 'vcfR' *****"
##  "***** Meta section *****"
##  "##source=\"GATK haplotype Caller, phased with beagle4\""
##  "##FORMAT=<ID=AD,Number=.,Type=Integer,Description=\"Allelic depths fo [Truncated]"
##  "***** Fixed section *****"
##  "***** Genotype section *****"
##  "First 6 columns only."
After we have made any manipulations of the file we can save it as a VCF file with the function write.vcf().
write.vcf()will write a file to your active directory. We now have a summary of our VCF file which we can use to help understand what forms of information are contained within it. This information can be further explored with plotting functions and used to filter the VCF file for high quality variants as we will see in the next section.
1) How would we find more information about read.vcfR()?
2) How would we learn what the acronym “AD” stands for?
##  "Description=Allelic depths for the ref and alt alleles in the order listed"
3) We used the head() function to view the first few lines of fix data. How would we view the last few lines of fix data?
4) There is a column in the fix portion of the data called QUAL. It is not defined in the meta portion of the data because it is defined in the VCF specification. It stands for ‘quality’. Does QUAL appear useful to us? Why or why not?
5) How would we query the sample names?
##   "FORMAT"        "BL2009P4_us23" "DDR7602"       "IN2009T1_us22"
##   "LBUS5"         "NL07434"       "P10127"        "P10650"
##   "P11633"        "P12204"        "P13527"        "P1362"
##  "P13626"        "P17777us22"    "P6096"         "P7722"
Note that the first column is FORMAT. This tells us the format for data for each variant. According to the VCF specification this can be different for each variant.