Skip to content

Commit

Permalink
fix: nucleotide symbol equals with dot
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Mar 5, 2024
1 parent 3ecde68 commit 855a492
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/silo/common/nucleotide_symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ char Nucleotide::symbolToChar(Nucleotide::Symbol symbol) {
std::optional<Nucleotide::Symbol> Nucleotide::charToSymbol(char character) {
switch (character) {
case '.':
return std::nullopt;
case '-':
return Symbol::GAP;
case 'A':
Expand Down
2 changes: 1 addition & 1 deletion src/silo/common/nucleotide_symbols.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/silo/test/amino_acid_symbol_equals.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
72 changes: 72 additions & 0 deletions src/silo/test/nucleotide_symbol_equals.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <nlohmann/json.hpp>

#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 <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

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)
);

0 comments on commit 855a492

Please sign in to comment.