Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transform lower case sequences to upper case #2577

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import org.springframework.transaction.annotation.Transactional
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.Locale
import javax.sql.DataSource

private val log = KotlinLogging.logger { }
Expand Down Expand Up @@ -318,7 +319,7 @@ class SubmissionDatabaseService(
val submittedWarnings = submittedProcessedData.warnings.orEmpty()

val (newStatus, processedData) = when {
submittedErrors.isEmpty() -> FINISHED to validateProcessedData(
submittedErrors.isEmpty() -> FINISHED to postprocessAndValidateProcessedData(
submittedProcessedData,
organism,
)
Expand Down Expand Up @@ -349,13 +350,35 @@ class SubmissionDatabaseService(
return newStatus
}

private fun validateProcessedData(submittedProcessedData: SubmittedProcessedData, organism: Organism) = try {
processedSequenceEntryValidatorFactory.create(organism).validate(submittedProcessedData.data)
} catch (validationException: ProcessingValidationException) {
private fun postprocessAndValidateProcessedData(
submittedProcessedData: SubmittedProcessedData,
organism: Organism,
) = try {
throwIfIsSubmissionForWrongOrganism(submittedProcessedData, organism)
val processedData = makeSequencesUpperCase(submittedProcessedData.data)
processedSequenceEntryValidatorFactory.create(organism).validate(processedData)
} catch (validationException: ProcessingValidationException) {
throw validationException
}

private fun makeSequencesUpperCase(processedData: ProcessedData<GeneticSequence>) = processedData.copy(
unalignedNucleotideSequences = processedData.unalignedNucleotideSequences.mapValues { (_, it) ->
it?.uppercase(Locale.US)
},
alignedNucleotideSequences = processedData.alignedNucleotideSequences.mapValues { (_, it) ->
it?.uppercase(Locale.US)
},
alignedAminoAcidSequences = processedData.alignedAminoAcidSequences.mapValues { (_, it) ->
it?.uppercase(Locale.US)
},
nucleotideInsertions = processedData.nucleotideInsertions.mapValues { (_, it) ->
it.map { insertion -> insertion.copy(sequence = insertion.sequence.uppercase(Locale.US)) }
},
aminoAcidInsertions = processedData.aminoAcidInsertions.mapValues { (_, it) ->
it.map { insertion -> insertion.copy(sequence = insertion.sequence.uppercase(Locale.US)) }
},
)

private fun validateExternalMetadata(
externalSubmittedData: ExternalSubmittedData,
organism: Organism,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ object PreparedProcessedData {
),
)

fun withLowercaseSequences(accession: Accession, version: Version) = defaultSuccessfulSubmittedData.copy(
accession = accession,
version = version,
data = defaultProcessedData.copy(
unalignedNucleotideSequences = mapOf(
MAIN_SEGMENT to "nactg",
),
alignedNucleotideSequences = mapOf(
MAIN_SEGMENT to "attaaaggtttataccttcccaggtaacaaaccaaccaactttcgatct",
),
nucleotideInsertions = mapOf(
MAIN_SEGMENT to listOf(Insertion(123, "actg")),
),
alignedAminoAcidSequences = mapOf(
SOME_LONG_GENE to "acdefghiklmnpqrstvwybzx-*",
SOME_SHORT_GENE to "mads",
),
aminoAcidInsertions = mapOf(
SOME_LONG_GENE to listOf(Insertion(123, "def")),
SOME_SHORT_GENE to listOf(Insertion(123, "n")),
),
),
)

fun withMissingMetadataFields(
accession: Accession,
version: Long = defaultSuccessfulSubmittedData.version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ class SubmitProcessedDataEndpointTest(
.assertStatusIs(Status.AWAITING_APPROVAL)
}

@Test
fun `WHEN I submit data with lowercase sequences THEN the sequences are converted to uppercase`() {
val (accession, version) = prepareExtractedSequencesInDatabase().first()

submissionControllerClient.submitProcessedData(
PreparedProcessedData.withLowercaseSequences(accession = accession, version = version),
)
.andExpect(status().isNoContent)

val processedData = convenienceClient.getSequenceEntryToEdit(accession = accession, version = version)
.processedData

assertThat(processedData.unalignedNucleotideSequences, hasEntry(MAIN_SEGMENT, "NACTG"))
assertThat(
processedData.alignedNucleotideSequences,
hasEntry(MAIN_SEGMENT, "ATTAAAGGTTTATACCTTCCCAGGTAACAAACCAACCAACTTTCGATCT"),
)
assertThat(processedData.alignedAminoAcidSequences, hasEntry(SOME_LONG_GENE, "ACDEFGHIKLMNPQRSTVWYBZX-*"))
assertThat(processedData.nucleotideInsertions, hasEntry(MAIN_SEGMENT, listOf(Insertion(123, "ACTG"))))
assertThat(processedData.aminoAcidInsertions, hasEntry(SOME_LONG_GENE, listOf(Insertion(123, "DEF"))))
}

@Test
fun `WHEN I submit with all valid symbols THEN the sequence entry is in status processed`() {
val accessions = prepareExtractedSequencesInDatabase().map { it.accession }
Expand Down Expand Up @@ -381,21 +403,21 @@ class SubmitProcessedDataEndpointTest(

@Test
fun `WHEN I submit an entry with the wrong organism THEN refuses update with unprocessable entity`() {
val accession = prepareUnprocessedSequenceEntry(DEFAULT_ORGANISM)
val accession = prepareUnprocessedSequenceEntry(OTHER_ORGANISM)

submissionControllerClient.submitProcessedData(
PreparedProcessedData.successfullyProcessed(accession = accession),
organism = OTHER_ORGANISM,
organism = DEFAULT_ORGANISM,
)
.andExpect(status().isUnprocessableEntity)
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(
jsonPath("\$.detail")
.value(containsString("$accession.1 is for organism dummyOrganism")),
.value(containsString("$accession.1 is for organism otherOrganism")),
)
.andExpect(
jsonPath("\$.detail")
.value(containsString("submitted data is for organism otherOrganism")),
.value(containsString("submitted data is for organism dummyOrganism")),
)
}

Expand Down
Loading