Skip to contents

Read in a VCF file and convert it to a GenomicRanges object or data.table with preserved INFO and FORMAT metadata. The function extracts all VCF fields including CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO, and FORMAT columns. The VCF file can be either zipped or unzipped.

Usage

read_vcf_file(
  vcf_file,
  output_type = c("gr", "dt"),
  sample_names = NULL,
  parse_info = TRUE,
  parse_format = TRUE,
  cpus = 1,
  seq_lengths = gUtils::hg_seqlengths(),
  verbose = TRUE
)

Arguments

vcf_file

Path to VCF file (supports .vcf, .vcf.gz, .vcf.bgz)

output_type

Character string specifying output format: gr="GenomicRanges" (default) or dt="data.table"

sample_names

Character vector of sample names to extract from FORMAT fields. If NULL, all samples are extracted. Default: NULL

parse_info

Logical, whether to parse INFO field into separate columns. Default: TRUE

parse_format

Logical, whether to parse FORMAT fields for each sample. Default: TRUE

cpus

Integer, number of CPUs for parallel processing. Default: 1

seq_lengths

Named vector object used as template for new seq details. See gUtils::hg_seqlengths() for example. Default: hg38 seqlengths. Only used when output_type = "GenomicRanges"

verbose

Logical, whether to print progress messages. Default: TRUE

Value

GenomicRanges object or data.table with VCF data including INFO and FORMAT fields