Skip to content

Commit

Permalink
fix: set default min proportion
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Dec 19, 2023
1 parent 79c9f2d commit d033b34
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.genspectrum.lapis.openApi.REQUEST_SCHEMA_WITH_MIN_PROPORTION
import org.genspectrum.lapis.request.AminoAcidInsertion
import org.genspectrum.lapis.request.AminoAcidMutation
import org.genspectrum.lapis.request.CommonSequenceFilters
import org.genspectrum.lapis.request.DEFAULT_MIN_PROPORTION
import org.genspectrum.lapis.request.Field
import org.genspectrum.lapis.request.MutationProportionsRequest
import org.genspectrum.lapis.request.NucleotideInsertion
Expand Down Expand Up @@ -290,7 +291,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down Expand Up @@ -345,7 +346,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down Expand Up @@ -394,7 +395,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down Expand Up @@ -483,7 +484,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down Expand Up @@ -534,7 +535,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down Expand Up @@ -583,7 +584,7 @@ class LapisController(
@RequestParam(required = false)
@AminoAcidMutations
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam minProportion: Double?,
@RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?,
@MutationsOrderByFields
@RequestParam
orderBy: List<OrderByField>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.genspectrum.lapis.controller.BadRequestException
import org.genspectrum.lapis.controller.MIN_PROPORTION_PROPERTY
import org.springframework.boot.jackson.JsonComponent

const val DEFAULT_MIN_PROPORTION = 0.05

data class MutationProportionsRequest(
override val sequenceFilters: Map<String, String>,
override val nucleotideMutations: List<NucleotideMutation>,
Expand All @@ -32,7 +34,7 @@ class MutationProportionsRequestDeserializer : JsonDeserializer<MutationProporti
val codec = jsonParser.codec

val minProportion = when (val minProportionNode = node.get(MIN_PROPORTION_PROPERTY)) {
null, is NullNode -> null
null, is NullNode -> DEFAULT_MIN_PROPORTION
is NumericNode -> minProportionNode.doubleValue()

else -> throw BadRequestException("minProportion must be a number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package org.genspectrum.lapis.controller
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.IntNode
import com.fasterxml.jackson.databind.node.TextNode
import com.fasterxml.jackson.module.kotlin.readValue
import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.genspectrum.lapis.model.SiloQueryModel
import org.genspectrum.lapis.request.DEFAULT_MIN_PROPORTION
import org.genspectrum.lapis.request.Field
import org.genspectrum.lapis.request.MutationProportionsRequest
import org.genspectrum.lapis.request.NucleotideMutation
Expand Down Expand Up @@ -170,7 +172,7 @@ class LapisControllerTest(
@ParameterizedTest(name = "GET {0} without explicit minProportion")
@MethodSource("getMutationEndpoints")
fun `GET mutations without explicit minProportion`(endpoint: String) {
setupMutationMock(endpoint, null)
setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION)

mockMvc.perform(getSample("$endpoint?country=Switzerland"))
.andExpect(status().isOk)
Expand All @@ -196,7 +198,7 @@ class LapisControllerTest(
@ParameterizedTest(name = "POST {0} without explicit minProportion")
@MethodSource("getMutationEndpoints")
fun `POST mutations without explicit minProportion`(endpoint: String) {
setupMutationMock(endpoint, null)
setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION)

val request = postSample(endpoint)
.content("""{"country": "Switzerland"}""")
Expand Down Expand Up @@ -245,13 +247,13 @@ class LapisControllerTest(
@ParameterizedTest(name = "GET {0} only returns mutation, proportion and count")
@MethodSource("getMutationEndpoints")
fun `GET mutations only returns mutation, proportion and count`(endpoint: String) {
setupMutationMock(endpoint, null)
setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION)

val mvcResult = mockMvc.perform(getSample("$endpoint?country=Switzerland"))
.andExpect(status().isOk)
.andReturn()

val response = ObjectMapper().readValue(mvcResult.response.contentAsString, Map::class.java)
val response = ObjectMapper().readValue<Map<*, *>>(mvcResult.response.contentAsString)
val data = response["data"] as List<*>
val firstDataObject = data[0] as Map<*, *>

Expand All @@ -261,7 +263,7 @@ class LapisControllerTest(

private fun setupMutationMock(
endpoint: String,
minProportion: Double?,
minProportion: Double = DEFAULT_MIN_PROPORTION,
) {
if (endpoint == "/nucleotideMutations") {
every {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MutationProportionsRequestTest {
emptyList(),
emptyList(),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
Expand All @@ -71,6 +72,7 @@ class MutationProportionsRequestTest {
emptyList(),
emptyList(),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
Expand All @@ -85,6 +87,7 @@ class MutationProportionsRequestTest {
listOf(AminoAcidMutation("S", 501, "Y"), AminoAcidMutation("ORF1b", 12, null)),
emptyList(),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
Expand All @@ -102,6 +105,7 @@ class MutationProportionsRequestTest {
NucleotideInsertion(12, "ABCD", null),
),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
Expand All @@ -119,6 +123,7 @@ class MutationProportionsRequestTest {
AminoAcidInsertion(501, "S", "Y"),
AminoAcidInsertion(12, "ORF1", "ABCD"),
),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
Expand All @@ -135,14 +140,28 @@ class MutationProportionsRequestTest {
"accessKey": "some access key"
}
""",
MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()),
MutationProportionsRequest(
emptyMap(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
Arguments.of(
"""
{
}
""",
MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()),
MutationProportionsRequest(
emptyMap(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
minProportion = DEFAULT_MIN_PROPORTION,
),
),
)

Expand Down

0 comments on commit d033b34

Please sign in to comment.