Reads the body of a VCF file (lines after #CHROM) into a data.table.
The resulting table has whatever columns the VCF has (CHROM, POS, ID,
REF, ALT, QUAL, FILTER, INFO, and optionally FORMAT plus one
or more sample columns), with #CHROM renamed to CHROM.
Arguments
- file
Path or URL to the VCF file.
- filter
Controls which rows are kept based on the
FILTERcolumn:TRUE(default): keep rows whereFILTER %in% c("PASS", ".", "")— the union of passing values across common callers.FALSEorNULL: keep all rows.A character vector: keep rows where
FILTER %in% filter. Rows with noFILTERcolumn are always kept; a warning is emitted whenfilteris non-trivial in that case.
- name_of_vcf
Optional name for the VCF, used only for warning / error messages. Defaults to the filename with extension stripped.
Value
A data.table with one row per variant. The name of the first
column is 'CHROM', not '#CHROM'. Other column names
Details
Caller-agnostic. read_vcf() does not know or care which variant
caller produced the VCF. It does not parse FORMAT/sample columns and
does not extract VAF or read depth. The only caller-dependent semantics
is the default value of the filter argument (see below).
Uses data.table::fread() with
check.names=FALSE, na.strings = ""``, fill = TRUE`, to parse the VCF body. Handles uncompressed
and gzipped files; does not handle bgzipped/tabix.