Skip to content

Commit

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

single:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import VariantQueryBaseListener
import VariantQueryParser.AndContext
import VariantQueryParser.NotContext
import VariantQueryParser.Nucleotide_mutationContext
import VariantQueryParser.OrContext
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.Or
import org.genspectrum.lapis.silo.SiloFilterExpression

class VariantQueryCustomListener : VariantQueryBaseListener(), ParseTreeListener {
Expand Down Expand Up @@ -37,4 +39,9 @@ class VariantQueryCustomListener : VariantQueryBaseListener(), ParseTreeListener
val child = expressionStack.removeLast()
expressionStack.addLast(Not(child))
}

override fun exitOr(ctx: OrContext?) {
val children = listOf(expressionStack.removeLast(), expressionStack.removeLast()).reversed()
expressionStack.addLast(Or(children))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ object True : SiloFilterExpression("True")

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

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

data class Not(val child: SiloFilterExpression) : SiloFilterExpression("Not")
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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.genspectrum.lapis.silo.Or
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -70,4 +71,19 @@ class VariantQueryFacadeTest {
val expectedResult = Not(NucleotideSymbolEquals(300, "G"))
MatcherAssert.assertThat(result, Matchers.equalTo(expectedResult))
}

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

val result = underTest.map(variantQuery)

val expectedResult = Or(
listOf(
NucleotideSymbolEquals(300, "G"),
NucleotideSymbolEquals(400, "-"),
),
)
MatcherAssert.assertThat(result, Matchers.equalTo(expectedResult))
}
}
20 changes: 20 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 @@ -201,6 +201,26 @@ class SiloQueryTest {
}
""",
),
Arguments.of(
Or(listOf(StringEquals("theColumn", "theValue"), StringEquals("theOtherColumn", "theOtherValue"))),
"""
{
"type": "Or",
"children": [
{
"type": "StringEquals",
"column": "theColumn",
"value": "theValue"
},
{
"type": "StringEquals",
"column": "theOtherColumn",
"value": "theOtherValue"
}
]
}
""",
),
)
}
}

0 comments on commit 5a0ef38

Please sign in to comment.