Learn R Programming

VariantAnnotation (version 1.12.9)

filterVcf: Filter VCF files

Description

Filter Variant Call Format (VCF) files from one file to another

Usage

"filterVcf"(file, genome, destination, ..., verbose = TRUE, index = FALSE, prefilters = FilterRules(), filters = FilterRules(), param = ScanVcfParam())
"filterVcf"(file, genome, destination, ..., verbose = TRUE, index = FALSE, prefilters = FilterRules(), filters = FilterRules(), param = ScanVcfParam())

Arguments

file
A character(1) file path or TabixFile specifying the VCF file to be filtered.
genome
A character(1) identifier
destination
A character(1) path to the location where the filtered VCF file will be written.
...
Additional arguments, possibly used by future methods.
verbose
A logical(1) indicating whether progress messages should be printed.
index
A logical(1) indicating whether the filtered file should be compressed and indexed (using bgzip and indexTabix).
prefilters
A FilterRules instance contains rules for filtering un-parsed lines of the VCF file.
filters
A FilterRules instance contains rules for filtering fully parsed VCF objects.
param
A ScanVcfParam instance restricting input of particular info or geno fields, or genomic locations. Applicable when applying a filter only. Prefiltering involves a grep of unparsed lines in the file; indexing is not used.

Value

character(1).

Details

This function transfers content of one VCF file to another, removing records that fail to satisfy prefilters and filters. Filtering is done in a memory efficient manner, iterating over the input VCF file in chunks of default size 100,000 (when invoked with character(1) for file) or as specified by the yieldSize argument of TabixFile (when invoked with TabixFile).

There are up to two passes. In the first pass, unparsed lines are passed to prefilters for filtering, e.g., searching for a fixed character string. In the second pass lines successfully passing prefilters are parsed into VCF instances and made available for further filtering. One or both of prefilter and filter can be present.

See Also

readVcf, writeVcf.

Examples

Run this code
fl <- system.file(package="VariantAnnotation", "extdata",
                  "chr22.vcf.gz")
destination <- tempfile()
pre <- FilterRules(list(isLowCoverageExomeSnp = function(x) {
    grepl("LOWCOV,EXOME", x, fixed=TRUE)
}))
filt <- FilterRules(list(isSNP = function(x) info(x)$VT == "SNP"))
filtered <- filterVcf(fl, "hg19", destination, prefilters=pre, filters=filt)
vcf <- readVcf(filtered, "hg19")

Run the code above in your browser using DataLab