From 1c25594c7673726a712fbcb2abef123103f8baa8 Mon Sep 17 00:00:00 2001 From: NhanLT Date: Wed, 15 Feb 2023 21:56:43 +1100 Subject: [PATCH 1/2] Change to use reference to unique_ptr instead of rvalue reference to avoid unnecessary moves --- maple/cmaple.cpp | 6 +++--- tree/node.cpp | 2 +- tree/node.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/maple/cmaple.cpp b/maple/cmaple.cpp index 1df225b..1e4e453 100644 --- a/maple/cmaple.cpp +++ b/maple/cmaple.cpp @@ -295,14 +295,14 @@ void test() std::cout << " Update partial_lh " << std::endl; std::unique_ptr new_partial_lh = std::make_unique(SeqRegions()); new_partial_lh->emplace_back(0, 100); - phylonode1.setPartialLh(mini_index, std::move(new_partial_lh)); + phylonode1.setPartialLh(mini_index, new_partial_lh); std::cout << "- (size of) partial_lh: " << phylonode1.getPartialLh(mini_index)->size() << std::endl; std::cout << " Update partial_lh 2nd time" << std::endl; std::unique_ptr new_partial_lh2 = std::make_unique(SeqRegions()); new_partial_lh2->emplace_back(1, 200); new_partial_lh2->emplace_back(2, 300); - phylonode1.setPartialLh(mini_index, std::move(new_partial_lh2)); + phylonode1.setPartialLh(mini_index, new_partial_lh2); std::cout << "- (size of) partial_lh: " << phylonode1.getPartialLh(mini_index)->size() << std::endl; // test phylonode is an internal node @@ -322,7 +322,7 @@ void test() std::unique_ptr new_partial_lh1 = std::make_unique(SeqRegions()); new_partial_lh1->emplace_back(0, 100); new_partial_lh1->emplace_back(1, 200); - phylonode2.setPartialLh(mini_index2, std::move(new_partial_lh1)); + phylonode2.setPartialLh(mini_index2, new_partial_lh1); std::cout << "- (size of) partial_lh at the left mininode: " << phylonode2.getPartialLh(mini_index2)->size() << std::endl; // create a phylonode as an internal node diff --git a/tree/node.cpp b/tree/node.cpp index b58e3eb..159092c 100644 --- a/tree/node.cpp +++ b/tree/node.cpp @@ -88,7 +88,7 @@ std::unique_ptr& PhyloNode::getPartialLh(const MiniIndex mini_index) return data_.leaf.partial_lh_; } -void PhyloNode::setPartialLh(const MiniIndex mini_index, std::unique_ptr&& partial_lh) +void PhyloNode::setPartialLh(const MiniIndex mini_index, std::unique_ptr& partial_lh) { // if it's an internal node if (is_internal_) diff --git a/tree/node.h b/tree/node.h index 93d7da1..50aa395 100644 --- a/tree/node.h +++ b/tree/node.h @@ -288,7 +288,7 @@ class PhyloNode /** Set partial_lh */ - void setPartialLh(const MiniIndex mini_index, std::unique_ptr&& partial_lh); + void setPartialLh(const MiniIndex mini_index, std::unique_ptr& partial_lh); /** Get the index of the neighbor node From 14d59253ff6775b6c4c1fb094664f7eb17596e2a Mon Sep 17 00:00:00 2001 From: NhanLT Date: Fri, 17 Feb 2023 19:01:43 +1100 Subject: [PATCH 2/2] Add logs for debugging --- alignment/seqregions.cpp | 14 ++++++++++++++ tree/tree.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/alignment/seqregions.cpp b/alignment/seqregions.cpp index 698f086..7a5d1e1 100644 --- a/alignment/seqregions.cpp +++ b/alignment/seqregions.cpp @@ -644,6 +644,13 @@ void SeqRegions::mergeUpperLower(SeqRegions* &merged_regions, { merge_RACGT_ORACGT(*seq1_region, *seq2_region, total_blength_1, total_blength_2, upper_plength, end_pos, threshold_prob, model, aln, *merged_regions); } + + // NHANLT: LOGS FOR DEBUGGING + /*if (merged_regions->at(merged_regions->size()-1).type == TYPE_O) + { + SeqRegion::LHType lh = *merged_regions->at(merged_regions->size()-1).likelihood; + std::cout << "mergeUpLow " << pos << " " << std::setprecision(20) << lh[0] << " " << lh[1] << " " << lh[2] << " " << lh[3] << " " << std::endl; + }*/ } // update pos @@ -1011,6 +1018,13 @@ RealNumType SeqRegions::mergeTwoLowers(SeqRegions* &merged_regions, RealNumType { if (!merge_notN_notN_TwoLowers(*seq1_region, *seq2_region, plength1, plength2, end_pos, pos, aln, model, threshold_prob, log_lh, merged_regions, return_log_lh)) return MIN_NEGATIVE; } + + // NHANLT: LOGS FOR DEBUGGING + /*if (merged_regions->at(merged_regions->size()-1).type == TYPE_O) + { + SeqRegion::LHType lh = *merged_regions->at(merged_regions->size()-1).likelihood; + std::cout << "merge2Low " << pos << " " << std::setprecision(20) << lh[0] << " " << lh[1] << " " << lh[2] << " " << lh[3] << " " << std::endl; + }*/ // update pos pos = end_pos + 1; } diff --git a/tree/tree.cpp b/tree/tree.cpp index 229bb27..cb5e514 100644 --- a/tree/tree.cpp +++ b/tree/tree.cpp @@ -1715,6 +1715,10 @@ void Tree::connectNewSample2Branch(SeqRegions* const sample, const std::string & next_node_1->getPartialLhAtNode(aln, model, threshold_prob)->mergeUpperLower(new_sample_node->mid_branch_lh, half_branch_length, *sample, half_branch_length, aln, model, threshold_prob); } + // NHANLT: LOGS FOR DEBUGGING + /*cout << "2Branch " << seq_name << " " << (best_blength > 0?new_sample_node->total_lh->size():0)<< " " << (best_blength > 0?new_sample_node->mid_branch_lh->size():0)<< " " << new_sample_node->partial_lh->size()<< " " << new_internal_node->total_lh->size()<< " " << new_internal_node->mid_branch_lh->size()<< " " << new_internal_node->partial_lh->size() << " " << next_node_1->partial_lh->size() << " " << next_node_2->partial_lh->size() << std::endl; + cout << std::setprecision(20) << new_internal_node->length << " " << sibling_node->length << " " << new_sample_node->length << std::endl;*/ + // update pseudo_count model.updatePesudoCount(aln, *next_node_1->getPartialLhAtNode(aln, model, threshold_prob), *sample); @@ -1957,6 +1961,10 @@ void Tree::connectNewSample2Root(SeqRegions* const sample, const std::string &se createFurtherMidNodes(new_root.children[1],new_root.probVectUpLeft)*/ } + // NHANLT: LOGS FOR DEBUGGING + /*cout << "2Root " << seq_name << " " << (best_length2 > 0 ?new_sample_node->total_lh->size():0)<< " " << (best_length2 > 0?new_sample_node->mid_branch_lh->size():0)<< " " << new_sample_node->partial_lh->size()<< " " << new_root->total_lh->size()<< " " << new_root->partial_lh->size() << " " << next_node_1->partial_lh->size() << " " << next_node_2->partial_lh->size() << std::endl; + cout << std::setprecision(20) << sibling_node->length << " " << new_sample_node->length << std::endl;*/ + // update tree->root; root = new_root;