@@ -37,7 +37,7 @@ TEST(config_test, write_to)
3737 std::string const expected_file{" @HIBF_CONFIG\n "
3838 " @{\n "
3939 " @ \" hibf_config\" : {\n "
40- " @ \" version\" : 2 ,\n "
40+ " @ \" version\" : 3 ,\n "
4141 " @ \" number_of_user_bins\" : 123456789,\n "
4242 " @ \" number_of_hash_functions\" : 4,\n "
4343 " @ \" maximum_fpr\" : 0.0001,\n "
@@ -46,6 +46,7 @@ TEST(config_test, write_to)
4646 " @ \" sketch_bits\" : 8,\n "
4747 " @ \" tmax\" : 128,\n "
4848 " @ \" empty_bin_fraction\" : 0.0,\n "
49+ " @ \" track_occupancy\" : false,\n "
4950 " @ \" alpha\" : 1.0,\n "
5051 " @ \" max_rearrangement_ratio\" : 0.333,\n "
5152 " @ \" disable_estimate_union\" : true,\n "
@@ -62,7 +63,7 @@ TEST(config_test, read_from)
6263 std::stringstream ss{" @HIBF_CONFIG\n "
6364 " @{\n "
6465 " @ \" hibf_config\" : {\n "
65- " @ \" version\" : 2 ,\n "
66+ " @ \" version\" : 3 ,\n "
6667 " @ \" number_of_user_bins\" : 123456789,\n "
6768 " @ \" number_of_hash_functions\" : 4,\n "
6869 " @ \" maximum_fpr\" : 0.0001,\n "
@@ -71,6 +72,7 @@ TEST(config_test, read_from)
7172 " @ \" sketch_bits\" : 8,\n "
7273 " @ \" tmax\" : 128,\n "
7374 " @ \" empty_bin_fraction\" : 0.5,\n "
75+ " @ \" track_occupancy\" : true,\n "
7476 " @ \" alpha\" : 1.0,\n "
7577 " @ \" max_rearrangement_ratio\" : 0.333,\n "
7678 " @ \" disable_estimate_union\" : true,\n "
@@ -90,6 +92,7 @@ TEST(config_test, read_from)
9092 EXPECT_EQ (configuration.sketch_bits , 8 );
9193 EXPECT_EQ (configuration.tmax , 128 );
9294 EXPECT_EQ (configuration.empty_bin_fraction , 0.5 );
95+ EXPECT_EQ (configuration.track_occupancy , true );
9396 EXPECT_EQ (configuration.alpha , 1.0 );
9497 EXPECT_EQ (configuration.max_rearrangement_ratio , 0.333 );
9598 EXPECT_EQ (configuration.disable_estimate_union , true );
@@ -134,6 +137,46 @@ TEST(config_test, read_from_v1)
134137 EXPECT_EQ (configuration.disable_rearrangement , false );
135138}
136139
140+ TEST (config_test, read_from_v2)
141+ {
142+ std::stringstream ss{" @HIBF_CONFIG\n "
143+ " @{\n "
144+ " @ \" hibf_config\" : {\n "
145+ " @ \" version\" : 2,\n "
146+ " @ \" number_of_user_bins\" : 123456789,\n "
147+ " @ \" number_of_hash_functions\" : 4,\n "
148+ " @ \" maximum_fpr\" : 0.0001,\n "
149+ " @ \" relaxed_fpr\" : 0.3,\n "
150+ " @ \" threads\" : 31,\n "
151+ " @ \" sketch_bits\" : 8,\n "
152+ " @ \" tmax\" : 128,\n "
153+ " @ \" empty_bin_fraction\" : 0.5,\n "
154+ " @ \" alpha\" : 1.0,\n "
155+ " @ \" max_rearrangement_ratio\" : 0.333,\n "
156+ " @ \" disable_estimate_union\" : true,\n "
157+ " @ \" disable_rearrangement\" : false\n "
158+ " @ }\n "
159+ " @}\n "
160+ " @HIBF_CONFIG_END\n " };
161+
162+ seqan::hibf::config configuration;
163+ configuration.read_from (ss);
164+
165+ EXPECT_EQ (configuration.number_of_user_bins , 123456789 );
166+ EXPECT_EQ (configuration.number_of_hash_functions , 4 );
167+ EXPECT_EQ (configuration.maximum_fpr , 0.0001 );
168+ EXPECT_EQ (configuration.relaxed_fpr , 0.3 );
169+ EXPECT_EQ (configuration.threads , 31 );
170+ EXPECT_EQ (configuration.sketch_bits , 8 );
171+ EXPECT_EQ (configuration.tmax , 128 );
172+ EXPECT_EQ (configuration.empty_bin_fraction , 0.5 );
173+ EXPECT_EQ (configuration.track_occupancy , true );
174+ EXPECT_EQ (configuration.alpha , 1.0 );
175+ EXPECT_EQ (configuration.max_rearrangement_ratio , 0.333 );
176+ EXPECT_EQ (configuration.disable_estimate_union , true );
177+ EXPECT_EQ (configuration.disable_rearrangement , false );
178+ }
179+
137180TEST (config_test, read_from_with_more_meta)
138181{
139182 std::stringstream ss{" @blah some chopper stuff\n "
@@ -144,14 +187,16 @@ TEST(config_test, read_from_with_more_meta)
144187 " @HIBF_CONFIG\n "
145188 " @{\n "
146189 " @ \" hibf_config\" : {\n "
147- " @ \" version\" : 1 ,\n "
190+ " @ \" version\" : 3 ,\n "
148191 " @ \" number_of_user_bins\" : 123456789,\n "
149192 " @ \" number_of_hash_functions\" : 4,\n "
150193 " @ \" maximum_fpr\" : 0.0001,\n "
151194 " @ \" relaxed_fpr\" : 0.3,\n "
152195 " @ \" threads\" : 31,\n "
153196 " @ \" sketch_bits\" : 8,\n "
154197 " @ \" tmax\" : 128,\n "
198+ " @ \" empty_bin_fraction\" : 0.0,\n "
199+ " @ \" track_occupancy\" : true,\n "
155200 " @ \" alpha\" : 1.0,\n "
156201 " @ \" max_rearrangement_ratio\" : 0.333,\n "
157202 " @ \" disable_estimate_union\" : true,\n "
@@ -170,6 +215,8 @@ TEST(config_test, read_from_with_more_meta)
170215 EXPECT_EQ (configuration.threads , 31 );
171216 EXPECT_EQ (configuration.sketch_bits , 8 );
172217 EXPECT_EQ (configuration.tmax , 128 );
218+ EXPECT_EQ (configuration.empty_bin_fraction , 0.0 );
219+ EXPECT_EQ (configuration.track_occupancy , true );
173220 EXPECT_EQ (configuration.alpha , 1.0 );
174221 EXPECT_EQ (configuration.max_rearrangement_ratio , 0.333 );
175222 EXPECT_EQ (configuration.disable_estimate_union , true );
@@ -349,6 +396,20 @@ TEST(config_test, validate_and_set_defaults)
349396 " [HIBF CONFIG ERROR] config::empty_bin_fraction must be in [0.0,1.0)." );
350397 }
351398
399+ // empty_bin_fraction != 0.0 also enables tracking occupancy
400+ {
401+ seqan::hibf::config configuration{.input_fn = dummy_input_fn,
402+ .number_of_user_bins = 1u ,
403+ .empty_bin_fraction = 0.0 ,
404+ .track_occupancy = false };
405+ configuration.validate_and_set_defaults ();
406+ EXPECT_EQ (configuration.track_occupancy , false );
407+
408+ configuration.empty_bin_fraction = 0.3 ;
409+ configuration.validate_and_set_defaults ();
410+ EXPECT_EQ (configuration.track_occupancy , true );
411+ }
412+
352413 // alpha must be positive
353414 {
354415 seqan::hibf::config configuration{.input_fn = dummy_input_fn, .number_of_user_bins = 1u , .alpha = -0.1 };
@@ -413,6 +474,8 @@ TEST(config_test, serialisation)
413474 .threads = 31 ,
414475 .sketch_bits = 8 ,
415476 .tmax = 128 ,
477+ .empty_bin_fraction = 0.13 ,
478+ .track_occupancy = true ,
416479 .alpha = 1.0 ,
417480 .max_rearrangement_ratio = 0.333 ,
418481 .disable_estimate_union = true ,
0 commit comments