Contents

1 Version Info

R version: R version 3.6.0 (2019-04-26)
Bioconductor version: 3.9
Package version: 1.8.0

2 Background

The VariantAnnotation package has facilities for reading in all or subsets of Variant Call Format (VCF) files. These text files contain meta-information lines, a header line and data lines each containing information about a position in the genome. The format also may also contain genotype information on samples for each position. More on the file format can be found in the VCF specs.

The ‘locateVariants’ function in the VariantAnnotation package identifies where a variant is located with respect to the gene model (e.g., exon, intron, splice site, etc.). The ‘predictCoding’ function reports the amino acid change for non-synonymous coding variants. Consequences of the coding changes can be investigated with the SIFT and PolyPhen database packages. We’ll use these functions to learn about variants located on the TRPV gene on chromosome

3 Set Up

This workflow requires several different Bioconductor packages. Usage of each will be described in detail in the following sections.

library(VariantAnnotation)
library(cgdv17)
library(org.Hs.eg.db)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(BSgenome.Hsapiens.UCSC.hg19)
library(PolyPhen.Hsapiens.dbSNP131)

Use BiocManager::install() to get the packages you don’t have installed:

if (!"BiocManager" %in% rownames(installed.packages()))
     install.packages("BiocManager")
BiocManager::install("mypackage")

4 Exploring variants in the TRPV gene family

This workflow focuses on variants located in the Transient Receptor Potential Vanilloid (TRPV) gene family on chromosome 17. Sample data are from the Bioconductor cgdv17 experimental data package which contains Complete Genomics Diversity panel data for chromosome 17 on 46 individuals. For more background on how these data were curated see the package vignette.

browseVignettes("cgdv17")

We use a VCF file from the package that is a subset of chromosome 17 for a single individual from the CEU population.

file <- system.file("vcf", "NA06985_17.vcf.gz", package = "cgdv17")

4.1 Examine header data in a vcf file

To get an idea of what data are in the file we look at the header. scanVcfHeader() parses the file header into a VCFHeader object and the info() and geno() accessors extract field-specific data.

hdr <- scanVcfHeader(file)

info(hdr)
## DataFrame with 3 rows and 3 columns
##         Number        Type                 Description
##    <character> <character>                 <character>
## NS           1     Integer Number of Samples With Data
## DP           1     Integer                 Total Depth
## DB           0        Flag dbSNP membership, build 131
geno(hdr)
## DataFrame with 12 rows and 3 columns
##             Number        Type                         Description
##        <character> <character>                         <character>
## GT               1      String                            Genotype
## GQ               1     Integer                    Genotype Quality
## DP               1     Integer                          Read Depth
## HDP              2     Integer                Haplotype Read Depth
## HQ               2     Integer                   Haplotype Quality
## ...            ...         ...                                 ...
## mRNA             .      String                     Overlaping mRNA
## rmsk             .      String                  Overlaping Repeats
## segDup           .      String Overlaping segmentation duplication
## rCov             1       Float                   relative Coverage
## cPd              1      String                called Ploidy(level)

Variants in the VCF have been aligned to NCBI genome build GRCh37:

meta(hdr)
## DataFrameList of length 6
## names(6): fileDate fileformat phasing reference source contig

[ Back to top ]

4.2 Convert gene symbols to gene ids

Use the org.Hs.eg.db package to convert gene symbols to gene ids.

## get entrez ids from gene symbols
genesym <- c("TRPV1", "TRPV2", "TRPV3")
geneid <- select(org.Hs.eg.db, keys=genesym, keytype="SYMBOL",
         columns="ENTREZID")
## 'select()' returned 1:1 mapping between keys and columns
geneid
##   SYMBOL ENTREZID
## 1  TRPV1     7442
## 2  TRPV2    51393
## 3  TRPV3   162514

[ Back to top ]

4.3 Create gene ranges

We use the hg19 known gene track from UCSC to identify the TRPV gene ranges. These ranges will eventually be used to extract variants from a regions in the VCF file.

