Skip to content

Commit

Permalink
feat: throw error in preprocessing when default sequence is not in re…
Browse files Browse the repository at this point in the history
…ference genomes

closes #454
  • Loading branch information
fengelniederhammer committed Jul 16, 2024
1 parent b2c9325 commit 4c76b08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/silo/preprocessing/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Preprocessor {
Database preprocess();

private:
void validateConfig();

static std::string makeNonNullKey(const std::string& field);
std::string getPartitionKeySelect() const;

Expand Down
27 changes: 27 additions & 0 deletions src/silo/preprocessing/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Preprocessor::Preprocessor(
}

Database Preprocessor::preprocess() {
validateConfig();

SPDLOG_INFO(
"preprocessing - creating intermediate results directory '{}'",
preprocessing_config.getIntermediateResultsDirectory().string()
Expand Down Expand Up @@ -126,6 +128,31 @@ Database Preprocessor::preprocess() {
);
}

void Preprocessor::validateConfig() {
bool default_nucleotide_sequence_is_not_in_reference =
database_config.default_nucleotide_sequence.has_value() &&
std::find(
nuc_sequences.begin(), nuc_sequences.end(), *database_config.default_nucleotide_sequence
) == nuc_sequences.end();
if (default_nucleotide_sequence_is_not_in_reference) {
throw silo::preprocessing::PreprocessingException(
"The default nucleotide sequence that is set in the database config is not contained in "
"the reference genomes."
);
}
bool default_amino_acid_sequence_is_not_in_reference =
database_config.default_amino_acid_sequence.has_value() &&
std::find(
aa_sequences.begin(), aa_sequences.end(), *database_config.default_amino_acid_sequence
) == aa_sequences.end();
if (default_amino_acid_sequence_is_not_in_reference) {
throw silo::preprocessing::PreprocessingException(
"The default amino acid sequence that is set in the database config is not contained in "
"the reference genomes."
);
}
}

void Preprocessor::buildTablesFromNdjsonInput(const ValidatedNdjsonFile& input_file) {
(void)preprocessing_db.query(fmt::format(
"CREATE OR REPLACE TABLE metadata_table({});",
Expand Down

0 comments on commit 4c76b08

Please sign in to comment.