read_vcf() reads plain or gzip-compressed VCF files (including large DiscoSnp-RAD output) into a VCFArrow S4 object. Variant information is kept in memory; genotypes are written to disk as an ‘Apache Arrow’ dataset in chunks and read lazily, so datasets larger than memory can be processed.
set_vcf_groups() assigns samples to groups (populations); vcf_copy() makes an independent copy; vcf_gc() deletes the on-disk data of objects that are no longer referenced.
vcf_filter_adr() corrects or removes genotypes with an extreme allele depth ratio (ALT / (REF + ALT)): they are changed to homozygous or set to missing.
vcf_bind() merges objects with the same or different samples, matching variants by CHROM, POS, REF and ALT, in "intersect" or "union" mode, with an ingroup/outgroup mode (outgroup = TRUE) and optional recovery of previously filtered loci (recover_loci = TRUE). vcf_bind_sparse() is a deprecated alias of vcf_bind(..., recover_loci = TRUE).
Statistics and plots
vcf_stats() computes per-sample statistics (heterozygosity, missing data, depth) and, optionally, Watterson’s theta and nucleotide diversity per group (vcf_theta()), accumulated chunk by chunk with little memory.
vcf_set_workers() runs the per-chunk work of reading, filtering, statistics, merging and exporting on background R processes. Results do not depend on the number of workers.
Performance-critical steps (VCF parsing, per-sample counts, theta and pi, writers of the exported formats) are implemented in C++.
Dependencies
‘adegenet’ (for vcf2genlight()) and ‘svglite’ (for SVG plots) are suggested rather than imported; without ‘svglite’, SVG plots are written with R’s Cairo device.