当前位置: 首页>>代码示例>>C++>>正文


C++ SequenceTree::addLeafs方法代码示例

本文整理汇总了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);
}
开发者ID:arvestad,项目名称:FastPhylo,代码行数:101,代码来源:SequenceBasedNJ.cpp


注:本文中的SequenceTree::addLeafs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。