Skip to content

Commit

Permalink
feat: e2e tests for filter by insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Sep 13, 2023
1 parent 3376cb7 commit fe8f0b9
Show file tree
Hide file tree
Showing 25 changed files with 513 additions and 218 deletions.
41 changes: 41 additions & 0 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/OpenApiDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.genspectrum.lapis.config.SequenceFilterFields
import org.genspectrum.lapis.controller.AGGREGATED_GROUP_BY_FIELDS_DESCRIPTION
import org.genspectrum.lapis.controller.AGGREGATED_REQUEST_SCHEMA
import org.genspectrum.lapis.controller.AGGREGATED_RESPONSE_SCHEMA
import org.genspectrum.lapis.controller.AMINO_ACID_INSERTIONS_PROPERTY
import org.genspectrum.lapis.controller.AMINO_ACID_INSERTIONS_SCHEMA
import org.genspectrum.lapis.controller.AMINO_ACID_MUTATIONS_PROPERTY
import org.genspectrum.lapis.controller.AMINO_ACID_MUTATIONS_RESPONSE_SCHEMA
import org.genspectrum.lapis.controller.AMINO_ACID_MUTATIONS_SCHEMA
Expand All @@ -25,6 +27,8 @@ import org.genspectrum.lapis.controller.LIMIT_DESCRIPTION
import org.genspectrum.lapis.controller.LIMIT_PROPERTY
import org.genspectrum.lapis.controller.LIMIT_SCHEMA
import org.genspectrum.lapis.controller.MIN_PROPORTION_PROPERTY
import org.genspectrum.lapis.controller.NUCLEOTIDE_INSERTIONS_PROPERTY
import org.genspectrum.lapis.controller.NUCLEOTIDE_INSERTIONS_SCHEMA
import org.genspectrum.lapis.controller.NUCLEOTIDE_MUTATIONS_PROPERTY
import org.genspectrum.lapis.controller.NUCLEOTIDE_MUTATIONS_RESPONSE_SCHEMA
import org.genspectrum.lapis.controller.NUCLEOTIDE_MUTATIONS_SCHEMA
Expand All @@ -35,7 +39,9 @@ import org.genspectrum.lapis.controller.ORDER_BY_FIELDS_SCHEMA
import org.genspectrum.lapis.controller.ORDER_BY_PROPERTY
import org.genspectrum.lapis.controller.REQUEST_SCHEMA_WITH_MIN_PROPORTION
import org.genspectrum.lapis.controller.SEQUENCE_FILTERS_SCHEMA
import org.genspectrum.lapis.request.AminoAcidInsertion
import org.genspectrum.lapis.request.AminoAcidMutation
import org.genspectrum.lapis.request.NucleotideInsertion
import org.genspectrum.lapis.request.NucleotideMutation
import org.genspectrum.lapis.request.OrderByField
import org.genspectrum.lapis.response.COUNT_PROPERTY
Expand All @@ -51,6 +57,8 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
val sequenceFilters = requestProperties +
Pair(NUCLEOTIDE_MUTATIONS_PROPERTY, nucleotideMutations()) +
Pair(AMINO_ACID_MUTATIONS_PROPERTY, aminoAcidMutations()) +
Pair(NUCLEOTIDE_INSERTIONS_PROPERTY, nucleotideInsertions()) +
Pair(AMINO_ACID_INSERTIONS_PROPERTY, aminoAcidInsertions()) +
Pair(ORDER_BY_PROPERTY, orderByPostSchema()) +
Pair(LIMIT_PROPERTY, limitSchema()) +
Pair(OFFSET_PROPERTY, offsetSchema()) +
Expand Down Expand Up @@ -130,6 +138,8 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
),
)
.addSchemas(AMINO_ACID_MUTATIONS_SCHEMA, aminoAcidMutations())
.addSchemas(NUCLEOTIDE_INSERTIONS_SCHEMA, nucleotideInsertions())
.addSchemas(AMINO_ACID_INSERTIONS_SCHEMA, aminoAcidInsertions())
.addSchemas(ORDER_BY_FIELDS_SCHEMA, orderByGetSchema())
.addSchemas(LIMIT_SCHEMA, limitSchema())
.addSchemas(OFFSET_SCHEMA, offsetSchema())
Expand Down Expand Up @@ -160,6 +170,8 @@ private fun mapToOpenApiType(type: MetadataType): String = when (type) {
MetadataType.DATE -> "string"
MetadataType.INT -> "integer"
MetadataType.FLOAT -> "number"
MetadataType.NUCLEOTIDE_INSERTION -> "string"
MetadataType.AMINO_ACID_INSERTION -> "string"
}

