Skip to content

Commit

Permalink
feat: add alignedNucleotideSequence, aminoAcidSequence endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Sep 25, 2023
1 parent 67a9aa9 commit 575070a
Show file tree
Hide file tree
Showing 38 changed files with 1,533 additions and 248 deletions.
20 changes: 10 additions & 10 deletions .idea/runConfigurations/LapisV2Open.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions .idea/runConfigurations/LapisV2Protected.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lapis2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ openApi {
apiDocsUrl.set("http://localhost:8080/api-docs")
customBootRun {
args.set([
"--silo.url=does.not.matter.here",
"--lapis.databaseConfig.path=../siloLapisTests/testData/testDatabaseConfig.yaml"
"--silo.url=does.not.matter.here",
"--lapis.databaseConfig.path=../siloLapisTests/testData/testDatabaseConfig.yaml",
"--referenceGenomeFilename=../siloLapisTests/testData/reference-genomes.json"
])
}
}
6 changes: 5 additions & 1 deletion lapis2/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ services:
image: ghcr.io/genspectrum/lapis-v2:${LAPIS_TAG}
ports:
- "8080:8080"
command: --silo.url=http://silo:8081 --lapis.databaseConfig.path=databaseConfig.yaml
command: --silo.url=http://silo:8081 --lapis.databaseConfig.path=databaseConfig.yaml --referenceGenomeFilename=reference-genomes.json
volumes:
- type: bind
source: ../siloLapisTests/testData/testDatabaseConfig.yaml
target: /workspace/databaseConfig.yaml
read_only: true
- type: bind
source: ../siloLapisTests/testData/reference-genomes.json
target: /workspace/reference-genomes.json
read_only: true

silo:
image: ghcr.io/genspectrum/lapis-silo:${SILO_TAG}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.genspectrum.lapis

import org.genspectrum.lapis.config.ReferenceGenome
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class Lapisv2Application

fun main(args: Array<String>) {
runApplication<Lapisv2Application>(*args)
val referenceGenomeArgs = ReferenceGenome.readFromFileFromProgramArgs(args).toSpringApplicationArgs()

runApplication<Lapisv2Application>(*(args + referenceGenomeArgs))
}
10 changes: 10 additions & 0 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/LapisSpringConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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.NucleotideSequence
import org.genspectrum.lapis.config.REFERENCE_GENOME_APPLICATION_ARG_PREFIX
import org.genspectrum.lapis.config.ReferenceGenome
import org.genspectrum.lapis.config.SequenceFilterFields
import org.genspectrum.lapis.logging.RequestContext
import org.genspectrum.lapis.logging.RequestContextLogger
Expand Down Expand Up @@ -60,4 +63,11 @@ class LapisSpringConfig {
fun dataOpennessAuthorizationFilter(
dataOpennessAuthorizationFilterFactory: DataOpennessAuthorizationFilterFactory,
) = dataOpennessAuthorizationFilterFactory.create()

@Bean
fun referenceGenome(
@Value("\${$REFERENCE_GENOME_APPLICATION_ARG_PREFIX}") nucleotideSegments: List<String>,
): ReferenceGenome {
return ReferenceGenome(nucleotideSegments.map { NucleotideSequence(it) })
}
}
18 changes: 13 additions & 5 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/OpenApiDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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.controller.SEQUENCE_REQUEST_SCHEMA
import org.genspectrum.lapis.request.AminoAcidInsertion
import org.genspectrum.lapis.request.AminoAcidMutation
import org.genspectrum.lapis.request.NucleotideInsertion
Expand All @@ -64,8 +65,9 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
Pair(AMINO_ACID_INSERTIONS_PROPERTY, aminoAcidInsertions()) +
Pair(ORDER_BY_PROPERTY, orderByPostSchema()) +
Pair(LIMIT_PROPERTY, limitSchema()) +
Pair(OFFSET_PROPERTY, offsetSchema()) +
Pair(FORMAT_PROPERTY, formatSchema())
Pair(OFFSET_PROPERTY, offsetSchema())

val sequenceFiltersWithFormat = sequenceFilters + Pair(FORMAT_PROPERTY, formatSchema())

