Skip to content

Commit e27649c

Browse files
committed
feat(silo): error if 2 sequences link to same nodeId, do not error if sequence has no node or node has no sequence
1 parent a2b28d8 commit e27649c

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/silo/common/phylo_tree.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ roaring::Roaring PhyloTree::getDescendents(const TreeNodeId& node_id) {
272272
dfs(child);
273273
}
274274
};
275+
if (child_it->second->isLeaf()) {
276+
return result_bitmap;
277+
}
275278
dfs(child_it->second);
276279
return result_bitmap;
277280
}

src/silo/common/phylo_tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TreeNode {
2121
int depth;
2222

2323
bool isLeaf() { return children.empty(); }
24+
bool rowIndexExists() const { return row_index.has_value(); }
2425
};
2526

2627
class PhyloTree {

src/silo/storage/column/string_column.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "silo/common/bidirectional_map.h"
66
#include "silo/common/string.h"
77
#include "silo/common/tree_node_id.h"
8+
#include "silo/initialize/initialize_exception.h"
89

910
using silo::common::String;
1011
using silo::common::STRING_SIZE;
@@ -42,8 +43,15 @@ void StringColumnPartition::insert(const std::string& value) {
4243
const String<STRING_SIZE> tmp(value, metadata->dictionary);
4344
values.push_back(tmp);
4445
if (metadata->phylo_tree.has_value()) {
45-
metadata->phylo_tree->validateNodeExists(value);
4646
auto child_it = (metadata->phylo_tree->nodes).find(TreeNodeId{value});
47+
if (child_it == metadata->phylo_tree->nodes.end()) {
48+
return;
49+
}
50+
if (child_it->second->rowIndexExists()) {
51+
throw silo::initialize::InitializeException(
52+
fmt::format("Node '{}' already exists in the phylogenetic tree.", value)
53+
);
54+
}
4755
child_it->second->row_index = values.size() - 1;
4856
}
4957
}

src/silo/storage/column/string_column.test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "silo/storage/column/string_column.h"
22

33
#include <gtest/gtest.h>
4+
#include "silo/common/phylo_tree.h"
45

56
using silo::storage::column::StringColumnMetadata;
67
using silo::storage::column::StringColumnPartition;
@@ -27,6 +28,25 @@ TEST(StringColumnPartition, rawInsertedValuesRequeried) {
2728
EXPECT_EQ(under_test.getValues()[5].toString(metadata.dictionary), "value 1");
2829
}
2930

31+
TEST(StringColumnPartition, rawInsertedValuesWithPhyloTreeRequeried) {
32+
auto phylo_tree = silo::common::PhyloTree::fromNewickString(
33+
"((CHILD2:0.5, CHILD3:1)CHILD:0.1, NOT_IN_DATASET:1.5)ROOT;"
34+
);
35+
StringColumnMetadata metadata{"string_column", std::move(phylo_tree)};
36+
StringColumnPartition under_test(&metadata);
37+
38+
under_test.insert("CHILD2");
39+
under_test.insert("CHILD3");
40+
under_test.insert("NOT_IN_TREE");
41+
42+
EXPECT_EQ(under_test.getValues()[0].toString(metadata.dictionary), "CHILD2");
43+
EXPECT_EQ(under_test.getValues()[1].toString(metadata.dictionary), "CHILD3");
44+
EXPECT_EQ(under_test.getValues()[2].toString(metadata.dictionary), "NOT_IN_TREE");
45+
EXPECT_EQ(under_test.getDescendents("CHILD2").cardinality(), 0);
46+
EXPECT_EQ(under_test.getDescendents("CHILD").cardinality(), 2);
47+
EXPECT_EQ(under_test.getDescendents("ROOT").cardinality(), 2);
48+
}
49+
3050
TEST(StringColumn, rawInsertedValuesRequeried) {
3151
StringColumnMetadata column("string_column");
3252
StringColumnPartition under_test{&column};

0 commit comments

Comments
 (0)