private fun primitiveSequenceFilterFieldSchemas(sequenceFilterFields: SequenceFilterFields) =
Expand Down Expand Up @@ -242,6 +254,35 @@ private fun aminoAcidMutations() =
),
)

private fun nucleotideInsertions() =
Schema<List<NucleotideInsertion>>()
.type("array")
.items(
Schema<String>()
.type("string")
.example("ins_123:ATT")
.description(
"""
|A nucleotide insertion in the format "ins_(\<sequenceName\>:)?\<position\>:\<insertion\>".
|If the sequenceName is not provided, LAPIS will use the default sequence name.
""".trimMargin(),
),
)

private fun aminoAcidInsertions() =
Schema<List<AminoAcidInsertion>>()
.type("array")
.items(
Schema<String>()
.type("string")
.example("ins_ORF1:123:ATT")
.description(
"""
|A amino acid insertion in the format "ins_\<gene\>:\<position\>:\<insertion\>".
""".trimMargin(),
),
)

private fun orderByGetSchema() = Schema<List<String>>()
.type("array")
.items(orderByFieldStringSchema())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ enum class MetadataType {

@JsonProperty("float")
FLOAT,

@JsonProperty("insertion")
NUCLEOTIDE_INSERTION,

@JsonProperty("aaInsertion")
AMINO_ACID_INSERTION,
}

data class DatabaseFeature(val name: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private fun mapToSequenceFilterFields(databaseMetadata: DatabaseMetadata) = when
"${databaseMetadata.name}From" to SequenceFilterFieldType.FloatFrom(databaseMetadata.name),
"${databaseMetadata.name}To" to SequenceFilterFieldType.FloatTo(databaseMetadata.name),
)
MetadataType.NUCLEOTIDE_INSERTION -> emptyList()
MetadataType.AMINO_ACID_INSERTION -> emptyList()
}

