@@ -8715,6 +8715,67 @@ test_init_take_ownership_no_edge_metadata(void)
87158715 tsk_treeseq_free (& ts );
87168716}
87178717
8718+ static void
8719+ test_init_compute_mutation_parents (void )
8720+ {
8721+ int ret ;
8722+ tsk_table_collection_t * tables , * tables2 ;
8723+ tsk_treeseq_t ts ;
8724+ const char * sites = "0 0\n" ;
8725+ /* Make a mutation on a parallel branch the parent*/
8726+ const char * bad_mutations = "0 0 1 -1\n"
8727+ "0 1 1 0\n" ;
8728+
8729+ tables = tsk_malloc (sizeof (tsk_table_collection_t ));
8730+ CU_ASSERT_NOT_EQUAL_FATAL (tables , NULL );
8731+ tables2 = tsk_malloc (sizeof (tsk_table_collection_t ));
8732+ CU_ASSERT_NOT_EQUAL_FATAL (tables2 , NULL );
8733+
8734+ CU_ASSERT_FATAL (tables != NULL );
8735+ ret = tsk_table_collection_init (tables , 0 );
8736+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
8737+
8738+ tables -> sequence_length = 1 ;
8739+ parse_nodes (single_tree_ex_nodes , & tables -> nodes );
8740+ CU_ASSERT_EQUAL_FATAL (tables -> nodes .num_rows , 7 );
8741+ parse_edges (single_tree_ex_edges , & tables -> edges );
8742+ CU_ASSERT_EQUAL_FATAL (tables -> edges .num_rows , 6 );
8743+ parse_sites (sites , & tables -> sites );
8744+ CU_ASSERT_EQUAL_FATAL (tables -> sites .num_rows , 1 );
8745+ parse_mutations (bad_mutations , & tables -> mutations );
8746+ CU_ASSERT_EQUAL_FATAL (tables -> mutations .num_rows , 2 );
8747+ tables -> sequence_length = 1.0 ;
8748+ ret = tsk_table_collection_copy (tables , tables2 , 0 );
8749+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
8750+
8751+ ret = tsk_treeseq_init (& ts , tables , TSK_TS_INIT_BUILD_INDEXES );
8752+ CU_ASSERT_EQUAL_FATAL (ret , TSK_ERR_BAD_MUTATION_PARENT );
8753+ tsk_treeseq_free (& ts );
8754+
8755+ ret = tsk_treeseq_init (
8756+ & ts , tables , TSK_TS_INIT_BUILD_INDEXES | TSK_TS_INIT_COMPUTE_MUTATION_PARENTS );
8757+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
8758+ tsk_treeseq_free (& ts );
8759+
8760+ /* When we use take ownership, the check of parents shouldn't overwrite them*/
8761+ ret = tsk_treeseq_init (& ts , tables , TSK_TAKE_OWNERSHIP | TSK_TS_INIT_BUILD_INDEXES );
8762+ CU_ASSERT_EQUAL_FATAL (ret , TSK_ERR_BAD_MUTATION_PARENT );
8763+ CU_ASSERT_EQUAL (tables -> mutations .parent [0 ], -1 );
8764+ CU_ASSERT_EQUAL (tables -> mutations .parent [1 ], 0 );
8765+ tsk_treeseq_free (& ts );
8766+
8767+ /* When we use take ownership and compute, the tables are overwritten*/
8768+ ret = tsk_treeseq_init (& ts , tables2 ,
8769+ TSK_TAKE_OWNERSHIP | TSK_TS_INIT_BUILD_INDEXES
8770+ | TSK_TS_INIT_COMPUTE_MUTATION_PARENTS );
8771+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
8772+ CU_ASSERT_EQUAL (tables2 -> mutations .parent [0 ], -1 );
8773+ CU_ASSERT_EQUAL (tables2 -> mutations .parent [1 ], -1 );
8774+
8775+ /* Don't need to free tables as we took ownership */
8776+ tsk_treeseq_free (& ts );
8777+ }
8778+
87188779int
87198780main (int argc , char * * argv )
87208781{
@@ -8923,6 +8984,7 @@ main(int argc, char **argv)
89238984 test_extend_haplotypes_conflicting_times },
89248985 { "test_init_take_ownership_no_edge_metadata" ,
89258986 test_init_take_ownership_no_edge_metadata },
8987+ { "test_init_compute_mutation_parents" , test_init_compute_mutation_parents },
89268988 { NULL , NULL },
89278989 };
89288990
0 commit comments