VCFArrow

CRAN status

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:

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.

mirror server hosted at Truenetwork, Russian Federation.