-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow null for sequenceName in insertion contains queries
- Loading branch information
1 parent
21eeaf8
commit 6dbe251
Showing
7 changed files
with
293 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
#include "silo/database.h" | ||
|
||
namespace silo { | ||
|
||
template <typename SymbolType> | ||
std::string validateSequenceName(std::string sequence_name, const silo::Database& database) { | ||
CHECK_SILO_QUERY( | ||
database.getSequenceStores<SymbolType>().contains(sequence_name), | ||
fmt::format( | ||
"Database does not contain the {} Sequence with name: '{}'", | ||
SymbolType::SYMBOL_NAME, | ||
sequence_name | ||
) | ||
); | ||
return sequence_name; | ||
} | ||
|
||
template <typename SymbolType> | ||
std::string validateSequenceNameOrGetDefault( | ||
std::optional<std::string> sequence_name, | ||
const silo::Database& database | ||
) { | ||
if (sequence_name.has_value()) { | ||
return validateSequenceName<SymbolType>(sequence_name.value(), database); | ||
} | ||
|
||
CHECK_SILO_QUERY( | ||
database.getDefaultSequenceName<SymbolType>().has_value(), | ||
"The database has no default " + std::string(SymbolType::SYMBOL_NAME_LOWER_CASE) + | ||
" sequence name" | ||
); | ||
|
||
const auto default_sequence_name = database.getDefaultSequenceName<SymbolType>().value(); | ||
return validateSequenceName<SymbolType>(default_sequence_name, database); | ||
} | ||
|
||
} // namespace silo |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <nlohmann/json.hpp> | ||
|
||
#include <optional> | ||
|
||
#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; | ||
|
||
nlohmann::json createDataWithAminoAcidInsertions( | ||
const std::string& primaryKey, | ||
const nlohmann::json& aminoAcidInsertions | ||
) { | ||
return { | ||
{"metadata", {{"primaryKey", primaryKey}}}, | ||
{"alignedNucleotideSequences", {{"segment1", nullptr}, {"segment2", nullptr}}}, | ||
{"unalignedNucleotideSequences", {{"segment1", nullptr}, {"segment2", nullptr}}}, | ||
{"alignedAminoAcidSequences", {{"gene1", nullptr}, {"gene2", nullptr}}}, | ||
{"nucleotideInsertions", {{"segment1", {}}, {"segment2", {}}}}, | ||
{"aminoAcidInsertions", aminoAcidInsertions} | ||
}; | ||
} | ||
|
||
const std::vector<nlohmann::json> DATA = { | ||
createDataWithAminoAcidInsertions("id_0", {{"gene1", {"123:A"}}, {"gene2", {}}}), | ||
createDataWithAminoAcidInsertions("id_1", {{"gene1", {"123:A"}}, {"gene2", {}}}), | ||
createDataWithAminoAcidInsertions("id_2", {{"gene1", {"234:BB"}}, {"gene2", {}}}), | ||
createDataWithAminoAcidInsertions("id_3", {{"gene1", {"123:CCC"}}, {"gene2", {}}}), | ||
}; | ||
|
||
const auto DATABASE_CONFIG = DatabaseConfig{ | ||
.default_nucleotide_sequence = "segment1", | ||
.schema = | ||
{.instance_name = "dummy name", | ||
.metadata = {{.name = "primaryKey", .type = ValueType::STRING}}, | ||
.primary_key = "primaryKey"} | ||
}; | ||
|
||
const auto REFERENCE_GENOMES = ReferenceGenomes{ | ||
{{"segment1", "A"}, {"segment2", "T"}}, | ||
{{"gene1", "*"}, {"gene2", "*"}}, | ||
}; | ||
|
||
const QueryTestData TEST_DATA{ | ||
.ndjson_input_data = {DATA}, | ||
.database_config = DATABASE_CONFIG, | ||
.reference_genomes = REFERENCE_GENOMES | ||
}; | ||
|
||
nlohmann::json createAminoAcidInsertionContainsQuery( | ||
const nlohmann::json& sequenceName, | ||
int position, | ||
const std::string& insertedSymbols | ||
) { | ||
return { | ||
{"action", {{"type", "Details"}}}, | ||
{"filterExpression", | ||
{{"type", "AminoAcidInsertionContains"}, | ||
{"position", position}, | ||
{"value", insertedSymbols}, | ||
{"sequenceName", sequenceName}}} | ||
}; | ||
} | ||
|
||
nlohmann::json createAminoAcidInsertionContainsQueryWithEmptySequenceName( | ||
int position, | ||
const std::string& insertedSymbols | ||
) { | ||
return { | ||
{"action", {{"type", "Details"}}}, | ||
{"filterExpression", | ||
{ | ||
{"type", "AminoAcidInsertionContains"}, | ||
{"position", position}, | ||
{"value", insertedSymbols}, | ||
}} | ||
}; | ||
} | ||
|
||
const QueryTestScenario AMINO_ACID_INSERTION_CONTAINS_SCENARIO = { | ||
.name = "aminoAcidInsertionContains", | ||
.query = createAminoAcidInsertionContainsQuery("gene1", 123, "A"), | ||
.expected_query_result = nlohmann::json({{{"primaryKey", "id_0"}}, {{"primaryKey", "id_1"}}}) | ||
}; | ||
|
||
const QueryTestScenario AMINO_ACID_INSERTION_CONTAINS_WITH_NULL_SEGMENT_SCENARIO = { | ||
.name = "aminoAcidInsertionWithNullSegment", | ||
.query = createAminoAcidInsertionContainsQueryWithEmptySequenceName(123, "A"), | ||
.expected_error_message = "The database has no default amino acid sequence name", | ||
}; | ||
|
||
QUERY_TEST( | ||
AminoAcidInsertionContainsTest, | ||
TEST_DATA, | ||
::testing::Values( | ||
AMINO_ACID_INSERTION_CONTAINS_SCENARIO, | ||
AMINO_ACID_INSERTION_CONTAINS_WITH_NULL_SEGMENT_SCENARIO | ||
) | ||
); |
Oops, something went wrong.