From e40602300286b2948a9c8e16fdc8d4963e2a1f4a Mon Sep 17 00:00:00 2001 From: Jonas Kellerer Date: Tue, 9 Jan 2024 14:14:49 +0100 Subject: [PATCH] feat: provide full reference genome, and database config to new endpoints --- .../org/genspectrum/lapis/LapisApplication.kt | 8 +-- .../genspectrum/lapis/LapisSpringConfig.kt | 29 ++++++++--- .../lapis/config/ReferenceGenome.kt | 51 +++++++++++++------ .../controller/ControllerDescriptions.kt | 4 +- .../lapis/controller/InfoController.kt | 18 ++++++- .../SingleSegmentedSequenceController.kt | 8 +-- .../genspectrum/lapis/model/SiloQueryModel.kt | 8 +-- .../lapis/model/VariantQueryCustomListener.kt | 10 ++-- .../lapis/model/VariantQueryFacade.kt | 6 +-- .../genspectrum/lapis/openApi/OpenApiDocs.kt | 29 ++++++----- .../lapis/request/AminoAcidInsertion.kt | 14 ++--- .../lapis/request/AminoAcidMutation.kt | 14 ++--- .../lapis/request/NucleotideInsertion.kt | 14 ++--- .../lapis/request/NucleotideMutation.kt | 14 ++--- .../lapis/config/ReferenceGenomeTest.kt | 49 +++++++++++------- .../lapis/controller/InfoControllerTest.kt | 19 +++++++ .../model/SiloFilterExpressionMapperTest.kt | 6 +-- .../lapis/model/SiloQueryModelTest.kt | 18 +++---- .../lapis/model/VariantQueryFacadeTest.kt | 14 ++--- .../resources/application-test.properties | 1 + ...plication-testWithoutAccessKeys.properties | 1 + 21 files changed, 216 insertions(+), 119 deletions(-) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisApplication.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisApplication.kt index e45f3e36..5ee2529d 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisApplication.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisApplication.kt @@ -1,6 +1,6 @@ package org.genspectrum.lapis -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @@ -8,10 +8,12 @@ import org.springframework.boot.runApplication class Lapisv2Application fun main(args: Array) { - val referenceGenomeArgs = ReferenceGenome.readFromFileFromProgramArgsOrEnv(args).toSpringApplicationArgs() + val referenceGenomeSchemaArgs = ReferenceGenomeSchema.readFromFileFromProgramArgsOrEnv( + args, + ).toSpringApplicationArgs() try { - runApplication(*(args + referenceGenomeArgs)) + runApplication(*(args + referenceGenomeSchemaArgs)) } catch (e: Exception) { e.printStackTrace() throw e diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisSpringConfig.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisSpringConfig.kt index 49ad40d8..6c18683e 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisSpringConfig.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/LapisSpringConfig.kt @@ -4,10 +4,14 @@ import com.fasterxml.jackson.module.kotlin.readValue import mu.KotlinLogging import org.genspectrum.lapis.auth.DataOpennessAuthorizationFilterFactory import org.genspectrum.lapis.config.DatabaseConfig +import org.genspectrum.lapis.config.NO_REFERENCE_GENOME_FILENAME_ERROR_MESSAGE +import org.genspectrum.lapis.config.REFERENCE_GENOME_ENV_VARIABLE_NAME +import org.genspectrum.lapis.config.REFERENCE_GENOME_FILENAME_ARGS_NAME import org.genspectrum.lapis.config.REFERENCE_GENOME_GENES_APPLICATION_ARG_PREFIX import org.genspectrum.lapis.config.REFERENCE_GENOME_SEGMENTS_APPLICATION_ARG_PREFIX import org.genspectrum.lapis.config.ReferenceGenome -import org.genspectrum.lapis.config.ReferenceSequence +import org.genspectrum.lapis.config.ReferenceGenomeSchema +import org.genspectrum.lapis.config.ReferenceSequenceSchema import org.genspectrum.lapis.config.SequenceFilterFields import org.genspectrum.lapis.logging.RequestContext import org.genspectrum.lapis.logging.RequestContextLogger @@ -27,8 +31,8 @@ class LapisSpringConfig { fun openAPI( sequenceFilterFields: SequenceFilterFields, databaseConfig: DatabaseConfig, - referenceGenome: ReferenceGenome, - ) = buildOpenApiSchema(sequenceFilterFields, databaseConfig, referenceGenome) + referenceGenomeSchema: ReferenceGenomeSchema, + ) = buildOpenApiSchema(sequenceFilterFields, databaseConfig, referenceGenomeSchema) @Bean fun databaseConfig( @@ -70,11 +74,22 @@ class LapisSpringConfig { ) = dataOpennessAuthorizationFilterFactory.create() @Bean - fun referenceGenome( + fun referenceGenomeSchema( @Value("\${$REFERENCE_GENOME_SEGMENTS_APPLICATION_ARG_PREFIX}") nucleotideSegments: List, @Value("\${$REFERENCE_GENOME_GENES_APPLICATION_ARG_PREFIX}") genes: List, - ) = ReferenceGenome( - nucleotideSegments.map { ReferenceSequence(it) }, - genes.map { ReferenceSequence(it) }, + ) = ReferenceGenomeSchema( + nucleotideSegments.map { ReferenceSequenceSchema(it) }, + genes.map { ReferenceSequenceSchema(it) }, ) + + @Bean + fun referenceGenome( + @Value("\${$REFERENCE_GENOME_FILENAME_ARGS_NAME:#{null}}") referenceGenomeFilename: String?, + ): ReferenceGenome { + val filename = referenceGenomeFilename + ?: System.getenv(REFERENCE_GENOME_ENV_VARIABLE_NAME) + ?: throw IllegalArgumentException(NO_REFERENCE_GENOME_FILENAME_ERROR_MESSAGE) + + return ReferenceGenome.readFromFile(filename) + } } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/config/ReferenceGenome.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/config/ReferenceGenome.kt index c7396521..8d14ef53 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/config/ReferenceGenome.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/config/ReferenceGenome.kt @@ -9,22 +9,30 @@ import java.io.File const val REFERENCE_GENOME_SEGMENTS_APPLICATION_ARG_PREFIX = "referenceGenome.segments" const val REFERENCE_GENOME_GENES_APPLICATION_ARG_PREFIX = "referenceGenome.genes" -private const val ENV_VARIABLE_NAME = "LAPIS_REFERENCE_GENOME_FILENAME" -private const val ARGS_NAME = "referenceGenomeFilename" +const val REFERENCE_GENOME_ENV_VARIABLE_NAME = "LAPIS_REFERENCE_GENOME_FILENAME" +const val REFERENCE_GENOME_FILENAME_ARGS_NAME = "referenceGenomeFilename" + +const val NO_REFERENCE_GENOME_FILENAME_ERROR_MESSAGE = + """No reference genome filename specified. + Please specify a reference genome filename using the --$REFERENCE_GENOME_FILENAME_ARGS_NAME argument + or the $REFERENCE_GENOME_ENV_VARIABLE_NAME environment variable.""" @JsonIgnoreProperties(ignoreUnknown = true) -class ReferenceGenome(val nucleotideSequences: List, val genes: List) { - private val nucleotideSequenceNames: Map = nucleotideSequences +class ReferenceGenomeSchema( + val nucleotideSequences: List, + val genes: List, +) { + private val nucleotideSequenceNames: Map = nucleotideSequences .associateBy { it.name.lowercase() } - private val geneNames: Map = genes + private val geneNames: Map = genes .associateBy { it.name.lowercase() } - fun getNucleotideSequenceFromLowercaseName(lowercaseName: LowercaseName): ReferenceSequence { + fun getNucleotideSequenceFromLowercaseName(lowercaseName: LowercaseName): ReferenceSequenceSchema { return nucleotideSequenceNames[lowercaseName] ?: throw BadRequestException("Unknown nucleotide sequence from lower case: $lowercaseName") } - fun getGeneFromLowercaseName(lowercaseName: LowercaseName): ReferenceSequence { + fun getGeneFromLowercaseName(lowercaseName: LowercaseName): ReferenceSequenceSchema { return geneNames[lowercaseName] ?: throw BadRequestException("Unknown gene from lower case: $lowercaseName") } @@ -34,23 +42,20 @@ class ReferenceGenome(val nucleotideSequences: List, val gene } companion object { - fun readFromFileFromProgramArgsOrEnv(args: Array): ReferenceGenome { + fun readFromFileFromProgramArgsOrEnv(args: Array): ReferenceGenomeSchema { val filename = readFilenameFromProgramArgs(args) - ?: System.getenv(ENV_VARIABLE_NAME) - ?: throw IllegalArgumentException( - "No reference genome filename specified. Please specify a reference genome filename using the " + - "--$ARGS_NAME argument or the $ENV_VARIABLE_NAME environment variable.", - ) + ?: System.getenv(REFERENCE_GENOME_ENV_VARIABLE_NAME) + ?: throw IllegalArgumentException(NO_REFERENCE_GENOME_FILENAME_ERROR_MESSAGE) return readFromFile(filename) } - fun readFromFile(filename: String): ReferenceGenome { + fun readFromFile(filename: String): ReferenceGenomeSchema { return jacksonObjectMapper().readValue(File(filename)) } private fun readFilenameFromProgramArgs(args: Array): String? { - val referenceGenomeArg = args.find { it.startsWith("--$ARGS_NAME=") } + val referenceGenomeArg = args.find { it.startsWith("--$REFERENCE_GENOME_FILENAME_ARGS_NAME=") } return referenceGenomeArg?.substringAfter("=") } } @@ -66,6 +71,22 @@ class ReferenceGenome(val nucleotideSequences: List, val gene } @JsonIgnoreProperties(ignoreUnknown = true) +data class ReferenceSequenceSchema( + val name: String, +) + +data class ReferenceGenome( + val nucleotideSequences: List, + val genes: List, +) { + companion object { + fun readFromFile(filename: String): ReferenceGenome { + return jacksonObjectMapper().readValue(File(filename)) + } + } +} + data class ReferenceSequence( val name: String, + val sequence: String, ) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ControllerDescriptions.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ControllerDescriptions.kt index 08214339..5e7b947e 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ControllerDescriptions.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ControllerDescriptions.kt @@ -17,7 +17,9 @@ const val AMINO_ACID_INSERTIONS_ENDPOINT_DESCRIPTION = """Returns a list of mutations along with the counts and proportions whose proportions are greater than or equal to the specified minProportion. Only sequences matching the specified sequence filters are considered.""" -const val INFO_ENDPOINT_DESCRIPTION = "Returns information about LAPIS" +const val INFO_ENDPOINT_DESCRIPTION = "Returns information about LAPIS." +const val DATABASE_CONFIG_ENDPOINT_DESCRIPTION = "Returns the database configuration." +const val REFERENCE_GENOME_ENDPOINT_DESCRIPTION = "Returns the reference genome." const val ALIGNED_AMINO_ACID_SEQUENCE_ENDPOINT_DESCRIPTION = """Returns a string of fasta formated aligned amino acid sequences. Only sequences matching the specified sequence filters are considered.""" diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt index 1ae0cf58..4bfbb567 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt @@ -1,6 +1,8 @@ package org.genspectrum.lapis.controller import io.swagger.v3.oas.annotations.Operation +import org.genspectrum.lapis.config.DatabaseConfig +import org.genspectrum.lapis.config.ReferenceGenome import org.genspectrum.lapis.model.SiloQueryModel import org.genspectrum.lapis.request.LapisInfo import org.springframework.http.MediaType @@ -9,14 +11,28 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController const val INFO_ROUTE = "/info" +const val DATABASE_CONFIG_ROUTE = "/databaseConfig" +const val REFERENCE_GENOME_ROUTE = "/referenceGenome" @RestController @RequestMapping("/sample") -class InfoController(private val siloQueryModel: SiloQueryModel) { +class InfoController( + private val siloQueryModel: SiloQueryModel, + private val databaseConfig: DatabaseConfig, + private val referenceGenome: ReferenceGenome, +) { @GetMapping(INFO_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE]) @Operation(description = INFO_ENDPOINT_DESCRIPTION) fun getInfo(): LapisInfo { val siloInfo = siloQueryModel.getInfo() return LapisInfo(siloInfo.dataVersion) } + + @GetMapping(DATABASE_CONFIG_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE]) + @Operation(description = DATABASE_CONFIG_ENDPOINT_DESCRIPTION) + fun getDatabaseConfig(): DatabaseConfig = databaseConfig + + @GetMapping(REFERENCE_GENOME_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE]) + @Operation(description = REFERENCE_GENOME_ENDPOINT_DESCRIPTION) + fun getReferenceGenome(): ReferenceGenome = referenceGenome } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/SingleSegmentedSequenceController.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/SingleSegmentedSequenceController.kt index 94d74136..1887bb56 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/SingleSegmentedSequenceController.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/SingleSegmentedSequenceController.kt @@ -3,7 +3,7 @@ package org.genspectrum.lapis.controller import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.media.Schema import org.genspectrum.lapis.config.REFERENCE_GENOME_SEGMENTS_APPLICATION_ARG_PREFIX -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.logging.RequestContext import org.genspectrum.lapis.model.SiloQueryModel import org.genspectrum.lapis.openApi.AminoAcidInsertions @@ -41,7 +41,7 @@ const val IS_SINGLE_SEGMENT_SEQUENCE_EXPRESSION = class SingleSegmentedSequenceController( private val siloQueryModel: SiloQueryModel, private val requestContext: RequestContext, - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) { @GetMapping(ALIGNED_NUCLEOTIDE_SEQUENCES_ROUTE, produces = ["text/x-fasta"]) @LapisAlignedSingleSegmentedNucleotideSequenceResponse @@ -87,7 +87,7 @@ class SingleSegmentedSequenceController( return siloQueryModel.getGenomicSequence( request, SequenceType.ALIGNED, - referenceGenome.nucleotideSequences[0].name, + referenceGenomeSchema.nucleotideSequences[0].name, ) } @@ -103,7 +103,7 @@ class SingleSegmentedSequenceController( return siloQueryModel.getGenomicSequence( request, SequenceType.ALIGNED, - referenceGenome.nucleotideSequences[0].name, + referenceGenomeSchema.nucleotideSequences[0].name, ) } } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/SiloQueryModel.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/SiloQueryModel.kt index b3007884..02baa106 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/SiloQueryModel.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/SiloQueryModel.kt @@ -1,6 +1,6 @@ package org.genspectrum.lapis.model -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.request.MutationProportionsRequest import org.genspectrum.lapis.request.SequenceFiltersRequest import org.genspectrum.lapis.request.SequenceFiltersRequestWithFields @@ -20,7 +20,7 @@ import org.springframework.stereotype.Component class SiloQueryModel( private val siloClient: SiloClient, private val siloFilterExpressionMapper: SiloFilterExpressionMapper, - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) { fun getAggregated(sequenceFilters: SequenceFiltersRequestWithFields) = siloClient.sendQuery( @@ -51,7 +51,7 @@ class SiloQueryModel( ) return data.map { it -> val sequenceName = - if (referenceGenome.isSingleSegmented()) it.mutation else "${it.sequenceName}:${it.mutation}" + if (referenceGenomeSchema.isSingleSegmented()) it.mutation else "${it.sequenceName}:${it.mutation}" NucleotideMutationResponse( sequenceName, @@ -110,7 +110,7 @@ class SiloQueryModel( ) return data.map { it -> - val sequenceName = if (referenceGenome.isSingleSegmented()) "" else "${it.sequenceName}:" + val sequenceName = if (referenceGenomeSchema.isSingleSegmented()) "" else "${it.sequenceName}:" NucleotideInsertionResponse( "ins_${sequenceName}${it.position}:${it.insertions}", diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryCustomListener.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryCustomListener.kt index 6577b52f..6970bddf 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryCustomListener.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryCustomListener.kt @@ -16,7 +16,7 @@ import VariantQueryParser.OrContext import VariantQueryParser.PangolineageQueryContext import org.antlr.v4.runtime.RuleContext import org.antlr.v4.runtime.tree.ParseTreeListener -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.request.LAPIS_INSERTION_AMBIGUITY_SYMBOL import org.genspectrum.lapis.request.SILO_INSERTION_AMBIGUITY_SYMBOL import org.genspectrum.lapis.silo.AminoAcidInsertionContains @@ -34,7 +34,9 @@ import org.genspectrum.lapis.silo.PangoLineageEquals import org.genspectrum.lapis.silo.SiloFilterExpression import org.genspectrum.lapis.silo.StringEquals -class VariantQueryCustomListener(val referenceGenome: ReferenceGenome) : VariantQueryBaseListener(), ParseTreeListener { +class VariantQueryCustomListener(val referenceGenomeSchema: ReferenceGenomeSchema) : + VariantQueryBaseListener(), + ParseTreeListener { private val expressionStack = ArrayDeque() fun getVariantQueryExpression(): SiloFilterExpression { @@ -110,7 +112,7 @@ class VariantQueryCustomListener(val referenceGenome: ReferenceGenome) : Variant return } val position = ctx.position().text.toInt() - val gene = referenceGenome.getGeneFromLowercaseName(ctx.gene().text.lowercase()).name + val gene = referenceGenomeSchema.getGeneFromLowercaseName(ctx.gene().text.lowercase()).name val expression = when (val aaSymbol = ctx.possiblyAmbiguousAaSymbol()) { null -> HasAminoAcidMutation(gene, position) @@ -122,7 +124,7 @@ class VariantQueryCustomListener(val referenceGenome: ReferenceGenome) : Variant override fun enterAaInsertionQuery(ctx: AaInsertionQueryContext) { val value = ctx.aaInsertionSymbol().joinToString("", transform = ::mapInsertionSymbol) - val gene = referenceGenome.getGeneFromLowercaseName(ctx.gene().text.lowercase()).name + val gene = referenceGenomeSchema.getGeneFromLowercaseName(ctx.gene().text.lowercase()).name expressionStack.addLast( AminoAcidInsertionContains( diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryFacade.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryFacade.kt index 1536ee2f..3bdb1a2d 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryFacade.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/model/VariantQueryFacade.kt @@ -5,17 +5,17 @@ import VariantQueryParser import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream import org.antlr.v4.runtime.tree.ParseTreeWalker -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.silo.SiloFilterExpression import org.springframework.stereotype.Component @Component -class VariantQueryFacade(val referenceGenome: ReferenceGenome) { +class VariantQueryFacade(val referenceGenomeSchema: ReferenceGenomeSchema) { fun map(variantQuery: String): SiloFilterExpression { val lexer = VariantQueryLexer(CharStreams.fromString(variantQuery)) val tokens = CommonTokenStream(lexer) val parser = VariantQueryParser(tokens) - val listener = VariantQueryCustomListener(referenceGenome) + val listener = VariantQueryCustomListener(referenceGenomeSchema) val walker = ParseTreeWalker() walker.walk(listener, parser.start()) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt index 48bb3ea7..1bec2c69 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt @@ -7,7 +7,7 @@ import org.genspectrum.lapis.config.DatabaseConfig import org.genspectrum.lapis.config.DatabaseMetadata import org.genspectrum.lapis.config.MetadataType import org.genspectrum.lapis.config.OpennessLevel -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.config.SequenceFilterFieldName import org.genspectrum.lapis.config.SequenceFilterFieldType import org.genspectrum.lapis.config.SequenceFilterFields @@ -37,7 +37,7 @@ import org.genspectrum.lapis.response.COUNT_PROPERTY fun buildOpenApiSchema( sequenceFilterFields: SequenceFilterFields, databaseConfig: DatabaseConfig, - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, ): OpenAPI { return OpenAPI() .components( @@ -102,7 +102,7 @@ fun buildOpenApiSchema( getSequenceFilters( databaseConfig, sequenceFilterFields, - aminoAcidSequenceFieldsEnum(referenceGenome, databaseConfig), + aminoAcidSequenceFieldsEnum(referenceGenomeSchema, databaseConfig), ), ), ) @@ -112,7 +112,7 @@ fun buildOpenApiSchema( getSequenceFilters( databaseConfig, sequenceFilterFields, - nucleotideSequenceFieldsEnum(referenceGenome, databaseConfig), + nucleotideSequenceFieldsEnum(referenceGenomeSchema, databaseConfig), ), ), ) @@ -202,17 +202,17 @@ fun buildOpenApiSchema( ) .addSchemas( AMINO_ACID_SEQUENCES_ORDER_BY_FIELDS_SCHEMA, - arraySchema(aminoAcidSequenceFieldsEnum(referenceGenome, databaseConfig)), + arraySchema(aminoAcidSequenceFieldsEnum(referenceGenomeSchema, databaseConfig)), ) .addSchemas( NUCLEOTIDE_SEQUENCES_ORDER_BY_FIELDS_SCHEMA, - arraySchema(nucleotideSequenceFieldsEnum(referenceGenome, databaseConfig)), + arraySchema(nucleotideSequenceFieldsEnum(referenceGenomeSchema, databaseConfig)), ) .addSchemas( SEGMENT_SCHEMA, - fieldsEnum(additionalFields = referenceGenome.nucleotideSequences.map { it.name }), + fieldsEnum(additionalFields = referenceGenomeSchema.nucleotideSequences.map { it.name }), ) - .addSchemas(GENE_SCHEMA, fieldsEnum(additionalFields = referenceGenome.genes.map { it.name })) + .addSchemas(GENE_SCHEMA, fieldsEnum(additionalFields = referenceGenomeSchema.genes.map { it.name })) .addSchemas(LIMIT_SCHEMA, limitSchema()) .addSchemas(OFFSET_SCHEMA, offsetSchema()) .addSchemas(FORMAT_SCHEMA, formatSchema()), @@ -505,14 +505,19 @@ private fun mutationsOrderByFieldsEnum() = fieldsEnum(emptyList(), listOf("mutat private fun insertionsOrderByFieldsEnum() = fieldsEnum(emptyList(), listOf("insertion", "count")) private fun aminoAcidSequenceFieldsEnum( - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, databaseConfig: DatabaseConfig, -) = fieldsEnum(emptyList(), referenceGenome.genes.map { it.name } + databaseConfig.schema.primaryKey) +) = fieldsEnum(emptyList(), referenceGenomeSchema.genes.map { it.name } + databaseConfig.schema.primaryKey) private fun nucleotideSequenceFieldsEnum( - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, databaseConfig: DatabaseConfig, -) = fieldsEnum(emptyList(), referenceGenome.nucleotideSequences.map { it.name } + databaseConfig.schema.primaryKey) +) = fieldsEnum( + emptyList(), + referenceGenomeSchema.nucleotideSequences.map { + it.name + } + databaseConfig.schema.primaryKey, +) private fun fieldsEnum( databaseConfig: List = emptyList(), diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidInsertion.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidInsertion.kt index 9934f114..b991cbf8 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidInsertion.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidInsertion.kt @@ -3,7 +3,7 @@ package org.genspectrum.lapis.request import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.controller.BadRequestException import org.springframework.boot.jackson.JsonComponent import org.springframework.core.convert.converter.Converter @@ -13,7 +13,7 @@ data class AminoAcidInsertion(val position: Int, val gene: String, val insertion companion object { fun fromString( aminoAcidInsertion: String, - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, ): AminoAcidInsertion { val match = AMINO_ACID_INSERTION_REGEX.find(aminoAcidInsertion) ?: throw BadRequestException("Invalid nucleotide mutation: $aminoAcidInsertion") @@ -29,7 +29,7 @@ data class AminoAcidInsertion(val position: Int, val gene: String, val insertion ?: throw BadRequestException( "Invalid amino acid insertion: $aminoAcidInsertion: Did not find gene", ) - val geneName = referenceGenome.getGeneFromLowercaseName(geneLowerCase).name + val geneName = referenceGenomeSchema.getGeneFromLowercaseName(geneLowerCase).name val insertions = matchGroups["insertions"]?.value?.replace( LAPIS_INSERTION_AMBIGUITY_SYMBOL, @@ -55,17 +55,17 @@ private val AMINO_ACID_INSERTION_REGEX = @JsonComponent class AminoAcidInsertionDeserializer( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : JsonDeserializer() { override fun deserialize( p: JsonParser, ctxt: DeserializationContext, - ) = AminoAcidInsertion.fromString(p.valueAsString, referenceGenome) + ) = AminoAcidInsertion.fromString(p.valueAsString, referenceGenomeSchema) } @Component class StringToAminoAcidInsertionConverter( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : Converter { - override fun convert(source: String) = AminoAcidInsertion.fromString(source, referenceGenome) + override fun convert(source: String) = AminoAcidInsertion.fromString(source, referenceGenomeSchema) } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidMutation.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidMutation.kt index 5afde2ed..3eb06598 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidMutation.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidMutation.kt @@ -3,7 +3,7 @@ package org.genspectrum.lapis.request import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.controller.BadRequestException import org.springframework.boot.jackson.JsonComponent import org.springframework.core.convert.converter.Converter @@ -13,7 +13,7 @@ data class AminoAcidMutation(val gene: String, val position: Int, val symbol: St companion object { fun fromString( aminoAcidMutation: String, - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, ): AminoAcidMutation { val match = AMINO_ACID_MUTATION_REGEX.find(aminoAcidMutation) ?: throw BadRequestException("Invalid amino acid mutation: $aminoAcidMutation") @@ -22,7 +22,7 @@ data class AminoAcidMutation(val gene: String, val position: Int, val symbol: St val geneLowerCase = matchGroups["gene"]?.value?.lowercase() ?: throw BadRequestException("Invalid amino acid mutation: $aminoAcidMutation: Did not find gene") - val geneName = referenceGenome.getGeneFromLowercaseName(geneLowerCase).name + val geneName = referenceGenomeSchema.getGeneFromLowercaseName(geneLowerCase).name val position = matchGroups["position"]?.value?.toInt() ?: throw BadRequestException( @@ -45,17 +45,17 @@ private val AMINO_ACID_MUTATION_REGEX = @JsonComponent class AminoAcidMutationDeserializer( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : JsonDeserializer() { override fun deserialize( p: JsonParser, ctxt: DeserializationContext, - ) = AminoAcidMutation.fromString(p.valueAsString, referenceGenome) + ) = AminoAcidMutation.fromString(p.valueAsString, referenceGenomeSchema) } @Component class StringToAminoAcidMutationConverter( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : Converter { - override fun convert(source: String) = AminoAcidMutation.fromString(source, referenceGenome) + override fun convert(source: String) = AminoAcidMutation.fromString(source, referenceGenomeSchema) } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideInsertion.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideInsertion.kt index 523aee86..0fdde101 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideInsertion.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideInsertion.kt @@ -3,7 +3,7 @@ package org.genspectrum.lapis.request import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.controller.BadRequestException import org.springframework.boot.jackson.JsonComponent import org.springframework.core.convert.converter.Converter @@ -16,7 +16,7 @@ data class NucleotideInsertion(val position: Int, val insertions: String, val se companion object { fun fromString( nucleotideInsertion: String, - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, ): NucleotideInsertion { val match = NUCLEOTIDE_INSERTION_REGEX.find(nucleotideInsertion) ?: throw BadRequestException("Invalid nucleotide mutation: $nucleotideInsertion") @@ -37,7 +37,7 @@ data class NucleotideInsertion(val position: Int, val insertions: String, val se ) val segmentName = matchGroups["segment"]?.value?.lowercase() - ?.let { referenceGenome.getNucleotideSequenceFromLowercaseName(it).name } + ?.let { referenceGenomeSchema.getNucleotideSequenceFromLowercaseName(it).name } return NucleotideInsertion( position, @@ -54,17 +54,17 @@ private val NUCLEOTIDE_INSERTION_REGEX = ) @JsonComponent -class NucleotideInsertionDeserializer(private val referenceGenome: ReferenceGenome) : +class NucleotideInsertionDeserializer(private val referenceGenomeSchema: ReferenceGenomeSchema) : JsonDeserializer() { override fun deserialize( p: JsonParser, ctxt: DeserializationContext, - ) = NucleotideInsertion.fromString(p.valueAsString, referenceGenome) + ) = NucleotideInsertion.fromString(p.valueAsString, referenceGenomeSchema) } @Component class StringToNucleotideInsertionConverter( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : Converter { - override fun convert(source: String) = NucleotideInsertion.fromString(source, referenceGenome) + override fun convert(source: String) = NucleotideInsertion.fromString(source, referenceGenomeSchema) } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideMutation.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideMutation.kt index 347246cb..e028d5f2 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideMutation.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/NucleotideMutation.kt @@ -3,7 +3,7 @@ package org.genspectrum.lapis.request import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.controller.BadRequestException import org.springframework.boot.jackson.JsonComponent import org.springframework.core.convert.converter.Converter @@ -13,7 +13,7 @@ data class NucleotideMutation(val sequenceName: String?, val position: Int, val companion object { fun fromString( nucleotideMutation: String, - referenceGenome: ReferenceGenome, + referenceGenomeSchema: ReferenceGenomeSchema, ): NucleotideMutation { val match = NUCLEOTIDE_MUTATION_REGEX.find(nucleotideMutation) ?: throw BadRequestException("Invalid nucleotide mutation: $nucleotideMutation") @@ -26,7 +26,7 @@ data class NucleotideMutation(val sequenceName: String?, val position: Int, val ) val segmentName = matchGroups["sequenceName"]?.value?.lowercase() - ?.let { referenceGenome.getNucleotideSequenceFromLowercaseName(it).name } + ?.let { referenceGenomeSchema.getNucleotideSequenceFromLowercaseName(it).name } return NucleotideMutation( segmentName, @@ -45,16 +45,16 @@ private val NUCLEOTIDE_MUTATION_REGEX = @JsonComponent class NucleotideMutationDeserializer( - private val referenceGenome: ReferenceGenome, + private val referenceGenomeSchema: ReferenceGenomeSchema, ) : JsonDeserializer() { override fun deserialize( p: JsonParser, ctxt: DeserializationContext, - ) = NucleotideMutation.fromString(p.valueAsString, referenceGenome) + ) = NucleotideMutation.fromString(p.valueAsString, referenceGenomeSchema) } @Component -class StringToNucleotideMutationConverter(private val referenceGenome: ReferenceGenome) : +class StringToNucleotideMutationConverter(private val referenceGenomeSchema: ReferenceGenomeSchema) : Converter { - override fun convert(source: String) = NucleotideMutation.fromString(source, referenceGenome) + override fun convert(source: String) = NucleotideMutation.fromString(source, referenceGenomeSchema) } diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/config/ReferenceGenomeTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/config/ReferenceGenomeTest.kt index fb0c2498..49c6e253 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/config/ReferenceGenomeTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/config/ReferenceGenomeTest.kt @@ -7,51 +7,64 @@ import org.junit.jupiter.api.assertThrows private const val REFERENCE_GENOME_DEFAULT_FILENAME = "src/test/resources/config/reference-genomes.json" -class ReferenceGenomeTest { +class ReferenceGenomeSchemaTest { @Test fun `should read from file`() { - val referenceGenome = ReferenceGenome.readFromFile(REFERENCE_GENOME_DEFAULT_FILENAME) - assertThat(referenceGenome.nucleotideSequences.size, equalTo(1)) - assertThat(referenceGenome.nucleotideSequences[0].name, equalTo("main")) + val referenceGenomeSchema = ReferenceGenomeSchema.readFromFile(REFERENCE_GENOME_DEFAULT_FILENAME) + assertThat(referenceGenomeSchema.nucleotideSequences.size, equalTo(1)) + assertThat(referenceGenomeSchema.nucleotideSequences[0].name, equalTo("main")) } @Test fun `should read from file through program args`() { val args = arrayOf("--referenceGenomeFilename=$REFERENCE_GENOME_DEFAULT_FILENAME") - val referenceGenome = ReferenceGenome.readFromFileFromProgramArgsOrEnv(args) - assertThat(referenceGenome.nucleotideSequences.size, equalTo(1)) - assertThat(referenceGenome.nucleotideSequences[0].name, equalTo("main")) + val referenceGenomeSchema = ReferenceGenomeSchema.readFromFileFromProgramArgsOrEnv(args) + assertThat(referenceGenomeSchema.nucleotideSequences.size, equalTo(1)) + assertThat(referenceGenomeSchema.nucleotideSequences[0].name, equalTo("main")) } @Test fun `should throw if no reference genome filename is given in the args`() { val args = emptyArray() - assertThrows { ReferenceGenome.readFromFileFromProgramArgsOrEnv(args) } + assertThrows { ReferenceGenomeSchema.readFromFileFromProgramArgsOrEnv(args) } } @Test fun `should generate spring application arguments`() { - val referenceGenome = ReferenceGenome( - listOf(ReferenceSequence("main"), ReferenceSequence("other_segment")), - listOf(ReferenceSequence("gene1"), ReferenceSequence("gene2")), + val referenceGenomeSchema = ReferenceGenomeSchema( + listOf(ReferenceSequenceSchema("main"), ReferenceSequenceSchema("other_segment")), + listOf(ReferenceSequenceSchema("gene1"), ReferenceSequenceSchema("gene2")), ) - val springArgs = referenceGenome.toSpringApplicationArgs() + val springArgs = referenceGenomeSchema.toSpringApplicationArgs() assertThat(springArgs[0], equalTo("--$REFERENCE_GENOME_SEGMENTS_APPLICATION_ARG_PREFIX=main,other_segment")) assertThat(springArgs[1], equalTo("--$REFERENCE_GENOME_GENES_APPLICATION_ARG_PREFIX=gene1,gene2")) } @Test fun `should detect single segmented sequence`() { - val singleSegmented = ReferenceGenome( - listOf(ReferenceSequence("main")), - listOf(ReferenceSequence("gene1"), ReferenceSequence("gene2")), + val singleSegmented = ReferenceGenomeSchema( + listOf(ReferenceSequenceSchema("main")), + listOf(ReferenceSequenceSchema("gene1"), ReferenceSequenceSchema("gene2")), ) assertThat(singleSegmented.isSingleSegmented(), equalTo(true)) - val multiSegmented = ReferenceGenome( - listOf(ReferenceSequence("main"), ReferenceSequence("other_segment")), - listOf(ReferenceSequence("gene1"), ReferenceSequence("gene2")), + val multiSegmented = ReferenceGenomeSchema( + listOf(ReferenceSequenceSchema("main"), ReferenceSequenceSchema("other_segment")), + listOf(ReferenceSequenceSchema("gene1"), ReferenceSequenceSchema("gene2")), ) assertThat(multiSegmented.isSingleSegmented(), equalTo(false)) } } + +class ReferenceGenomeTest { + @Test + fun `should read from file`() { + val referenceGenome = ReferenceGenome.readFromFile(REFERENCE_GENOME_DEFAULT_FILENAME) + assertThat(referenceGenome.nucleotideSequences.size, equalTo(1)) + assertThat(referenceGenome.nucleotideSequences[0].name, equalTo("main")) + assertThat(referenceGenome.nucleotideSequences[0].sequence, equalTo("ATTA")) + assertThat(referenceGenome.genes.size, equalTo(12)) + assertThat(referenceGenome.genes[0].name, equalTo("E")) + assertThat(referenceGenome.genes[0].sequence, equalTo("MYSFVSEET*")) + } +} diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt index eb263e3a..fcf23a47 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt @@ -30,4 +30,23 @@ class InfoControllerTest( .andExpect(status().isOk) .andExpect(jsonPath("\$.dataVersion").value("1234")) } + + @Test + fun `GET databaseConfig`() { + mockMvc.perform(getSample(DATABASE_CONFIG_ROUTE)) + .andExpect(status().isOk) + .andExpect(jsonPath("\$.schema.instanceName").value("sars_cov-2_minimal_test_config")) + .andExpect(jsonPath("\$.schema.metadata[0].name").value("primaryKey")) + .andExpect(jsonPath("\$.schema.metadata[0].type").value("string")) + } + + @Test + fun `GET referenceGenome`() { + mockMvc.perform(getSample(REFERENCE_GENOME_ROUTE)) + .andExpect(status().isOk) + .andExpect(jsonPath("\$.nucleotideSequences[0].name").value("main")) + .andExpect(jsonPath("\$.nucleotideSequences[0].sequence").value("ATTA")) + .andExpect(jsonPath("\$.genes[0].name").value("E")) + .andExpect(jsonPath("\$.genes[0].sequence").value("MYSFVSEET*")) + } } diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloFilterExpressionMapperTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloFilterExpressionMapperTest.kt index 707b04c0..29a8b635 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloFilterExpressionMapperTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloFilterExpressionMapperTest.kt @@ -2,7 +2,7 @@ package org.genspectrum.lapis.model import org.genspectrum.lapis.DATE_FIELD import org.genspectrum.lapis.FIELD_WITH_UPPERCASE_LETTER -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.controller.BadRequestException import org.genspectrum.lapis.dummySequenceFilterFields import org.genspectrum.lapis.request.AminoAcidInsertion @@ -42,8 +42,8 @@ import java.time.LocalDate private const val SOME_VALUE = "some value" class SiloFilterExpressionMapperTest { - private val dummyReferenceGenome = ReferenceGenome(emptyList(), emptyList()) - private var variantQueryFacade = VariantQueryFacade(dummyReferenceGenome) + private val dummyReferenceGenomeSchema = ReferenceGenomeSchema(emptyList(), emptyList()) + private var variantQueryFacade = VariantQueryFacade(dummyReferenceGenomeSchema) private var underTest = SiloFilterExpressionMapper(dummySequenceFilterFields, variantQueryFacade) diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloQueryModelTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloQueryModelTest.kt index a96ae3d4..82621fe4 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloQueryModelTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/SiloQueryModelTest.kt @@ -4,7 +4,7 @@ import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.verify -import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.config.ReferenceGenomeSchema import org.genspectrum.lapis.request.CommonSequenceFilters import org.genspectrum.lapis.request.MutationProportionsRequest import org.genspectrum.lapis.request.SequenceFiltersRequest @@ -32,7 +32,7 @@ class SiloQueryModelTest { lateinit var siloClientMock: SiloClient @MockK - lateinit var referenceGenomeMock: ReferenceGenome + lateinit var referenceGenomeSchemaMock: ReferenceGenomeSchema @MockK lateinit var siloFilterExpressionMapperMock: SiloFilterExpressionMapper @@ -42,14 +42,14 @@ class SiloQueryModelTest { @BeforeEach fun setup() { MockKAnnotations.init(this) - underTest = SiloQueryModel(siloClientMock, siloFilterExpressionMapperMock, referenceGenomeMock) + underTest = SiloQueryModel(siloClientMock, siloFilterExpressionMapperMock, referenceGenomeSchemaMock) } @Test fun `aggregate calls the SILO client with an aggregated action`() { every { siloClientMock.sendQuery(any>>()) } returns emptyList() every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns true + every { referenceGenomeSchemaMock.isSingleSegmented() } returns true underTest.getAggregated( SequenceFiltersRequestWithFields( @@ -73,7 +73,7 @@ class SiloQueryModelTest { fun `computeNucleotideMutationProportions calls the SILO client with a mutations action`() { every { siloClientMock.sendQuery(any>>()) } returns emptyList() every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns true + every { referenceGenomeSchemaMock.isSingleSegmented() } returns true underTest.computeNucleotideMutationProportions( MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList(), 0.5), @@ -92,7 +92,7 @@ class SiloQueryModelTest { MutationData("A1234B", 1234, 0.1234, "someSequenceName"), ) every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns true + every { referenceGenomeSchemaMock.isSingleSegmented() } returns true val result = underTest.computeNucleotideMutationProportions( MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()), @@ -107,7 +107,7 @@ class SiloQueryModelTest { MutationData("A1234B", 1234, 0.1234, "someSegmentName"), ) every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns false + every { referenceGenomeSchemaMock.isSingleSegmented() } returns false val result = underTest.computeNucleotideMutationProportions( MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()), @@ -136,7 +136,7 @@ class SiloQueryModelTest { InsertionData(42, "ABCD", 1234, "someSequenceName"), ) every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns true + every { referenceGenomeSchemaMock.isSingleSegmented() } returns true val result = underTest.getNucleotideInsertions( SequenceFiltersRequest( @@ -158,7 +158,7 @@ class SiloQueryModelTest { InsertionData(42, "ABCD", 1234, "someSequenceName"), ) every { siloFilterExpressionMapperMock.map(any()) } returns True - every { referenceGenomeMock.isSingleSegmented() } returns false + every { referenceGenomeSchemaMock.isSingleSegmented() } returns false val result = underTest.getNucleotideInsertions( SequenceFiltersRequest( diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/VariantQueryFacadeTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/VariantQueryFacadeTest.kt index 3f0ac231..cc74bf9b 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/model/VariantQueryFacadeTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/model/VariantQueryFacadeTest.kt @@ -1,7 +1,7 @@ package org.genspectrum.lapis.model -import org.genspectrum.lapis.config.ReferenceGenome -import org.genspectrum.lapis.config.ReferenceSequence +import org.genspectrum.lapis.config.ReferenceGenomeSchema +import org.genspectrum.lapis.config.ReferenceSequenceSchema import org.genspectrum.lapis.silo.AminoAcidInsertionContains import org.genspectrum.lapis.silo.AminoAcidSymbolEquals import org.genspectrum.lapis.silo.And @@ -20,16 +20,16 @@ import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test class VariantQueryFacadeTest { - private val dummyReferenceGenome = ReferenceGenome( + private val dummyReferenceGenomeSchema = ReferenceGenomeSchema( listOf( - ReferenceSequence("main"), + ReferenceSequenceSchema("main"), ), listOf( - ReferenceSequence("S"), - ReferenceSequence("ORF1a"), + ReferenceSequenceSchema("S"), + ReferenceSequenceSchema("ORF1a"), ), ) - private var underTest = VariantQueryFacade(dummyReferenceGenome) + private var underTest = VariantQueryFacade(dummyReferenceGenomeSchema) @Test fun `given a complex variant query then map should return the corresponding SiloQuery`() { diff --git a/lapis2/src/test/resources/application-test.properties b/lapis2/src/test/resources/application-test.properties index 5f0cfc7c..9a81c248 100644 --- a/lapis2/src/test/resources/application-test.properties +++ b/lapis2/src/test/resources/application-test.properties @@ -3,3 +3,4 @@ lapis.databaseConfig.path=src/test/resources/config/testDatabaseConfig.yaml lapis.accessKeys.path=src/test/resources/config/testAccessKeys.yaml referenceGenome.segments=main,other_segment referenceGenome.genes=gene1,gene2 +referenceGenomeFilename=src/test/resources/config/reference-genomes.json diff --git a/lapis2/src/test/resources/application-testWithoutAccessKeys.properties b/lapis2/src/test/resources/application-testWithoutAccessKeys.properties index 5997eab7..688c9ed4 100644 --- a/lapis2/src/test/resources/application-testWithoutAccessKeys.properties +++ b/lapis2/src/test/resources/application-testWithoutAccessKeys.properties @@ -3,3 +3,4 @@ silo.url=http://url.to.silo lapis.databaseConfig.path=src/test/resources/config/testDatabaseConfig.yaml referenceGenome.segments=main,other_segment referenceGenome.genes=gene1,gene2 +referenceGenomeFilename=src/test/resources/config/reference-genomes.json