Skip to content

Commit

Permalink
Make min.base.quality accessible in PureCN.R, throw warning when many…
Browse files Browse the repository at this point in the history
… variants are removed (#320).
  • Loading branch information
lima1 committed Sep 6, 2023
1 parent df67480 commit 43edf33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions R/filterVcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ function(vcf, tumor.id.in.vcf, allowed = 0.05) {
.filterVcfByBQ <- function(vcf, tumor.id.in.vcf, min.base.quality) {
n.vcf.before.filter <- .countVariants(vcf)
idx <- .getBQFromVcf(vcf, tumor.id.in.vcf, base.quality.offset = 0) < min.base.quality
if (sum(idx, na.rm = TRUE) / length(idx) > 0.5) {
flog.warn("Many variants removed by min.base.quality (%i) filter. You might want to lower the cutoff.", min.base.quality)
}
vcf <- .removeVariants(vcf, idx, "BQ", na.rm = FALSE)
flog.info("Removing %i low quality variants with non-offset BQ < %i.",
n.vcf.before.filter - .countVariants(vcf), min.base.quality)
Expand Down
12 changes: 8 additions & 4 deletions inst/extdata/PureCN.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ option_list <- list(
make_option(c("--base-quality-offset"), action = "store", type = "integer",
default = formals(PureCN::filterVcfBasic)$base.quality.offset,
help = "VCF Filter: Subtracts the specified value from the base quality score [default %default]"),
make_option(c("--min-base-quality"), action = "store", type = "integer",
default = formals(PureCN::filterVcfBasic)$min.base.quality,
help = "VCF Filter: Minimum base quality for variants. Set to 0 to turn off filter [default %default]"),
make_option(c("--min-supporting-reads"), action = "store", type = "integer",
default = formals(PureCN::filterVcfBasic)$min.supporting.reads,
help = "VCF Filter: Instead of calculating the min. number of supporting reads, use specified one [default %default]"),
Expand Down Expand Up @@ -177,14 +180,14 @@ alias_list <- list(
"maxhomozygousloss" = "max-homozygous-loss",
"speedupheuristics" = "speedup-heuristics",
"outvcf" = "out-vcf"
)
)
replace_alias <- function(x, deprecated = TRUE) {
idx <- match(x, paste0("--", names(alias_list)))
if (any(!is.na(idx))) {
replaced <- paste0("--", alias_list[na.omit(idx)])
x[!is.na(idx)] <- replaced
if (deprecated) {
flog.warn("Deprecated arguments, use %s instead.", paste(replaced, collapse=" "))
flog.warn("Deprecated arguments, use %s instead.", paste(replaced, collapse = " "))
}
}
return(x)
Expand Down Expand Up @@ -253,9 +256,9 @@ if (Sys.getenv("PURECN_DEBUG") != "") {
}

.checkFileList <- function(file) {
files <- read.delim(file, as.is = TRUE, header = FALSE)[,1]
files <- read.delim(file, as.is = TRUE, header = FALSE)[, 1]
numExists <- sum(file.exists(files), na.rm = TRUE)
if (numExists < length(files)) {
if (numExists < length(files)) {
stop("File not exists in file ", file)
}
files
Expand Down Expand Up @@ -397,6 +400,7 @@ if (file.exists(file.rds) && !opt$force) {
af.range = af.range, stats.file = opt$stats_file,
min.supporting.reads = opt$min_supporting_reads,
base.quality.offset = opt$base_quality_offset,
min.base.quality = opt$min_base_quality,
ignore = mutect.ignore,
interval.padding = opt$interval_padding),
args.filterIntervals = list(
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_filterVcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,10 @@ test_that("issue 249", {
vcf.bq <- PureCN:::.readAndCheckVcf(vcf.bq, "hg19")
expect_equal(NA, geno(vcf.bq)$BQ[[2, 1]])
})

test_that("issue 320", {
# set random BQ to NA
expect_output(x <- filterVcfBasic(vcf, use.somatic.status = FALSE, min.base.quality = 34),
"Many variants removed by min.base.quality")
expect_equal(34, min(sapply(geno(x$vcf)$BQ[,1], function(x) x[1])))
})

0 comments on commit 43edf33

Please sign in to comment.