Skip to content

Commit

Permalink
fix: exact n of query with more elements than n
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer authored and fengelniederhammer committed Feb 12, 2024
1 parent 43e5e9e commit 1402019
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class VariantQueryCustomListener(val referenceGenomeSchema: ReferenceGenomeSchem

val n = ctx.nOfNumberOfMatchers().text.toInt()
val matchExactly = ctx.nOfMatchExactly() != null
val nOfExprs = ctx.nOfExprs().expr().size

val children = mutableListOf<SiloFilterExpression>()
for (i in 1..n) {
for (i in 1..nOfExprs) {
children += expressionStack.removeLast()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class VariantQueryFacadeTest {

@Test
fun `given a variantQuery with a 'Nof' expression then map should return the corresponding SiloQuery`() {
val variantQuery = "[3-of: 123A, 234T, 345G]"
val variantQuery = "[3-of: 123A, 234T, 345G, 456A]"

val result = underTest.map(variantQuery)

Expand All @@ -232,14 +232,15 @@ class VariantQueryFacadeTest {
NucleotideSymbolEquals(null, 123, "A"),
NucleotideSymbolEquals(null, 234, "T"),
NucleotideSymbolEquals(null, 345, "G"),
NucleotideSymbolEquals(null, 456, "A"),
),
)
assertThat(result, equalTo(expectedResult))
}

@Test
fun `given a variantQuery with a exact 'Nof' expression then map should return the corresponding SiloQuery`() {
val variantQuery = "[exactly-3-of: 123A, 234T, 345G]"
val variantQuery = "[exactly-3-of: 123A, 234T, 345G, 456A]"

val result = underTest.map(variantQuery)

Expand All @@ -250,6 +251,27 @@ class VariantQueryFacadeTest {
NucleotideSymbolEquals(null, 123, "A"),
NucleotideSymbolEquals(null, 234, "T"),
NucleotideSymbolEquals(null, 345, "G"),
NucleotideSymbolEquals(null, 456, "A"),
),
)
assertThat(result, equalTo(expectedResult))
}

@Test
@Suppress("ktlint:standard:max-line-length")
fun `given a variantQuery with a nested exact 'Nof' expression then map should return the corresponding SiloQuery`() {
val variantQuery = "[exactly-3-of: 123A, !234G, 345G, 456A]"

val result = underTest.map(variantQuery)

val expectedResult = NOf(
3,
true,
listOf(
NucleotideSymbolEquals(null, 123, "A"),
Not(NucleotideSymbolEquals(null, 234, "G")),
NucleotideSymbolEquals(null, 345, "G"),
NucleotideSymbolEquals(null, 456, "A"),
),
)
assertThat(result, equalTo(expectedResult))
Expand Down

0 comments on commit 1402019

Please sign in to comment.