Skip to content

Commit

Permalink
feat: add nucleotideInsertions endpoint returning json,csv and tsv
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Sep 15, 2023
1 parent 4abe1ce commit 829b8e9
Show file tree
Hide file tree
Showing 12 changed files with 985 additions and 482 deletions.
36 changes: 34 additions & 2 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/OpenApiDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ 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_REQUEST_SCHEMA
import org.genspectrum.lapis.controller.NUCLEOTIDE_INSERTIONS_SCHEMA
import org.genspectrum.lapis.controller.NUCLEOTIDE_INSERTIONS_RESPONSE_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 Down Expand Up @@ -89,6 +91,10 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
DETAILS_REQUEST_SCHEMA,
requestSchemaWithFields(sequenceFilters, DETAILS_FIELDS_DESCRIPTION),
)
.addSchemas(
NUCLEOTIDE_INSERTIONS_REQUEST_SCHEMA,
requestSchemaForCommonSequencenFilters(sequenceFilters),
)
.addSchemas(
AGGREGATED_RESPONSE_SCHEMA,
lapisResponseSchema(
Expand Down Expand Up @@ -137,6 +143,15 @@ fun buildOpenApiSchema(sequenceFilterFields: SequenceFilterFields, databaseConfi
.properties(aminoAcidMutationProportionSchema()),
),
)
.addSchemas(
NUCLEOTIDE_INSERTIONS_RESPONSE_SCHEMA,
lapisResponseSchema(
Schema<String>()
.type("object")
.description("Nucleotide Insertion data.")
.properties(nucleotideInsertionSchema()),
),
)
.addSchemas(AMINO_ACID_MUTATIONS_SCHEMA, aminoAcidMutations())
.addSchemas(NUCLEOTIDE_INSERTIONS_SCHEMA, nucleotideInsertions())
.addSchemas(AMINO_ACID_INSERTIONS_SCHEMA, aminoAcidInsertions())
Expand Down Expand Up @@ -179,6 +194,14 @@ private fun primitiveSequenceFilterFieldSchemas(sequenceFilterFields: SequenceFi
.map { (fieldName, fieldType) -> fieldName to Schema<String>().type(fieldType.openApiType) }
.toMap()

private fun requestSchemaForCommonSequencenFilters(
requestProperties: Map<SequenceFilterFieldName, Schema<out Any>>,
): Schema<*> =
Schema<String>()
.type("object")
.description("valid filters for sequence data")
.properties(requestProperties)

private fun requestSchemaWithFields(
requestProperties: Map<SequenceFilterFieldName, Schema<out Any>>,
fieldsDescription: String,
Expand Down Expand Up @@ -208,20 +231,29 @@ private fun accessKeySchema() = Schema<String>()

private fun nucleotideMutationProportionSchema() =
mapOf(
"mutation" to Schema<String>().type("string").description("The mutation that was found."),
"mutation" to Schema<String>().type("string").example("T123C").description("The mutation that was found."),
"proportion" to Schema<String>().type("number").description("The proportion of sequences having the mutation."),
"count" to Schema<String>().type("number").description("The number of sequences matching having the mutation."),
)

private fun aminoAcidMutationProportionSchema() =
mapOf(
"mutation" to Schema<String>().type("string").description(
"mutation" to Schema<String>().type("string").example("ORF1a:123").description(
"A amino acid mutation that was found in the format \"\\<gene\\>:\\<position\\>",
),
"proportion" to Schema<String>().type("number").description("The proportion of sequences having the mutation."),
"count" to Schema<String>().type("number").description("The number of sequences matching having the mutation."),
)

private fun nucleotideInsertionSchema() =
mapOf(
"insertion" to Schema<String>().type("string")
.example("ins_segment:123:AAT")
.description("The insertion that was found."),
"count" to Schema<String>().type("number")
.description("The number of sequences matching having the insertion."),
)

private fun nucleotideMutations() =
Schema<List<NucleotideMutation>>()
.type("array")
Expand Down
Loading

0 comments on commit 829b8e9

Please sign in to comment.