-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter by insertions at all endpoints
- Loading branch information
1 parent
18a4a38
commit 3376cb7
Showing
21 changed files
with
761 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
lapis2/src/main/kotlin/org/genspectrum/lapis/request/AminoAcidInsertion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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.springframework.boot.jackson.JsonComponent | ||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.stereotype.Component | ||
|
||
data class AminoAcidInsertion(val position: Int, val gene: String, val insertions: String) { | ||
companion object { | ||
fun fromString(aminoAcidInsertion: String): AminoAcidInsertion { | ||
val match = AMINO_ACID_INSERTION_REGEX.find(aminoAcidInsertion) | ||
?: throw IllegalArgumentException("Invalid nucleotide mutation: $aminoAcidInsertion") | ||
|
||
val matchGroups = match.groups | ||
|
||
val position = matchGroups["position"]?.value?.toInt() | ||
?: throw IllegalArgumentException( | ||
"Invalid amino acid insertion: $aminoAcidInsertion: Did not find position", | ||
) | ||
|
||
val gene = matchGroups["gene"]?.value | ||
?: throw IllegalArgumentException( | ||
"Invalid amino acid insertion: $aminoAcidInsertion: Did not find gene", | ||
) | ||
|
||
val insertions = matchGroups["insertion"]?.value?.replace("?", ".*") | ||
?: throw IllegalArgumentException( | ||
"Invalid amino acid insertion: $aminoAcidInsertion: Did not find insertions", | ||
) | ||
|
||
return AminoAcidInsertion( | ||
position, | ||
gene, | ||
insertions, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private val AMINO_ACID_INSERTION_REGEX = | ||
Regex( | ||
"""^ins_(?<gene>[a-zA-Z0-9_-]+):(?<position>\d+):(?<insertion>[a-zA-Z0-9?_-]+)?$""", | ||
) | ||
|
||
@JsonComponent | ||
class AminoAcidInsertionDeserializer : JsonDeserializer<AminoAcidInsertion>() { | ||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext) = | ||
AminoAcidInsertion.fromString(p.valueAsString) | ||
} | ||
|
||
@Component | ||
class StringToAminoAcidInsertionConverter : Converter<String, AminoAcidInsertion> { | ||
override fun convert(source: String) = AminoAcidInsertion.fromString(source) | ||
} |
Oops, something went wrong.