本文整理汇总了C++中SequenceTree::addLeafs方法的典型用法代码示例。如果您正苦于以下问题:C++ SequenceTree::addLeafs方法的具体用法?C++ SequenceTree::addLeafs怎么用?C++ SequenceTree::addLeafs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SequenceTree
的用法示例。
在下文中一共展示了SequenceTree::addLeafs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defaultString
//.........这里部分代码省略.........
//----------------
// 4.
// NJ ITERATION
//compute the row sums
while ( dm.getSize() > 3 ) {
//FIND MIN PAIR
//find the minimal value
double minVal = FLT_MAX;
size_t mini = 1000000;
size_t minj = 1000000;
for ( size_t i = 0 ; i < dm.getSize() ; i++ ){
for ( size_t j = i+1 ; j < dm.getSize() ; j++ ){
double newVal = (dm.getSize() - 2.0)*dm.getDistance(i,j) - rowSums[i] - rowSums[j];
//std::cout << newVal << " , ";
if ( newVal < minVal ){
minVal = newVal;
mini = i;
minj = j;
}
}
}
// std::cout << std::endl;
//PRINT(minVal);
//make sure that minj is the last row in the matrix
if ( mini == dm.getSize() -1 ){
mini = minj;
}
else {
dm.swapRowToLast(minj);
double tmp = rowSums[dm.getSize()-1];
rowSums[dm.getSize()-1] = rowSums[minj];
rowSums[minj] = tmp;
}
minj = dm.getSize()-1;
//CLUSTER THE LEAFS
DNA_b128_String &child1str = dm.getIdentifier(mini)->data;
DNA_b128_String &child2str = dm.getIdentifier(minj)->data;
b128Tree::Node *parent = dm.getIdentifier(mini)->getTree()->detachFromParentAndAddAsSiblings(dm.getIdentifier(mini),dm.getIdentifier(minj), defaultString);
dm.setIdentifier(mini, parent);
//COMPUTE PARSIMONY AND SET IN PARENT
DNA_b128_String &parentstr = parent->data;
DNA_b128_String::create_weighted_parsimonious(parentstr,child1str,child2str);
//COMPUTE DISTANCES FROM PARENT TO ALL OTHER NODES
//PRINT(mini);PRINT(minj);
for ( size_t i = 0 ; i < dm.getSize()-1 ; i++ ){//skip last row
double dist2iandj = dm.getDistance(mini,i) + dm.getDistance(minj,i);
DNA_b128_String &leafstr = dm.getIdentifier(i)->data;
double dist = computeK2PDistance(parentstr,leafstr);
// regular nj update function:
//double regnj = dist2iandj * 0.5;
//double studier = (dist2iandj-dm.getDistance(mini,minj))*0.5;
//PRINT(dist); PRINT(regnj);PRINT(dist2iandj);PRINT(dist-regnj);PRINT(dist-studier);
//PRINT(dist - dm.getDistance(mini,i) );PRINT(dist - dm.getDistance(minj,i) );
dm.setDistance(mini,i, dist);
//update rowsums
rowSums[i] = rowSums[i] - dist2iandj + dm.getDistance(mini,i);
//PRINT(rowSums[i]);
}
dm.setDistance(mini,mini,0);
//remove the last row of the matrix
dm.removeLastRow();
//recompute the row sum for the parent
double sum = 0;
for ( size_t i = 0 ; i < dm.getSize() ; i++ )
sum += dm.getDistance(mini,i);
rowSums[mini] = sum;
}
//END ITERATION
//----------------------------------
//CONVERT THE TREE TO A SEQUENCE TREE
tree.recalcNodeStructure();
// tree.drawTree(std::cout);
b128Tree::NodeVector leafnodes;
tree.addLeafs(leafnodes);
Sequence_double dummy;
dummy.dbl = -1;
resultTree = SequenceTree(tree,dummy);
SequenceTree::NodeVector seqnodes;
resultTree.addLeafs(seqnodes);
for ( size_t i = 0 ; i < seqnodes.size() ; i++ ){
seqnodes[i]->data.s = *((Sequence *) node2seqs[leafnodes[i]]);
}
//resultTree.drawTree(std::cout);
}