Load the annotation package.

txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
txdb
## TxDb object:
## # Db type: TxDb
## # Supporting package: GenomicFeatures
## # Data source: UCSC
## # Genome: hg19
## # Organism: Homo sapiens
## # Taxonomy ID: 9606
## # UCSC Table: knownGene
## # Resource URL: http://genome.ucsc.edu/
## # Type of Gene ID: Entrez Gene ID
## # Full dataset: yes
## # miRBase build ID: GRCh37
## # transcript_nrow: 82960
## # exon_nrow: 289969
## # cds_nrow: 237533
## # Db created by: GenomicFeatures package from Bioconductor
## # Creation time: 2015-10-07 18:11:28 +0000 (Wed, 07 Oct 2015)
## # GenomicFeatures version at creation time: 1.21.30
## # RSQLite version at creation time: 1.0.0
## # DBSCHEMAVERSION: 1.1

Our VCF file was aligned to a genome from NCBI and the known gene track was from UCSC. These institutions have different naming conventions for the chromosomes. In order to use these two pieces of data in a matching or overlap operation the chromosome names (also called sesqlevels) need to match. We will modify the txdb to match the VCF file.

txdb <- renameSeqlevels(txdb, gsub("chr", "", seqlevels(txdb)))
txdb <- keepSeqlevels(txdb, "17")

Create a list of transcripts by gene:

txbygene = transcriptsBy(txdb, "gene")

Create the gene ranges for the TRPV genes

gnrng <- unlist(range(txbygene[geneid$ENTREZID]), use.names=FALSE)
names(gnrng) <- geneid$SYMBOL

[ Back to top ]

4.4 Extract variant subsets

A ScanVcfParam object is used to retrieve data subsets. This object can specify genomic coordinates (ranges) or individual VCF elements. Extractions of ranges (vs fields) requires a tabix index. See ?indexTabix for details.

param <- ScanVcfParam(which = gnrng, info = "DP", geno = c("GT", "cPd"))
param
## class: ScanVcfParam 
## vcfWhich: 1 elements
## vcfFixed: character() [All] 
## vcfInfo: DP 
## vcfGeno: GT cPd 
## vcfSamples:
## Extract the TRPV ranges from the VCF file
vcf <- readVcf(file, "hg19", param)
## Inspect the VCF object with the 'fixed', 'info' and 'geno' accessors
vcf
## class: CollapsedVCF 
## dim: 405 1 
## rowRanges(vcf):
##   GRanges with 5 metadata columns: paramRangeID, REF, ALT, QUAL, FILTER
## info(vcf):
##   DataFrame with 1 column: DP
## info(header(vcf)):
##       Number Type    Description
##    DP 1      Integer Total Depth
## geno(vcf):
##   SimpleList of length 2: GT, cPd
## geno(header(vcf)):
##        Number Type   Description         
##    GT  1      String Genotype            
##    cPd 1      String called Ploidy(level)
head(fixed(vcf))
## DataFrame with 6 rows and 4 columns
##              REF                ALT      QUAL      FILTER
##   <DNAStringSet> <DNAStringSetList> <numeric> <character>
## 1              A                  G       120        PASS
## 2              A                            0        PASS
## 3          AAAAA                            0        PASS
## 4             AA                            0        PASS
## 5              C                  T        59        PASS
## 6              T                  C       157        PASS
geno(vcf)
## List of length 2
## names(2): GT cPd

[ Back to top ]

4.5 Variant location in the gene model

The locateVariants function identifies where a variant falls with respect to gene structure, e.g., exon, utr, splice site, etc. We use the gene model from the TxDb.Hsapiens.UCSC.hg19.knownGene package loaded eariler.

