From 855a4928e27a02cb0dd9f8ce2e0f6b9b8e5319ed Mon Sep 17 00:00:00 2001 From: "Jonas Kellerer (TNG)" Date: Tue, 5 Mar 2024 13:00:40 +0100 Subject: [PATCH] fix: nucleotide symbol equals with dot From https://github.com/GenSpectrum/cov-spectrum-website/issues/938 --- src/silo/common/nucleotide_symbols.cpp | 1 + src/silo/common/nucleotide_symbols.test.cpp | 2 +- .../test/amino_acid_symbol_equals.test.cpp | 2 +- .../test/nucleotide_symbol_equals.test.cpp | 72 +++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/silo/test/nucleotide_symbol_equals.test.cpp diff --git a/src/silo/common/nucleotide_symbols.cpp b/src/silo/common/nucleotide_symbols.cpp index d31a17312..92758889d 100644 --- a/src/silo/common/nucleotide_symbols.cpp +++ b/src/silo/common/nucleotide_symbols.cpp @@ -46,6 +46,7 @@ char Nucleotide::symbolToChar(Nucleotide::Symbol symbol) { std::optional Nucleotide::charToSymbol(char character) { switch (character) { case '.': + return std::nullopt; case '-': return Symbol::GAP; case 'A': diff --git a/src/silo/common/nucleotide_symbols.test.cpp b/src/silo/common/nucleotide_symbols.test.cpp index bc11e0512..7983d7856 100644 --- a/src/silo/common/nucleotide_symbols.test.cpp +++ b/src/silo/common/nucleotide_symbols.test.cpp @@ -7,7 +7,7 @@ TEST(NucleotideSymbol, enumShouldHaveSameLengthAsArrayOfSymbols) { } TEST(NucleotideSymbol, conversionFromCharacter) { - EXPECT_EQ(silo::Nucleotide::charToSymbol('.'), silo::Nucleotide::Symbol::GAP); + EXPECT_EQ(silo::Nucleotide::charToSymbol('.'), std::nullopt); EXPECT_EQ(silo::Nucleotide::charToSymbol('-'), silo::Nucleotide::Symbol::GAP); EXPECT_EQ(silo::Nucleotide::charToSymbol('A'), silo::Nucleotide::Symbol::A); EXPECT_EQ(silo::Nucleotide::charToSymbol('N'), silo::Nucleotide::Symbol::N); diff --git a/src/silo/test/amino_acid_symbol_equals.test.cpp b/src/silo/test/amino_acid_symbol_equals.test.cpp index 8b0040ec4..9c4f9157e 100644 --- a/src/silo/test/amino_acid_symbol_equals.test.cpp +++ b/src/silo/test/amino_acid_symbol_equals.test.cpp @@ -23,7 +23,7 @@ const nlohmann::json DATA_WITH_M = createDataWithAminoAcidSequence("M*"); const nlohmann::json DATA_WITH_B = createDataWithAminoAcidSequence("B*"); const auto DATABASE_CONFIG = - DatabaseConfig{"segmenet1", {"dummy name", {{"primaryKey", ValueType::STRING}}, "primaryKey"}}; + DatabaseConfig{"segment1", {"dummy name", {{"primaryKey", ValueType::STRING}}, "primaryKey"}}; const auto REFERENCE_GENOMES = ReferenceGenomes{ {{"segment1", "A"}}, diff --git a/src/silo/test/nucleotide_symbol_equals.test.cpp b/src/silo/test/nucleotide_symbol_equals.test.cpp new file mode 100644 index 000000000..204b87517 --- /dev/null +++ b/src/silo/test/nucleotide_symbol_equals.test.cpp @@ -0,0 +1,72 @@ +#include + +#include "silo/test/query_fixture.test.h" + +using silo::ReferenceGenomes; +using silo::config::DatabaseConfig; +using silo::config::ValueType; +using silo::test::QueryTestData; +using silo::test::QueryTestScenario; + +#include +#include + +using boost::uuids::random_generator; + +nlohmann::json createDataWithNucleotideSequence(const std::string& nucleotideSequence) { + random_generator generator; + const auto request_id = generator(); + + return { + {"metadata", {{"primaryKey", "id_" + to_string(request_id)}}}, + {"alignedNucleotideSequences", {{"segment1", nucleotideSequence}}}, + {"unalignedNucleotideSequences", {{"segment1", nullptr}}}, + {"alignedAminoAcidSequences", {{"gene1", nullptr}}} + }; +} +const nlohmann::json DATA_SAME_AS_REFERENCE = createDataWithNucleotideSequence("ATGCN"); +const nlohmann::json DATA_WITH_ALL_N = createDataWithNucleotideSequence("NNNNN"); +const nlohmann::json DATA_WITH_ALL_MUTATED = createDataWithNucleotideSequence("CATTT"); + +const auto DATABASE_CONFIG = + DatabaseConfig{"segment1", {"dummy name", {{"primaryKey", ValueType::STRING}}, "primaryKey"}}; + +const auto REFERENCE_GENOMES = ReferenceGenomes{ + {{"segment1", "ATGCN"}}, + {{"gene1", "M*"}}, +}; + +const QueryTestData TEST_DATA{ + {DATA_SAME_AS_REFERENCE, DATA_SAME_AS_REFERENCE, DATA_WITH_ALL_N, DATA_WITH_ALL_MUTATED}, + DATABASE_CONFIG, + REFERENCE_GENOMES +}; + +nlohmann::json createNucleotideSymbolEqualsQuery(const std::string& symbol, int position) { + return { + {"action", {{"type", "Aggregated"}}}, + {"filterExpression", + {{"type", "NucleotideEquals"}, + {"position", position}, + {"symbol", symbol}, + {"sequenceName", "segment1"}}} + }; +} + +const QueryTestScenario NUCLEOTIDE_EQUALS_WITH_SYMBOL = { + "nucleotideEqualsWithSymbol", + createNucleotideSymbolEqualsQuery("C", 1), + {{{"count", 1}}} +}; + +const QueryTestScenario NUCLEOTIDE_EQUALS_WITH_DOT = { + "nucleotideEqualsWithDot", + createNucleotideSymbolEqualsQuery(".", 1), + {{{"count", 2}}} +}; + +QUERY_TEST( + NucleotideSymbolEquals, + TEST_DATA, + ::testing::Values(NUCLEOTIDE_EQUALS_WITH_SYMBOL, NUCLEOTIDE_EQUALS_WITH_DOT) +);