@@ -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,39 @@ 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+ new_node_id = msp_store_node (
2958+ self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , TSK_NULL );
2959+ ret = (int ) new_node_id ;
2960+ if (ret < 0 ) {
2961+ goto out ;
2962+ }
2963+ store_edge = true;
2964+ }
29582965 }
29592966 }
29602967 }
2968+
2969+ if (store_edge ) {
2970+ ret = msp_store_arg_edges (self , z , new_node_id );
2971+ if (ret != 0 ) {
2972+ goto out ;
2973+ }
2974+ }
29612975 if (defrag_required ) {
29622976 ret = msp_defrag_segment_chain (self , z );
29632977 if (ret != 0 ) {
@@ -3020,6 +3034,7 @@ msp_merge_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
30203034 int ret = MSP_ERR_GENERIC ;
30213035 bool coalescence = false;
30223036 bool defrag_required = false;
3037+ bool store_edge = false;
30233038 uint32_t j , h ;
30243039 double l , r , r_max , next_l , l_min ;
30253040 avl_node_t * node ;
@@ -3180,14 +3195,35 @@ msp_merge_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
31803195 }
31813196 }
31823197 if (self -> store_full_arg ) {
3198+ store_edge = true;
31833199 if (!coalescence ) {
31843200 ret = msp_store_node (
31853201 self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , individual );
31863202 if (ret < 0 ) {
31873203 goto out ;
31883204 }
31893205 }
3190- ret = msp_store_arg_edges (self , z , TSK_NULL );
3206+ } else {
3207+ if (self -> store_unary ) {
3208+ if (new_node_id != TSK_NULL ) {
3209+ store_edge = true;
3210+ } else {
3211+ if (self -> model .type == MSP_MODEL_DTWF ) {
3212+ // PASS_THROUGH_EVENT have been dealth with in merge_n_ancestors
3213+ new_node_id = msp_store_node (self , MSP_NODE_IS_CA_EVENT , self -> time ,
3214+ population_id , individual );
3215+ ret = (int ) new_node_id ;
3216+ if (ret < 0 ) {
3217+ goto out ;
3218+ }
3219+ store_edge = true;
3220+ }
3221+ }
3222+ }
3223+ }
3224+
3225+ if (store_edge ) {
3226+ ret = msp_store_arg_edges (self , z , new_node_id );
31913227 if (ret != 0 ) {
31923228 goto out ;
31933229 }
@@ -3246,6 +3282,21 @@ msp_merge_n_ancestors(msp_t *self, avl_tree_t *Q, population_id_t population_id,
32463282
32473283 if (num_common_ancestors == 1 ) {
32483284 merged_head = msp_priority_queue_pop (self , Q );
3285+ if (self -> store_unary ) {
3286+ if (self -> model .type == MSP_MODEL_DTWF ) {
3287+ new_node_id = msp_store_node (
3288+ /*FIXME: not a CA_EVENT but PASS_THROUGH_EVENT*/
3289+ self , MSP_NODE_IS_CA_EVENT , self -> time , population_id , TSK_NULL );
3290+ ret = (int ) new_node_id ;
3291+ if (ret < 0 ) {
3292+ goto out ;
3293+ }
3294+ }
3295+ ret = msp_store_arg_edges (self , merged_head , new_node_id );
3296+ if (ret != 0 ) {
3297+ goto out ;
3298+ }
3299+ }
32493300 } else if (num_common_ancestors >= 2 ) {
32503301 msp_remove_individuals_from_population (self , Q );
32513302 if (num_common_ancestors == 2 ) {
0 commit comments