Table of Contents
Background
Top
R version: R version 3.5.0 Patched (2018-05-03 r74699)
Bioconductor version: 3.8
Package version: 1.3.0
Table of Contents
Set Up
Version Info
Top
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
Table of Contents
Exploring variants in the TRPV gene family
Background
Top
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 biocLite() to get the packages you don’t have installed:
## try http:// if https:// URLs are not supported
source("https://bioconductor.org/biocLite.R")
biocLite("mypackage")
Table of Contents
Exploring Package Content
Set Up
Top
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")
Table of Contents
Convert gene symbols to gene ids
Exploring variants in the TRPV gene family
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)$META
## DataFrame with 5 rows and 1 column
## Value
## <character>
## fileformat VCFv4.1
## fileDate 20111102
## source masterVar2VCFv40
## reference build37.fa.bz2
## phasing partial
[ Back to top ]
Table of Contents
Create gene ranges
Examine header data in a vcf file
Exploring variants in the TRPV gene family
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 ]
Table of Contents
Extract variant subsets
Convert gene symbols to gene ids
Exploring variants in the TRPV gene family
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 ]
Table of Contents
Variant location in the gene model
Create gene ranges
Exploring variants in the TRPV gene family
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: cPd, GT
## geno(header(vcf)):
## Number Type Description
## cPd 1 String called Ploidy(level)
## GT 1 String Genotype
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): cPd GT
[ Back to top ]
Table of Contents
Amino acid coding changes in non-synonymous variants
Extract variant subsets
Exploring variants in the TRPV gene family
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 153 0 58 117 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 ]
Table of Contents
Variant location in the gene model
Exploring variants in the TRPV gene family
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 ]
Table of Contents
Exploring variants in the TRPV gene family
Top
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 ]
Table of Contents
Exploring Package Content
Top
sessionInfo()
## R version 3.5.0 Patched (2018-05-03 r74699)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.4 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.8-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.8-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=en_US.UTF-8
## [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.3.0
## [2] PolyPhen.Hsapiens.dbSNP131_1.0.2
## [3] RSQLite_2.1.1
## [4] BSgenome.Hsapiens.UCSC.hg19_1.4.0
## [5] BSgenome_1.49.0
## [6] rtracklayer_1.41.2
## [7] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
## [8] GenomicFeatures_1.33.0
## [9] org.Hs.eg.db_3.6.0
## [10] AnnotationDbi_1.43.1
## [11] cgdv17_0.19.0
## [12] VariantAnnotation_1.27.1
## [13] Rsamtools_1.33.0
## [14] Biostrings_2.49.0
## [15] XVector_0.21.1
## [16] SummarizedExperiment_1.11.3
## [17] DelayedArray_0.7.0
## [18] BiocParallel_1.15.3
## [19] matrixStats_0.53.1
## [20] Biobase_2.41.0
## [21] GenomicRanges_1.33.4
## [22] GenomeInfoDb_1.17.1
## [23] IRanges_2.15.12
## [24] S4Vectors_0.19.4
## [25] BiocGenerics_0.27.0
## [26] BiocStyle_2.9.1
##
## loaded via a namespace (and not attached):
## [1] progress_1.1.2 xfun_0.1 lattice_0.20-35
## [4] htmltools_0.3.6 yaml_2.1.19 blob_1.1.1
## [7] XML_3.98-1.11 DBI_1.0.0 bit64_0.9-7
## [10] GenomeInfoDbData_1.1.0 stringr_1.3.1 zlibbioc_1.27.0
## [13] evaluate_0.10.1 memoise_1.1.0 knitr_1.20
## [16] biomaRt_2.37.1 BiocInstaller_1.31.1 Rcpp_0.12.16
## [19] backports_1.1.2 bit_1.1-13 digest_0.6.15
## [22] stringi_1.2.2 bookdown_0.7 grid_3.5.0
## [25] rprojroot_1.3-2 tools_3.5.0 bitops_1.0-6
## [28] magrittr_1.5 RCurl_1.95-4.10 pkgconfig_2.0.1
## [31] Matrix_1.2-14 prettyunits_1.0.2 assertthat_0.2.0
## [34] rmarkdown_1.9 httr_1.3.1 R6_2.2.2
## [37] GenomicAlignments_1.17.1 compiler_3.5.0
[ Back to top ]