private fun mapToSequenceFilterFieldsFromFeatures(databaseFeature: DatabaseFeature) = when (databaseFeature.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const val AMINO_ACID_MUTATIONS_RESPONSE_SCHEMA = "AminoAcidMutationsResponse"

const val NUCLEOTIDE_MUTATIONS_SCHEMA = "NucleotideMutations"
const val AMINO_ACID_MUTATIONS_SCHEMA = "AminoAcidMutations"
const val NUCLEOTIDE_INSERTIONS_SCHEMA = "NucleotideInsertions"
const val AMINO_ACID_INSERTIONS_SCHEMA = "AminoAcidInsertions"

const val ORDER_BY_FIELDS_SCHEMA = "OrderByFields"
const val LIMIT_SCHEMA = "Limit"
const val OFFSET_SCHEMA = "Offset"
Expand Down Expand Up @@ -102,8 +105,10 @@ class LapisController(
@RequestParam
aminoAcidMutations: List<AminoAcidMutation>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
@Parameter(
schema = Schema(ref = "#/components/schemas/$LIMIT_SCHEMA"),
Expand Down Expand Up @@ -188,8 +193,10 @@ class LapisController(
@RequestParam
dataFormat: String? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = SequenceFiltersRequestWithFields(
Expand Down Expand Up @@ -254,8 +261,10 @@ class LapisController(
@RequestParam
dataFormat: String? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = SequenceFiltersRequestWithFields(
Expand Down Expand Up @@ -296,7 +305,7 @@ class LapisController(
responses = [ApiResponse(responseCode = "200")],
)
fun postAggregatedAsCsv(
@Parameter(schema = Schema(ref = "#/components/schemas/$DETAILS_REQUEST_SCHEMA"))
@Parameter(schema = Schema(ref = "#/components/schemas/$AGGREGATED_REQUEST_SCHEMA"))
@RequestBody
request: SequenceFiltersRequestWithFields,
): String {
Expand All @@ -310,7 +319,7 @@ class LapisController(
responses = [ApiResponse(responseCode = "200")],
)
fun postAggregatedAsTsv(
@Parameter(schema = Schema(ref = "#/components/schemas/$DETAILS_REQUEST_SCHEMA"))
@Parameter(schema = Schema(ref = "#/components/schemas/$AGGREGATED_REQUEST_SCHEMA"))
@RequestBody
request: SequenceFiltersRequestWithFields,
): String {
Expand Down Expand Up @@ -365,8 +374,10 @@ class LapisController(
@RequestParam
dataFormat: String? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): LapisResponse<List<NucleotideMutationResponse>> {
val mutationProportionsRequest = MutationProportionsRequest(
Expand Down Expand Up @@ -427,8 +438,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = MutationProportionsRequest(
Expand Down Expand Up @@ -487,8 +500,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = MutationProportionsRequest(
Expand Down Expand Up @@ -594,8 +609,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): LapisResponse<List<AminoAcidMutationResponse>> {
val mutationProportionsRequest = MutationProportionsRequest(
Expand Down Expand Up @@ -656,8 +673,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val mutationProportionsRequest = MutationProportionsRequest(
Expand Down Expand Up @@ -716,8 +735,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val mutationProportionsRequest = MutationProportionsRequest(
Expand Down Expand Up @@ -842,8 +863,10 @@ class LapisController(
@RequestParam
dataFormat: String? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): LapisResponse<List<DetailsData>> {
val request = SequenceFiltersRequestWithFields(
Expand Down Expand Up @@ -901,8 +924,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = SequenceFiltersRequestWithFields(
Expand Down Expand Up @@ -958,8 +983,10 @@ class LapisController(
@RequestParam
offset: Int? = null,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$NUCLEOTIDE_INSERTIONS_SCHEMA"))
nucleotideInsertions: List<NucleotideInsertion>?,
@RequestParam
@Parameter(schema = Schema(ref = "#/components/schemas/$AMINO_ACID_INSERTIONS_SCHEMA"))
aminoAcidInsertions: List<AminoAcidInsertion>?,
): String {
val request = SequenceFiltersRequestWithFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class AminoAcidInsertion(val position: Int, val gene: String, val insertion
"Invalid amino acid insertion: $aminoAcidInsertion: Did not find gene",
)

val insertions = matchGroups["insertion"]?.value?.replace("?", ".*")
val insertions = matchGroups["insertions"]?.value?.replace("?", ".*")
?: throw IllegalArgumentException(
"Invalid amino acid insertion: $aminoAcidInsertion: Did not find insertions",
)
Expand All @@ -41,7 +41,7 @@ data class AminoAcidInsertion(val position: Int, val gene: String, val insertion

private val AMINO_ACID_INSERTION_REGEX =
Regex(
"""^ins_(?<gene>[a-zA-Z0-9_-]+):(?<position>\d+):(?<insertion>[a-zA-Z0-9?_-]+)?$""",
"""^ins_(?<gene>[a-zA-Z0-9_-]+):(?<position>\d+):(?<insertions>(([a-zA-Z?]|(\.\*))+))$""",
)

@JsonComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class NucleotideInsertion(val position: Int, val insertions: String, val se

private val NUCLEOTIDE_INSERTION_REGEX =
Regex(
"""^ins_((?<segment>[a-zA-Z0-9_-]+)(?=:):)?(?<position>\d+):(?<insertions>[a-zA-Z0-9?_-]+)?$""",
"""^ins_((?<segment>[a-zA-Z0-9_-]+)(?=:):)?(?<position>\d+):(?<insertions>(([a-zA-Z?]|(\.\*))+))$""",
)

@JsonComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class DatabaseConfigTest {
DatabaseMetadata(name = "region", type = MetadataType.STRING),
DatabaseMetadata(name = "country", type = MetadataType.STRING),
DatabaseMetadata(name = "pangoLineage", type = MetadataType.PANGO_LINEAGE),
DatabaseMetadata(name = "nucInsertion", type = MetadataType.NUCLEOTIDE_INSERTION),
DatabaseMetadata(name = "aaInsertion", type = MetadataType.AMINO_ACID_INSERTION),
),
)
assertThat(
Expand Down Expand Up @@ -56,6 +58,8 @@ class DatabaseConfigWithoutFeaturesTest {
DatabaseMetadata(name = "region", type = MetadataType.STRING),
DatabaseMetadata(name = "country", type = MetadataType.STRING),
DatabaseMetadata(name = "pangoLineage", type = MetadataType.PANGO_LINEAGE),
DatabaseMetadata(name = "nucInsertion", type = MetadataType.NUCLEOTIDE_INSERTION),
DatabaseMetadata(name = "aaInsertion", type = MetadataType.AMINO_ACID_INSERTION),
),
)
assertThat(underTest.schema.features, `is`(emptyList()))
Expand Down
Loading

0 comments on commit fe8f0b9

Please sign in to comment.