return OpenAPI()
.components(
Expand All @@ -82,18 +84,24 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
Schema<String>()
.type("object")
.description("valid filters for sequence data")
.properties(sequenceFilters + Pair(MIN_PROPORTION_PROPERTY, Schema<String>().type("number"))),
.properties(
sequenceFiltersWithFormat + Pair(MIN_PROPORTION_PROPERTY, Schema<String>().type("number")),
),
)
.addSchemas(
AGGREGATED_REQUEST_SCHEMA,
requestSchemaWithFields(sequenceFilters, AGGREGATED_GROUP_BY_FIELDS_DESCRIPTION),
requestSchemaWithFields(sequenceFiltersWithFormat, AGGREGATED_GROUP_BY_FIELDS_DESCRIPTION),
)
.addSchemas(
DETAILS_REQUEST_SCHEMA,
requestSchemaWithFields(sequenceFilters, DETAILS_FIELDS_DESCRIPTION),
requestSchemaWithFields(sequenceFiltersWithFormat, DETAILS_FIELDS_DESCRIPTION),
)
.addSchemas(
INSERTIONS_REQUEST_SCHEMA,
requestSchemaForCommonSequenceFilters(sequenceFiltersWithFormat),
)
.addSchemas(
SEQUENCE_REQUEST_SCHEMA,
requestSchemaForCommonSequenceFilters(sequenceFilters),
)
.addSchemas(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import org.genspectrum.lapis.config.AccessKeysReader
import org.genspectrum.lapis.config.DatabaseConfig
import org.genspectrum.lapis.config.OpennessLevel
import org.genspectrum.lapis.controller.ACCESS_KEY_PROPERTY
import org.genspectrum.lapis.controller.AGGREGATED_ROUTE
import org.genspectrum.lapis.controller.AMINO_ACID_INSERTIONS_ROUTE
import org.genspectrum.lapis.controller.AMINO_ACID_MUTATIONS_ROUTE
import org.genspectrum.lapis.controller.LapisError
import org.genspectrum.lapis.controller.LapisErrorResponse
import org.genspectrum.lapis.controller.NUCLEOTIDE_INSERTIONS_ROUTE
import org.genspectrum.lapis.controller.NUCLEOTIDE_MUTATIONS_ROUTE
import org.genspectrum.lapis.util.CachedBodyHttpServletRequest
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
Expand Down Expand Up @@ -93,7 +98,13 @@ private class ProtectedDataAuthorizationFilter(

companion object {
private val WHITELISTED_PATHS = listOf("/swagger-ui", "/api-docs")
private val ENDPOINTS_THAT_SERVE_AGGREGATED_DATA = listOf("/aggregated", "/nucleotideMutations")
private val ENDPOINTS_THAT_SERVE_AGGREGATED_DATA = listOf(
AGGREGATED_ROUTE,
NUCLEOTIDE_MUTATIONS_ROUTE,
AMINO_ACID_MUTATIONS_ROUTE,
NUCLEOTIDE_INSERTIONS_ROUTE,
AMINO_ACID_INSERTIONS_ROUTE,
)
}

override fun isAuthorizedForEndpoint(request: CachedBodyHttpServletRequest): AuthorizationResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.genspectrum.lapis.config

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File

const val REFERENCE_GENOME_APPLICATION_ARG_PREFIX = "referenceGenome.nucleotideSequences"

@JsonIgnoreProperties(ignoreUnknown = true)
class ReferenceGenome(
@JsonProperty("nucleotide_sequences")
val nucleotideSequences: List<NucleotideSequence>,
) {
fun isSingleSegmented(): Boolean {
return nucleotideSequences.size == 1
}

companion object {
fun readFromFile(filename: String): ReferenceGenome {
return jacksonObjectMapper().readValue(File(filename))
}

private fun readFilenameFromProgramArgs(args: Array<String>): String {
val referenceGenomeArg = args.find { it.startsWith("--referenceGenomeFilename=") }
return referenceGenomeArg?.substringAfter("=") ?: throw IllegalArgumentException(
"No reference genome filename specified. Please specify a reference genome filename using the " +
"--referenceGenomeFilename argument.",
)
}

fun readFromFileFromProgramArgs(args: Array<String>): ReferenceGenome {
return readFromFile(readFilenameFromProgramArgs(args))
}
}

fun toSpringApplicationArgs(): Array<String> {
val nucleotideSequenceArgs =
"--$REFERENCE_GENOME_APPLICATION_ARG_PREFIX=" + this.nucleotideSequences.joinToString(
separator = ",",
) {
it.name
}

return arrayOf(nucleotideSequenceArgs)
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class NucleotideSequence(
val name: String,
)

This file was deleted.

Loading

0 comments on commit 575070a

Please sign in to comment.