@@ -2784,6 +2784,7 @@ msp_merge_two_ancestors(msp_t *self, population_id_t population_id, label_id_t l
27842784 int ret = 0 ;
27852785 bool coalescence = false;
27862786 bool defrag_required = false;
2787+ bool store_edge = false;
27872788 tsk_id_t v ;
27882789 double l , r , l_min , r_max ;
27892790 avl_node_t * node ;
@@ -2938,26 +2939,38 @@ msp_merge_two_ancestors(msp_t *self, population_id_t population_id, label_id_t l
29382939 }
29392940 }
29402941 if (self -> store_full_arg ) {
2942+ store_edge = true;
29412943 if (!coalescence ) {
29422944 ret = msp_store_node (
29432945 self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , TSK_NULL );
29442946 if (ret < 0 ) {
29452947 goto out ;
29462948 }
29472949 }
2948- // is specified new_node_id impossible when recording full_arg?
2949- ret = msp_store_arg_edges (self , z , TSK_NULL );
2950- if (ret != 0 ) {
2951- goto out ;
2952- }
2950+
29532951 } else {
2954- if (self -> store_unary && coalescence ) {
2955- ret = msp_store_arg_edges (self , z , new_node_id );
2956- if (ret < 0 ) {
2957- goto out ;
2952+ if (self -> store_unary ) {
2953+ if (new_node_id != TSK_NULL ) {
2954+ store_edge = true;
2955+ } else {
2956+ if (self -> model .type == MSP_MODEL_DTWF ) {
2957+ ret = msp_store_node (
2958+ self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , TSK_NULL );
2959+ if (ret != 0 ) {
2960+ goto out ;
2961+ }
2962+ store_edge = true;
2963+ }
29582964 }
29592965 }
29602966 }
2967+
2968+ if (store_edge ) {
2969+ ret = msp_store_arg_edges (self , z , new_node_id );
2970+ if (ret != 0 ) {
2971+ goto out ;
2972+ }
2973+ }
29612974 if (defrag_required ) {
29622975 ret = msp_defrag_segment_chain (self , z );
29632976 if (ret != 0 ) {
@@ -3020,6 +3033,7 @@ msp_merge_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
30203033 int ret = MSP_ERR_GENERIC ;
30213034 bool coalescence = false;
30223035 bool defrag_required = false;
3036+ bool store_edge = false;
30233037 uint32_t j , h ;
30243038 double l , r , r_max , next_l , l_min ;
30253039 avl_node_t * node ;
@@ -3180,14 +3194,34 @@ msp_merge_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
31803194 }
31813195 }
31823196 if (self -> store_full_arg ) {
3197+ store_edge = true;
31833198 if (!coalescence ) {
31843199 ret = msp_store_node (
31853200 self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , individual );
31863201 if (ret < 0 ) {
31873202 goto out ;
31883203 }
31893204 }
3190- ret = msp_store_arg_edges (self , z , TSK_NULL );
3205+ } else {
3206+ if (self -> store_unary ) {
3207+ if (new_node_id != TSK_NULL ) {
3208+ store_edge = true;
3209+ } else {
3210+ if (self -> model .type == MSP_MODEL_DTWF ) {
3211+ // PASS_THROUGH_EVENT have been dealth with in merge_n_ancestors
3212+ ret = msp_store_node (self , MSP_NODE_IS_CA_EVENT , self -> time ,
3213+ population_id , individual );
3214+ if (ret < 0 ) {
3215+ goto out ;
3216+ }
3217+ store_edge = true;
3218+ }
3219+ }
3220+ }
3221+ }
3222+
3223+ if (store_edge ) {
3224+ ret = msp_store_arg_edges (self , z , new_node_id );
31913225 if (ret != 0 ) {
31923226 goto out ;
31933227 }
@@ -3246,6 +3280,18 @@ msp_merge_n_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
32463280
32473281 if (num_common_ancestors == 1 ) {
32483282 merged_head = msp_priority_queue_pop (self , Q );
3283+ if (self -> store_unary && self -> model .type == MSP_MODEL_DTWF ) {
3284+ ret = msp_store_node (
3285+ /*FIXME: not a CA_EVENT but PASS_THROUGH_EVENT*/
3286+ self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , TSK_NULL );
3287+ if (ret < 0 ) {
3288+ goto out ;
3289+ }
3290+ ret = msp_store_arg_edges (self , merged_head , TSK_NULL );
3291+ if (ret < 0 ) {
3292+ goto out ;
3293+ }
3294+ }
32493295 } else if (num_common_ancestors >= 2 ) {
32503296 msp_remove_individuals_from_population (self , Q );
32513297 if (num_common_ancestors == 2 ) {
0 commit comments