From 4d7d9ea3ffcdaf138bdf7227317a499134b7bf9c Mon Sep 17 00:00:00 2001 From: John Muirhead-Gould Date: Mon, 6 Jul 2026 15:44:29 -0400 Subject: [PATCH] fix: readVcfStack(param=ScanVcfParam()) reads all files when which= is e --- R/VcfStack-class.R | 7 ++++++- inst/unitTests/test_VcfStack-class.R | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/VcfStack-class.R b/R/VcfStack-class.R index ee8c5f9..957a7fd 100644 --- a/R/VcfStack-class.R +++ b/R/VcfStack-class.R @@ -313,7 +313,12 @@ readVcfStack <- function(x, i, j=colnames(x), param=ScanVcfParam()) gr <- GRanges() } else { # use param gr <- GRanges(vcfWhich(param)) - i = intersect(names(files(x)), as.character(seqnames(gr))) + if (length(gr)) { + i = intersect(names(files(x)), as.character(seqnames(gr))) + } else { + ## param provided but no which= specified: read all files + i = names(files(x)) + } } x = x[i] diff --git a/inst/unitTests/test_VcfStack-class.R b/inst/unitTests/test_VcfStack-class.R index 2dcd9d8..3d268ce 100644 --- a/inst/unitTests/test_VcfStack-class.R +++ b/inst/unitTests/test_VcfStack-class.R @@ -223,6 +223,14 @@ test_VcfStack_readVcfStack <- function(){ Rstack = RangedVcfStack(stack, gr) temp7 = readVcfStack(Rstack) checkTrue(all(dim(temp7) == dim(temp5))) + + # test param=ScanVcfParam() with no which= reads all variants (#50) + # Previously returned 0-row VCF because empty which= intersected to empty i + tempParam = readVcfStack(Rstack, param=ScanVcfParam()) + checkTrue(all(dim(tempParam) == dim(temp7))) + + tempParamStack = readVcfStack(stack, param=ScanVcfParam()) + checkTrue(all(dim(tempParamStack) == dim(temp))) } test_VcfStack_vcfFields <- function(){