Skip to content

Commit

Permalink
chore(deps): code style official renamed to intellij_idea; run ktlint…
Browse files Browse the repository at this point in the history
…Format
  • Loading branch information
TobiasKampmann committed Dec 6, 2023
1 parent 54a13ee commit e680f46
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 330 deletions.
2 changes: 1 addition & 1 deletion backend/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ insert_final_newline = true
end_of_line = crlf

[*.{kt,kts}]
ktlint_code_style = official
ktlint_code_style = intellij_idea
trailing-comma-on-call-site = true
trailing-comma-on-declaration-site = true
ij_kotlin_allow_trailing_comma_on_call_site = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import org.pathoplexus.backend.api.Organism
data class BackendConfig(
val instances: Map<String, InstanceConfig>,
) {
fun getInstanceConfig(organism: Organism) =
instances[organism.name] ?: throw IllegalArgumentException(
"Organism: ${organism.name} not found in backend config. Available organisms: ${instances.keys}",
)
fun getInstanceConfig(organism: Organism) = instances[organism.name] ?: throw IllegalArgumentException(
"Organism: ${organism.name} not found in backend config. Available organisms: ${instances.keys}",
)
}

data class InstanceConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ class SubmitModel(
}
}

private fun uploadSequences(
uploadId: String,
sequenceStream: InputStream,
batchSize: Int,
organism: Organism,
) {
private fun uploadSequences(uploadId: String, sequenceStream: InputStream, batchSize: Int, organism: Organism) {
log.info {
"intermediate storing uploaded sequence data with UploadId $uploadId"
}
Expand Down Expand Up @@ -238,10 +233,7 @@ class SubmitModel(
}

// TODO(#604): adapt revisions to the new flow
private fun processRevisedData(
metadataFile: MultipartFile,
sequenceFile: MultipartFile,
): List<RevisedData> {
private fun processRevisedData(metadataFile: MultipartFile, sequenceFile: MultipartFile): List<RevisedData> {
if (metadataFile.originalFilename == null || !metadataFile.originalFilename?.endsWith(".tsv")!!) {
throw BadRequestException("Metadata file must have extension .tsv")
}
Expand All @@ -263,10 +255,7 @@ class SubmitModel(
}
}

private fun validateHeaders(
metadataMap: Map<SubmissionId, Any>,
sequenceMap: Map<SubmissionId, Any>,
) {
private fun validateHeaders(metadataMap: Map<SubmissionId, Any>, sequenceMap: Map<SubmissionId, Any>) {
val metadataKeysSet = metadataMap.keys.toSet()
val sequenceKeysSet = sequenceMap.keys.toSet()
validateSubmissionIdSets(metadataKeysSet, sequenceKeysSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ class CompressionService(private val backendConfig: BackendConfig) {
uncompressedSequence: String,
segmentName: String,
organism: Organism,
): String =
compress(
uncompressedSequence,
getDictionaryForNucleotideSequenceSegments(segmentName, organism),
)
): String = compress(
uncompressedSequence,
getDictionaryForNucleotideSequenceSegments(segmentName, organism),
)

private fun decompressUnalignedNucleotideSequence(
compressedSequence: String,
Expand All @@ -40,31 +39,29 @@ class CompressionService(private val backendConfig: BackendConfig) {
getDictionaryForNucleotideSequenceSegments(segmentName, organism),
)

fun decompressSequencesInOriginalData(originalData: OriginalData, organism: Organism) =
OriginalData(
originalData.metadata,
originalData
.unalignedNucleotideSequences.mapValues {
decompressUnalignedNucleotideSequence(
it.value,
it.key,
organism,
)
},
)
fun decompressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = OriginalData(
originalData.metadata,
originalData
.unalignedNucleotideSequences.mapValues {
decompressUnalignedNucleotideSequence(
it.value,
it.key,
organism,
)
},
)

fun compressSequencesInOriginalData(originalData: OriginalData, organism: Organism) =
OriginalData(
originalData.metadata,
originalData
.unalignedNucleotideSequences.mapValues { (segmentName, sequenceData) ->
compressUnalignedNucleotideSequence(
sequenceData,
segmentName,
organism,
)
},
)
fun compressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = OriginalData(
originalData.metadata,
originalData
.unalignedNucleotideSequences.mapValues { (segmentName, sequenceData) ->
compressUnalignedNucleotideSequence(
sequenceData,
segmentName,
organism,
)
},
)

private fun compress(seq: String, dictionary: ByteArray?): String {
val input = seq.toByteArray(StandardCharsets.UTF_8)
Expand Down Expand Up @@ -99,13 +96,11 @@ class CompressionService(private val backendConfig: BackendConfig) {
return String(decompressedBuffer, 0, decompressionReturnCode.toInt(), StandardCharsets.UTF_8)
}

private fun getDictionaryForNucleotideSequenceSegments(
segmentName: String,
organism: Organism,
): ByteArray? = backendConfig
.getInstanceConfig(organism)
.referenceGenomes
.getNucleotideSegmentReference(
segmentName,
)?.toByteArray()
private fun getDictionaryForNucleotideSequenceSegments(segmentName: String, organism: Organism): ByteArray? =
backendConfig
.getInstanceConfig(organism)
.referenceGenomes
.getNucleotideSegmentReference(
segmentName,
)?.toByteArray()
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ class DatabaseService(
}
}

private fun addMissingKeysForInsertions(
submittedProcessedData: SubmittedProcessedData,
): SubmittedProcessedData {
private fun addMissingKeysForInsertions(submittedProcessedData: SubmittedProcessedData): SubmittedProcessedData {
val nucleotideInsertions = referenceGenome.nucleotideSequences.associate {
if (it.name in submittedProcessedData.data.nucleotideInsertions.keys) {
it.name to submittedProcessedData.data.nucleotideInsertions[it.name]!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ class SequenceValidator(
validateAminoAcidSequences(submittedProcessedData)
}

private fun validateMetadata(
submittedProcessedData: SubmittedProcessedData,
) {
private fun validateMetadata(submittedProcessedData: SubmittedProcessedData) {
val metadataFields = schema.metadata
validateNoUnknownInMetaData(submittedProcessedData.data.metadata, metadataFields.map { it.name })

Expand All @@ -100,21 +98,15 @@ class SequenceValidator(
}
}

private fun <T> validateNoUnknownInMetaData(
data: Map<String, T>,
known: List<String>,
) {
private fun <T> validateNoUnknownInMetaData(data: Map<String, T>, known: List<String>) {
val unknownMetadataKeys = data.keys.subtract(known.toSet())
if (unknownMetadataKeys.isNotEmpty()) {
val unknownMetadataKeysString = unknownMetadataKeys.sorted().joinToString(", ")
throw ProcessingValidationException("Unknown fields in processed data: $unknownMetadataKeysString.")
}
}

private fun validateKnownMetadataField(
metadata: Metadata,
submittedProcessedData: SubmittedProcessedData,
) {
private fun validateKnownMetadataField(metadata: Metadata, submittedProcessedData: SubmittedProcessedData) {
val fieldName = metadata.name
val fieldValue = submittedProcessedData.data.metadata[fieldName]

Expand Down Expand Up @@ -192,9 +184,7 @@ class SequenceValidator(
return pangoLineageCandidate.matches(pangoLineageRegex)
}

private fun validateNucleotideSequences(
submittedProcessedData: SubmittedProcessedData,
) {
private fun validateNucleotideSequences(submittedProcessedData: SubmittedProcessedData) {
for (segment in referenceGenome.nucleotideSequences) {
validateNoMissingSegment(
segment,
Expand Down Expand Up @@ -268,10 +258,7 @@ class SequenceValidator(
}
}

private fun <T> validateNoUnknownSegment(
dataToValidate: Map<String, T>,
sequenceGrouping: String,
) {
private fun <T> validateNoUnknownSegment(dataToValidate: Map<String, T>, sequenceGrouping: String) {
val unknownSegments = dataToValidate.keys.subtract(referenceGenome.nucleotideSequences.map { it.name }.toSet())
if (unknownSegments.isNotEmpty()) {
val unknownSegmentsString = unknownSegments.sorted().joinToString(", ")
Expand All @@ -281,10 +268,7 @@ class SequenceValidator(
}
}

private fun validateNoUnknownNucleotideSymbol(
dataToValidate: Map<String, String>,
sequenceGrouping: String,
) {
private fun validateNoUnknownNucleotideSymbol(dataToValidate: Map<String, String>, sequenceGrouping: String) {
for (sequence in dataToValidate) {
val invalidSymbols = sequence.value.getInvalidSymbols<NucleotideSymbols>()
if (invalidSymbols.isNotEmpty()) {
Expand All @@ -296,9 +280,7 @@ class SequenceValidator(
}
}

private fun validateNoUnknownNucleotideSymbolInInsertion(
dataToValidate: Map<String, List<Insertion>>,
) {
private fun validateNoUnknownNucleotideSymbolInInsertion(dataToValidate: Map<String, List<Insertion>>) {
for (sequence in dataToValidate) {
for (insertion in sequence.value) {
val invalidSymbols = insertion.sequence.getInvalidSymbols<NucleotideSymbols>()
Expand All @@ -320,9 +302,7 @@ class SequenceValidator(
where ValidSymbols : Enum<ValidSymbols>, ValidSymbols : Symbol =
enumValues<ValidSymbols>().any { it.symbol == this }

private fun validateAminoAcidSequences(
submittedProcessedData: SubmittedProcessedData,
) {
private fun validateAminoAcidSequences(submittedProcessedData: SubmittedProcessedData) {
for (gene in referenceGenome.genes) {
validateNoMissingGene(gene, submittedProcessedData)
validateLengthOfSequence(
Expand All @@ -346,29 +326,21 @@ class SequenceValidator(
validateNoUnknownAminoAcidSymbolInInsertion(submittedProcessedData.data.aminoAcidInsertions)
}

private fun validateNoMissingGene(
gene: ReferenceSequence,
submittedProcessedData: SubmittedProcessedData,
) {
private fun validateNoMissingGene(gene: ReferenceSequence, submittedProcessedData: SubmittedProcessedData) {
if (!submittedProcessedData.data.alignedAminoAcidSequences.containsKey(gene.name)) {
throw ProcessingValidationException("Missing the required gene '${gene.name}'.")
}
}

private fun validateNoUnknownGeneInData(
data: Map<String, *>,
geneGrouping: String,
) {
private fun validateNoUnknownGeneInData(data: Map<String, *>, geneGrouping: String) {
val unknownGenes = data.keys.subtract(referenceGenome.genes.map { it.name }.toSet())
if (unknownGenes.isNotEmpty()) {
val unknownGenesString = unknownGenes.sorted().joinToString(", ")
throw ProcessingValidationException("Unknown genes in '$geneGrouping': $unknownGenesString.")
}
}

private fun validateNoUnknownAminoAcidSymbol(
dataToValidate: Map<String, String>,
) {
private fun validateNoUnknownAminoAcidSymbol(dataToValidate: Map<String, String>) {
for (sequence in dataToValidate) {
val invalidSymbols = sequence.value.getInvalidSymbols<AminoAcidSymbols>()
if (invalidSymbols.isNotEmpty()) {
Expand All @@ -380,9 +352,7 @@ class SequenceValidator(
}
}

private fun validateNoUnknownAminoAcidSymbolInInsertion(
dataToValidate: Map<String, List<Insertion>>,
) {
private fun validateNoUnknownAminoAcidSymbolInInsertion(dataToValidate: Map<String, List<Insertion>>) {
for (sequence in dataToValidate) {
for (insertion in sequence.value) {
val invalidSymbols = insertion.sequence.getInvalidSymbols<AminoAcidSymbols>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ class IteratorStreamer(private val objectMapper: ObjectMapper) {
fun <T> streamAsNdjson(iterable: Iterable<T>, outputStream: OutputStream) =
streamAsNdjson(iterable.iterator(), outputStream)

fun <T> streamAsNdjson(
iterator: Iterator<T>,
outputStream: OutputStream,
) {
fun <T> streamAsNdjson(iterator: Iterator<T>, outputStream: OutputStream) {
iterator.forEach {
val json = objectMapper.writeValueAsString(it)
outputStream.write(json.toByteArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

private const val numberOfFieldsWithUnknownValue = 2
private const val NUMBER_OF_FIELDS_WITH_UNKNOWN_VALUE = 2

@EndpointTest
class GetReleasedDataEndpointTest(
Expand Down Expand Up @@ -77,7 +77,7 @@ class GetReleasedDataEndpointTest(
"versionStatus" to TextNode("LATEST_VERSION"),
)

assertThat(it.metadata.size, `is`(expectedMetadata.size + numberOfFieldsWithUnknownValue))
assertThat(it.metadata.size, `is`(expectedMetadata.size + NUMBER_OF_FIELDS_WITH_UNKNOWN_VALUE))
for ((key, value) in it.metadata) {
when (key) {
"submittedAt" -> {
Expand Down
Loading

0 comments on commit e680f46

Please sign in to comment.