## Use the 'region' argument to define the region
## of interest. See ?locateVariants for details.
cds <- locateVariants(vcf, txdb, CodingVariants())
five <- locateVariants(vcf, txdb, FiveUTRVariants())
splice <- locateVariants(vcf, txdb, SpliceSiteVariants())
intron <- locateVariants(vcf, txdb, IntronVariants())
all <- locateVariants(vcf, txdb, AllVariants())
## Warning in valid.GenomicRanges.seqinfo(x, suggest.trim = TRUE): GRanges object contains 140 out-of-bound ranges located on sequences
##   62411, 62399, 62400, 62401, 62403, 62404, 62405, and 62407. Note
##   that ranges located on a sequence whose length is unknown (NA) or on
##   a circular sequence are not considered out-of-bound (use
##   seqlengths() and isCircular() to get the lengths and circularity
##   flags of the underlying sequences). You can use trim() to trim these
##   ranges. See ?`trim,GenomicRanges-method` for more information.
## 'select()' returned many:1 mapping between keys and columns
## 'select()' returned many:1 mapping between keys and columns
## 'select()' returned many:1 mapping between keys and columns
## 'select()' returned many:1 mapping between keys and columns
## 'select()' returned many:1 mapping between keys and columns
## 'select()' returned many:1 mapping between keys and columns

Each row in cds represents a variant-transcript match so multiple rows per variant are possible. If we are interested in gene-centric questions the data can be summarized by gene regardless of transcript.

## Did any variants match more than one gene?
table(sapply(split(mcols(all)$GENEID, mcols(all)$QUERYID),
      function(x) length(unique(x)) > 1))
## 
## FALSE  TRUE 
##   367    38
## Summarize the number of variants by gene:
idx <- sapply(split(mcols(all)$QUERYID, mcols(all)$GENEID), unique)
sapply(idx, length)
## 125144 162514  23729  51393   7442  84690 
##      1    196      2     63    146     35
## Summarize variant location by gene:
sapply(names(idx),
    function(nm) {
    d <- all[mcols(all)$GENEID %in% nm, c("QUERYID", "LOCATION")]
    table(mcols(d)$LOCATION[duplicated(d) == FALSE])
    })
##            125144 162514 23729 51393 7442 84690
## spliceSite      0      2     0     0    1     0
## intron          0    155     0    58  118    19
## fiveUTR         0      2     0     1    3     5
## threeUTR        0     24     2     1    2     0
## coding          0      5     0     3    8     0
## intergenic      0      0     0     0    0     0
## promoter        1     10     0     0   15    11

[ Back to top ]

4.6 Amino acid coding changes in non-synonymous variants

Amino acid coding for non-synonymous variants can be computed with the function predictCoding. The BSgenome.Hsapiens.UCSC.hg19 package is used as the source of the reference alleles. Variant alleles are provided by the user.

seqlevelsStyle(vcf) <- "UCSC"
seqlevelsStyle(txdb) <- "UCSC"
aa <- predictCoding(vcf, txdb, Hsapiens)
## Warning in valid.GenomicRanges.seqinfo(x, suggest.trim = TRUE): GRanges object contains 140 out-of-bound ranges located on sequences
##   62411, 62399, 62400, 62401, 62403, 62404, 62405, and 62407. Note
##   that ranges located on a sequence whose length is unknown (NA) or on
##   a circular sequence are not considered out-of-bound (use
##   seqlengths() and isCircular() to get the lengths and circularity
##   flags of the underlying sequences). You can use trim() to trim these
##   ranges. See ?`trim,GenomicRanges-method` for more information.
## Warning in .predictCodingGRangesList(query, cache[["cdsbytx"]], seqSource, :
## records with missing 'varAllele' were ignored
## Warning in .predictCodingGRangesList(query, cache[["cdsbytx"]], seqSource, :
## 'varAllele' values with 'N', '.', '+' or '-' were not translated

predictCoding returns results for coding variants only. As with locateVariants, the output has one row per variant-transcript match so multiple rows per variant are possible.

## Did any variants match more than one gene?
table(sapply(split(mcols(aa)$GENEID, mcols(aa)$QUERYID),
    function(x) length(unique(x)) > 1))
