Fast and Memory-Efficient Manipulation and Conversion of VCF Files

Reads Variant Call Format (VCF) files into an S4 object whose genotypes are stored on disk as an 'Apache Arrow' dataset and loaded lazily, allowing large datasets to be processed with little memory. Provides functions to filter variants and samples, subset and merge datasets, compute summary statistics and diagnostic plots, write VCF files, and convert data to input formats of population genetic and phylogenetic software such as 'STRUCTURE', 'ADMIXTURE', 'PLINK', 'EIGENSTRAT', 'Arlequin', 'GENEPOP', 'BayeScan', 'TreeMix', 'SNAPP' and 'adegenet'.


VCFArrow

CRANstatus

Installation

The released version can be installed from CRAN with install.packages("VCFArrow"), and the development version from GitHub with pak::pak("legalLab/VCFArrow") or devtools::install_github("legalLab/VCFArrow").

Installing from GitHub compiles the package’s C++ code, which needs a compiler: Rtools on Windows, or the Xcode command line tools on macOS (xcode-select --install). Without one, use a precompiled binary instead. Each GitHub release provides two:

  • VCFArrow_<version>.zip for Windows;
  • VCFArrow_<version>.tgz for macOS on Apple silicon (M1 and later).

Both are built for the current R release. A binary contains the latest tagged version, which can be older than the code on GitHub. Its dependencies are not installed with it, so install them first. Then install the binary file:

# if necessary install dependencies
install.packages(c("Rcpp", "arrow", "cli", "dplyr", "ggplot2", "stringr", "tibble", "vctrs"))
# then install directly from Github
install.packages("https://github.com/legalLab/VCFArrow/releases/download/v1.0.0/VCFArrow_1.0.0.zip", repos = NULL, type = "win.binary")  # Windows
install.packages("https://github.com/legalLab/VCFArrow/releases/download/v1.0.0/VCFArrow_1.0.0.tgz", repos = NULL, type = "mac.binary")  # macOS
# or your download folder if you downloaded it
install.packages("~/Downloads/VCFArrow_1.0.0.zip", repos = NULL)  # Windows
install.packages("~/Downloads/VCFArrow_1.0.0.tgz", repos = NULL)  # macOS

Two packages are optional and only needed for specific functions: adegenet, for vcf2genlight(), and svglite, for SVG plots (without it, SVG plots are written with R’s own Cairo device). Install them with install.packages(c("adegenet", "svglite")).

The package is built around Apache Arrow, accessed through the arrow R package.

Introduction

This package has six main functionalities: (1) reading in and writing out VCF data files, including precalculation of diverse metrics used in the filtering functions; (2) data filtering functions; (3) merging VCFs; (4) subsetting VCFs; (5) generation of summary statistics and graphs; and (6) data transformation and writing out of other data formats (population genetic and phylogenetic formats) for downstream analyses. This package is a reimagination of the vcf2others package. Same as vcf2others, it uses the Apache Arrow library functions to manipulate SNP data via dplyr verb equivalents. However, unlike vcf2others, VCFArrow now reads in the VCF data file into an S4 R object constructed around an Apache Arrow data structure. It precalculates a number of metrics and stores them in the S4 object. The VCF genotype matrix is stored as a long tidy table, and the data in the S4 object are lazy loaded. Many common tasks have been delegated to shared, C++ backed APIs and functions, and these operations have been parallelized when possible. These modifications and optimizations now permit extremely fast data filtering, manipulation and transformation. It is possible to process VCFs comprising tens of millions of SNVs and hundreds of individuals in a matter of seconds to minutes with minimal RAM overhead. A comparison of VCFArrow with vcftools, vcfR and tidypopgen on a dataset of 18.6 million variants and 56 samples (run time, memory, and what each tool computes for the same function) is available in VCFArrow, vcftools, vcfR and tidypopgen compared.

Cookbook

How to use the functions of this package with examples of common workflows is available in the vignette.

Meta

News

The Github version is in sync with CRAN. See NEWS for details.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("VCFArrow")

1.0.0 by Tomas Hrbek, 2 days ago


https://legallab.github.io/VCFArrow/, https://github.com/legalLab/VCFArrow


Report a bug at https://github.com/legalLab/VCFArrow/issues


Browse source code at https://github.com/cran/VCFArrow


Authors: Tomas Hrbek [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports Rcpp, arrow, cli, dplyr, ggplot2, methods, parallel, stats, stringr, tibble, utils, vctrs

Suggests adegenet, knitr, rmarkdown, svglite

Linking to Rcpp

System requirements: zlib


See at CRAN