Selecting and classifying variants with VariantAnnotation can be done using the following steps:
- Create a prefilter function:
is_not_microsat <- function(x){ !grepl("microsat", x, fixed = TRUE)}
- Load up the prefilter function into a FilterRules object:
prefilters <- FilterRules(list(microsat = is_not_microsat) )
- Create a filter function to keep variants where the reference allele is in less than half the reads:
major_alt <- function(x){
af <- info(x)$AF
result <- unlist(lapply(af, function(x){x[1] < 0.5}))
return(result)
}
- Load the filter function into a FilterRules object:
filters <- FilterRules(list(alt_is_major = major_alt))
- Load the input VCF file and apply filters:
vcf_file <- file.path(getwd(), "datasets", "ch2", "sample.vcf.gz")
filterVcf(vcf_file, "hg17", "filtered.vcf", prefilters = prefilters, filters = filters)