@@ -3640,6 +3640,7 @@ test_single_tree_iter_depths(void)
36403640 tsk_tree_free (& tree );
36413641 tsk_treeseq_free (& ts );
36423642}
3643+
36433644static void
36443645test_single_tree_simplify (void )
36453646{
@@ -3697,6 +3698,55 @@ test_single_tree_simplify(void)
36973698 tsk_table_collection_free (& tables );
36983699}
36993700
3701+ static void
3702+ test_single_tree_simplify_debug (void )
3703+ {
3704+ tsk_treeseq_t ts , simplified ;
3705+ tsk_id_t samples [] = { 0 , 1 };
3706+ int ret ;
3707+ FILE * save_stdout = stdout ;
3708+ FILE * tmp = fopen (_tmp_file_name , "w" );
3709+
3710+ CU_ASSERT_FATAL (tmp != NULL );
3711+ tsk_treeseq_from_text (& ts , 1 , single_tree_ex_nodes , single_tree_ex_edges , NULL ,
3712+ single_tree_ex_sites , single_tree_ex_mutations , NULL , NULL , 0 );
3713+
3714+ stdout = tmp ;
3715+ ret = tsk_treeseq_simplify (& ts , samples , 2 , TSK_DEBUG , & simplified , NULL );
3716+ stdout = save_stdout ;
3717+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
3718+ CU_ASSERT_TRUE (ftell (tmp ) > 0 );
3719+
3720+ fclose (tmp );
3721+ tsk_treeseq_free (& ts );
3722+ tsk_treeseq_free (& simplified );
3723+ }
3724+
3725+ static void
3726+ test_single_tree_simplify_keep_input_roots (void )
3727+ {
3728+ tsk_treeseq_t ts ;
3729+ tsk_table_collection_t tables ;
3730+ tsk_id_t samples [] = { 0 , 1 };
3731+ int ret ;
3732+
3733+ tsk_treeseq_from_text (& ts , 1 , single_tree_ex_nodes , single_tree_ex_edges , NULL ,
3734+ single_tree_ex_sites , single_tree_ex_mutations , NULL , NULL , 0 );
3735+ verify_simplify (& ts );
3736+ ret = tsk_treeseq_copy_tables (& ts , & tables , 0 );
3737+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
3738+
3739+ ret = tsk_table_collection_simplify (& tables , samples , 2 , TSK_KEEP_INPUT_ROOTS , NULL );
3740+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
3741+ CU_ASSERT_EQUAL (tables .nodes .num_rows , 4 );
3742+ CU_ASSERT_EQUAL (tables .edges .num_rows , 3 );
3743+ CU_ASSERT_EQUAL (tables .sites .num_rows , 3 );
3744+ CU_ASSERT_EQUAL (tables .mutations .num_rows , 4 );
3745+
3746+ tsk_treeseq_free (& ts );
3747+ tsk_table_collection_free (& tables );
3748+ }
3749+
37003750static void
37013751test_single_tree_simplify_no_sample_nodes (void )
37023752{
@@ -4283,6 +4333,60 @@ test_nonbinary_multi_tree(void)
42834333 tsk_treeseq_free (& ts );
42844334}
42854335
4336+ static void
4337+ test_simplify_keep_input_roots_multi_tree (void )
4338+ {
4339+
4340+ /*
4341+ 0.25┊ 8 ┊ ┊ ┊
4342+ ┊ ┏━┻━┓ ┊ ┊ ┊
4343+ 0.20┊ ┃ ┃ ┊ ┊ 7 ┊
4344+ ┊ ┃ ┃ ┊ ┊ ┏━┻━┓ ┊
4345+ 0.17┊ 6 ┃ ┊ 6 ┊ ┃ ┃ ┊
4346+ ┊ ┏━┻┓ ┃ ┊ ┏━┻━┓ ┊ ┃ ┃ ┊
4347+ 0.09┊ ┃ 5 ┃ ┊ ┃ 5 ┊ ┃ 5 ┊
4348+ ┊ ┃ ┏┻┓ ┃ ┊ ┃ ┏━┻┓ ┊ ┃ ┏━┻┓ ┊
4349+ 0.07┊ ┃ ┃ ┃ ┃ ┊ ┃ ┃ 4 ┊ ┃ ┃ 4 ┊
4350+ ┊ ┃ ┃ ┃ ┃ ┊ ┃ ┃ ┏┻┓ ┊ ┃ ┃ ┏┻┓ ┊
4351+ 0.00┊ 0 1 3 2 ┊ 0 1 2 3 ┊ 0 1 2 3 ┊
4352+ 0.00 2.00 7.00 10.00
4353+
4354+ Simplifies to
4355+
4356+ 0.25┊ 4 ┊ ┊ ┊
4357+ ┊ ┃ ┊ ┊ ┊
4358+ 0.20┊ ┃ ┊ ┊ 3 ┊
4359+ ┊ ┃ ┊ ┊ ┏┻┓ ┊
4360+ 0.17┊ 2 ┊ 2 ┊ ┃ ┃ ┊
4361+ ┊ ┏┻┓ ┊ ┏┻┓ ┊ ┃ ┃ ┊
4362+ 0.00┊ 0 1 ┊ 0 1 ┊ 0 1 ┊
4363+ 0.00 2.00 7.00 10.00
4364+
4365+ */
4366+ int ret = 0 ;
4367+ // clang-format off
4368+ tsk_id_t parents [] = {
4369+ 2 , 2 , 4 , -1 , -1 ,
4370+ 2 , 2 , -1 , -1 , -1 ,
4371+ 3 , 3 , -1 , -1 , -1 ,
4372+ };
4373+ // clang-format on
4374+ uint32_t num_trees = 3 ;
4375+
4376+ tsk_id_t samples [] = { 0 , 3 };
4377+ tsk_treeseq_t ts , simplified ;
4378+
4379+ tsk_treeseq_from_text (& ts , 10 , paper_ex_nodes , paper_ex_edges , NULL , paper_ex_sites ,
4380+ paper_ex_mutations , paper_ex_individuals , NULL , 0 );
4381+ tsk_treeseq_dump (& ts , "tmp.trees" , 0 );
4382+ ret = tsk_treeseq_simplify (& ts , samples , 2 , TSK_KEEP_INPUT_ROOTS , & simplified , NULL );
4383+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
4384+ verify_trees (& simplified , num_trees , parents );
4385+
4386+ tsk_treeseq_free (& ts );
4387+ tsk_treeseq_free (& simplified );
4388+ }
4389+
42864390static void
42874391test_left_to_right_multi_tree (void )
42884392{
@@ -5839,6 +5943,9 @@ main(int argc, char **argv)
58395943 { "test_single_tree_iter_times" , test_single_tree_iter_times },
58405944 { "test_single_tree_iter_depths" , test_single_tree_iter_depths },
58415945 { "test_single_tree_simplify" , test_single_tree_simplify },
5946+ { "test_single_tree_simplify_debug" , test_single_tree_simplify_debug },
5947+ { "test_single_tree_simplify_keep_input_roots" ,
5948+ test_single_tree_simplify_keep_input_roots },
58425949 { "test_single_tree_simplify_no_sample_nodes" ,
58435950 test_single_tree_simplify_no_sample_nodes },
58445951 { "test_single_tree_simplify_null_samples" ,
@@ -5859,6 +5966,8 @@ main(int argc, char **argv)
58595966 { "test_internal_sample_multi_tree" , test_internal_sample_multi_tree },
58605967 { "test_internal_sample_simplified_multi_tree" ,
58615968 test_internal_sample_simplified_multi_tree },
5969+ { "test_simplify_keep_input_roots_multi_tree" ,
5970+ test_simplify_keep_input_roots_multi_tree },
58625971 { "test_left_to_right_multi_tree" , test_left_to_right_multi_tree },
58635972 { "test_gappy_multi_tree" , test_gappy_multi_tree },
58645973 { "test_tsk_treeseq_bad_records" , test_tsk_treeseq_bad_records },
0 commit comments