AnVILVRS 0.99.19
The AnVILVRS package provides an R interface to the AnVIL VRS Toolkit, a Python library for working with the Global Alliance for Genomics and Health (GA4GH) Variation Representation Specification (VRS) standard. The package allows users to translate variant identifiers from various formats (e.g., gnomAD, SPDI, HGVS, Beacon) into GA4GH VRS Allele IDs and vice versa. Additionally, it provides functionality to retrieve allele frequency data from the 1000 Genomes Project based on VRS Allele IDs.
To use the AnVILVRS package, you need to have Python installed on your system. The package requires Python 3.11, so ensure that you have this version installed.
Install the AnVILVRS package from Bioconductor with:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("AnVILVRS")
Load the AnVILVRS package and the reticulate package for Python
integration:
library(AnVILVRS)
library(reticulate)
After installing the package, you need to set up a Python virtual environment with the required dependencies. You can do this by running the following command in R:
install_AnVILVRS(envname = "vrs_env")
Once the virtual environment is set up, you can use the AnVILVRS package to translate variant identifiers and retrieve allele frequency data. First, load the package and activate the virtual environment:
use_virtualenv("vrs_env", required = TRUE)
You can translate variant identifiers from various formats into GA4GH VRS Allele
IDs using the get_vrs_id function. Supported formats include “gnomad”,
“spdi”, “hgvs”, and “beacon”.
get_vrs_id("chr7-87509329-A-G", "gnomad")
get_vrs_id("NC_000005.10:80656509:C:TT", "spdi")
get_vrs_id("NC_000005.10:g.80656510delinsTT", "hgvs")
get_vrs_id("5 : 80656489 C > T", "beacon")
You can also retrieve the VRS Allele object using the get_vrs_allele function:
allele <- get_vrs_allele("5 : 80656489 C > T", "beacon")
allele
You can convert a VRS Allele object back to a variant identifier in a specified
format using the get_variant_from_allele function:
get_variant_from_allele(allele, "hgvs")
The get_pop_descriptor function downloads the population descriptor file from
a known Google Storage URI to the BiocFileCache. This file is
used in the calculation of the Cohort Allele Frequency (CAF). The get_caf
function makes use of the population descriptor .tsv file to dynamically
provide a Cohort Allele Frequency based on the sub-population of interest. In
our example, we will use the “USA” population code.
library(readr)
pop_desc <- get_pop_descriptor()
read_tsv(
file = pop_desc,
col_types = cols(
population_descriptor_id = col_character(),
population_descriptor = col_character(),
subject_id = col_character(),
country_of_recruitment = col_character(),
population_label = col_character()
)
)
The get_seqrepo function downloads a SeqRepo archive from a specified URI to
a local directory. This is useful for setting up the SeqRepo database required
by the AnVIL VRS Toolkit.
get_seqrepo(destdir = tempdir())
Finally, to calculate the Cohort Allele Frequency (CAF) using the 1000 Genomes
Project based on a VRS Allele ID, use the get_caf function. A .gz zipped VCF
file and its corresponding index file obtained from the 1000 Genomes Project is
needed. It should include variants with allele frequency annotations.
use_virtualenv("vrs_env", required = TRUE)
toolkit_dir <- setup_vrs_toolkit()
vcf <- AnVILVRS:::.get_fixture_vcf()
vcf_index <- build_vrs_index()
variant_id <- "chr1-20094-TAA-T"
vrs_id <- get_vrs_id(variant_id, "gnomad")
pop_desc <- get_pop_descriptor()
get_caf(
vrs_id = vrs_id,
vcf = vcf,
vcf_index = vcf_index,
phenotype = "USA",
pop_desc_file = pop_desc,
toolkit_dir = toolkit_dir
)
Click to expand session info
sessionInfo()
#> R version 4.6.0 RC (2026-04-17 r89917)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.24-bioc/R/lib/libRblas.so
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_GB 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
#>
#> time zone: America/New_York
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] reticulate_1.46.0 AnVILVRS_0.99.19 BiocStyle_2.41.0
#>
#> loaded via a namespace (and not attached):
#> [1] rappdirs_0.3.4 sass_0.4.10 generics_0.1.4
#> [4] tidyr_1.3.2 RSQLite_2.4.6 lattice_0.22-9
#> [7] digest_0.6.39 magrittr_2.0.5 evaluate_1.0.5
#> [10] grid_4.6.0 bookdown_0.46 fastmap_1.2.0
#> [13] blob_1.3.0 jsonlite_2.0.0 Matrix_1.7-5
#> [16] AnVILGCP_1.7.0 DBI_1.3.0 BiocManager_1.30.27
#> [19] httr_1.4.8 purrr_1.2.2 codetools_0.2-20
#> [22] httr2_1.2.2 jquerylib_0.1.4 cli_3.6.6
#> [25] rlang_1.2.0 dbplyr_2.5.2 bit64_4.8.0
#> [28] cachem_1.1.0 yaml_2.3.12 otel_0.2.0
#> [31] BiocBaseUtils_1.15.0 tools_4.6.0 memoise_2.0.1
#> [34] dplyr_1.2.1 filelock_1.0.3 GCPtools_1.3.0
#> [37] curl_7.1.0 vctrs_0.7.3 R6_2.6.1
#> [40] png_0.1-9 lifecycle_1.0.5 BiocFileCache_3.3.0
#> [43] bit_4.6.0 pkgconfig_2.0.3 pillar_1.11.1
#> [46] bslib_0.10.0 glue_1.8.1 Rcpp_1.1.1-1.1
#> [49] xfun_0.57 tibble_3.3.1 tidyselect_1.2.1
#> [52] knitr_1.51 AnVILBase_1.7.0 htmltools_0.5.9
#> [55] rmarkdown_2.31 compiler_4.6.0