## 
## FALSE 
##    17
## Summarize the number of variants by gene:
idx <- sapply(split(mcols(aa)$QUERYID, mcols(aa)$GENEID, drop=TRUE), unique)
sapply(idx, length)
## 162514  51393   7442 
##      6      3      8
## Summarize variant consequence by gene:
sapply(names(idx),
       function(nm) {
       d <- aa[mcols(aa)$GENEID %in% nm, c("QUERYID","CONSEQUENCE")]
       table(mcols(d)$CONSEQUENCE[duplicated(d) == FALSE])
       })
##                162514 51393 7442
## nonsynonymous       2     0    2
## not translated      1     0    5
## synonymous          3     3    1

The variants ‘not translated’ are explained by the warnings thrown when predictCoding was called. Variants that have a missing varAllele or have an ‘N’ in the varAllele are not translated. If the varAllele substitution had resulted in a frameshift the consequence would be ‘frameshift’. See ?predictCoding for details.

[ Back to top ]

5 Exploring Package Content

Packages have extensive help pages, and include vignettes highlighting common use cases. The help pages and vignettes are available from within R. After loading a package, use syntax like

help(package="VariantAnnotation")
?predictCoding

to obtain an overview of help on the VariantAnnotation package, and the predictCoding function. View the package vignette with

browseVignettes(package="VariantAnnotation")

To view vignettes providing a more comprehensive introduction to package functionality use

help.start()

[ Back to top ]

6 sessionInfo()

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.9-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.9-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] variants_1.8.0                         
##  [2] PolyPhen.Hsapiens.dbSNP131_1.0.2       
##  [3] RSQLite_2.1.1                          
##  [4] BSgenome.Hsapiens.UCSC.hg19_1.4.0      
##  [5] BSgenome_1.52.0                        
##  [6] rtracklayer_1.44.0                     
##  [7] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
##  [8] GenomicFeatures_1.36.0                 
##  [9] org.Hs.eg.db_3.8.2                     
## [10] AnnotationDbi_1.46.0                   
## [11] cgdv17_0.21.0                          
## [12] VariantAnnotation_1.30.0               
## [13] Rsamtools_2.0.0                        
## [14] Biostrings_2.52.0                      
## [15] XVector_0.24.0                         
## [16] SummarizedExperiment_1.14.0            
## [17] DelayedArray_0.10.0                    
## [18] BiocParallel_1.18.0                    
## [19] matrixStats_0.54.0                     
## [20] Biobase_2.44.0                         
## [21] GenomicRanges_1.36.0                   
## [22] GenomeInfoDb_1.20.0                    
## [23] IRanges_2.18.0                         
## [24] S4Vectors_0.22.0                       
## [25] BiocGenerics_0.30.0                    
## [26] BiocStyle_2.12.0                       
## 
## loaded via a namespace (and not attached):
##  [1] progress_1.2.0           xfun_0.6                
##  [3] lattice_0.20-38          htmltools_0.3.6         
##  [5] yaml_2.2.0               blob_1.1.1              
##  [7] XML_3.98-1.19            rlang_0.3.4             
##  [9] DBI_1.0.0                bit64_0.9-7             
## [11] GenomeInfoDbData_1.2.1   stringr_1.4.0           
## [13] zlibbioc_1.30.0          evaluate_0.13           
## [15] memoise_1.1.0            knitr_1.22              
## [17] biomaRt_2.40.0           Rcpp_1.0.1              
## [19] BiocManager_1.30.4       bit_1.1-14              
## [21] hms_0.4.2                digest_0.6.18           
## [23] stringi_1.4.3            bookdown_0.9            
## [25] grid_3.6.0               tools_3.6.0             
## [27] bitops_1.0-6             magrittr_1.5            
## [29] RCurl_1.95-4.12          crayon_1.3.4            
## [31] pkgconfig_2.0.2          Matrix_1.2-17           
## [33] prettyunits_1.0.2        assertthat_0.2.1        
## [35] rmarkdown_1.12           httr_1.4.0              
## [37] R6_2.4.0                 GenomicAlignments_1.20.0
## [39] compiler_3.6.0

[ Back to top ]