@@ -10508,21 +10508,27 @@ template <const StateType num_states>
1050810508void cmaple::Tree::updatePesudoCountModel (PhyloNode& node,
1050910509 const Index node_index,
1051010510 const Index parent_index) {
10511- std::unique_ptr<SeqRegions>& upper_lr_regions =
10512- getPartialLhAtNode (parent_index);
10511+
1051310512 std::unique_ptr<SeqRegions>& lower_regions = node.getPartialLh (TOP);
10514- if (node.getUpperLength () > 0 && upper_lr_regions && lower_regions) {
10515- // de-integrate mutations at node, if any
10516- if (node_mutations[node_index.getVectorIndex ()])
10517- {
10518- model->updatePesudoCount (aln, *upper_lr_regions,
10519- *(lower_regions->integrateMutations <num_states>(node_mutations[node_index.getVectorIndex ()], aln)));
10520- }
10521- // otherwise, normally update the pseudo count
10522- else
10523- {
10524- model->updatePesudoCount (aln, *upper_lr_regions, *lower_regions);
10525- }
10513+ if (node.getUpperLength () > 0 && getPartialLhAtNode (parent_index) && lower_regions) {
10514+ // 0. extract the mutations at the current node
10515+ std::unique_ptr<SeqRegions>& this_node_mutations =
10516+ node_mutations[node_index.getVectorIndex ()];
10517+ // 1. create a new upper_lr_regions that integrate the mutations, if any
10518+ std::unique_ptr<SeqRegions> mut_integrated_upper_lr_regions =
10519+ (this_node_mutations && this_node_mutations->size ())
10520+ ? getPartialLhAtNode (parent_index)
10521+ ->integrateMutations <num_states>(this_node_mutations, aln)
10522+ : nullptr ;
10523+ // 2. create the pointer that points to the appropriate upper_lr_regions
10524+ const std::unique_ptr<SeqRegions>* upper_lr_regions_ptr =
10525+ (this_node_mutations && this_node_mutations->size ())
10526+ ? &(mut_integrated_upper_lr_regions)
10527+ : &(getPartialLhAtNode (parent_index));
10528+ // 3. create a reference from that pointer
10529+ auto & upper_lr_regions = *upper_lr_regions_ptr;
10530+
10531+ model->updatePesudoCount (aln, *upper_lr_regions, *lower_regions);
1052610532 }
1052710533}
1052810534
0 commit comments