Skip to content

Commit

Permalink
feat: add not expression to variantQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Apr 27, 2023
1 parent 3a7a7a2 commit 4b59e14
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ grammar VariantQuery;
start: expr EOF;
expr:
single # Uni
| '!' expr # Not
| expr '&' expr # And
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.genspectrum.lapis.model

import VariantQueryBaseListener
import VariantQueryParser.AndContext
import VariantQueryParser.NotContext
import VariantQueryParser.Nucleotide_mutationContext
import org.antlr.v4.runtime.tree.ParseTreeListener
import org.genspectrum.lapis.silo.And
import org.genspectrum.lapis.silo.Not
import org.genspectrum.lapis.silo.NucleotideSymbolEquals
import org.genspectrum.lapis.silo.SiloFilterExpression

Expand All @@ -30,4 +32,9 @@ class VariantQueryCustomListener : VariantQueryBaseListener(), ParseTreeListener
val children = listOf(expressionStack.removeLast(), expressionStack.removeLast()).reversed()
expressionStack.addLast(And(children))
}

override fun exitNot(ctx: NotContext?) {
val child = expressionStack.removeLast()
expressionStack.addLast(Not(child))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ data class DateBetween(val column: String, val from: LocalDate?, val to: LocalDa
object True : SiloFilterExpression("True")

data class And(val children: List<SiloFilterExpression>) : SiloFilterExpression("And")

data class Not(val child: SiloFilterExpression) : SiloFilterExpression("Not")
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.genspectrum.lapis.model

import org.genspectrum.lapis.silo.And
import org.genspectrum.lapis.silo.Not
import org.genspectrum.lapis.silo.NucleotideSymbolEquals
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
Expand Down Expand Up @@ -59,4 +60,14 @@ class VariantQueryFacadeTest {
)
MatcherAssert.assertThat(result, Matchers.equalTo(expectedResult))
}

@Test
fun `given a variant variantQuery with a not expression the map should return the corresponding SiloQuery`() {
val variantQuery = "!300G"

val result = underTest.map(variantQuery)

val expectedResult = Not(NucleotideSymbolEquals(300, "G"))
MatcherAssert.assertThat(result, Matchers.equalTo(expectedResult))
}
}
13 changes: 13 additions & 0 deletions lapis2/src/test/kotlin/org/genspectrum/lapis/silo/SiloQueryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ class SiloQueryTest {
}
""",
),
Arguments.of(
Not(StringEquals("theColumn", "theValue")),
"""
{
"type": "Not",
"child": {
"type": "StringEquals",
"column": "theColumn",
"value": "theValue"
}
}
""",
),
)
}
}

0 comments on commit 4b59e14

Please sign in to comment.