示例#1
0
bool DendrogramTest::run()
{
    context("triangle.pairs");
	Graph *graph = new Graph("data/triangle.pairs");
    Dendrogram *dendro = new Dendrogram(graph);
    testcase(dendro != NULL, "Initialized Dendrogram is NULL!");
    testcase(dendro->getRoot() != NULL, "Dendrogram has NULL root");
    testcase(((InternalNode *)(dendro->getRoot()))->getLeft() != NULL, "Dendrogram root has NULL left child");
    testcase(((InternalNode *)(dendro->getRoot()))->getRight() != NULL, "Dendrogram root has NULL right child");
    
    for (NodeList::iterator iterator=dendro->nodes.begin(); iterator!=dendro->nodes.end(); iterator++) {
        DendrogramNode *node = *iterator;
        
        if (node != dendro->getRoot()) {
            test_not_equal(node->parent,NULL,"Non-root node has NULL parent");
        }
        
        if (node->type == NODE_INTERNAL) {
            InternalNode *internal = (InternalNode *)node;
            if (internal->getLeft() != NULL) {
                test_equal(internal, internal->getLeft()->parent, "Left child of X does not have X as parent");
            }
            
            if (internal->getRight() != NULL) {
                test_equal(internal, internal->getRight()->parent, "Right child of X does not have X as parent");
            }
        }
    }
    
	delete dendro;
	delete graph;
    
    context("triangle.weights");
	graph = new Graph("data/triangle.weights");
    testcase(graph->isValid(), "failed to load valid graph from data/triangle.weights");
    dendro = new Dendrogram(graph);
    testcase(dendro != NULL, "Initialized Dendrogram is NULL!");
    testcase(dendro->getRoot() != NULL, "Dendrogram has NULL root");
    for (int i=0; i<100; i++) {
        dendro->sample();
    }
    testcase(dendro->likelihood() < 0.0f, "Invalid likelihood for post-sampled dendrogram");
    graph->addNode(99);
    graph->addEdge(99,1,0.9);
    std::set<Node> nodes_ab, nodes_z;
    nodes_ab.insert(1);
    nodes_ab.insert(2);
    nodes_z.insert(99);
    testcase(graph->linksBetween(nodes_ab,nodes_z) == 0.9, "Incorrect link weight between [A,B] , [Z]");
    dendro->addLeaf(99,1);
    testcase(graph->linksBetween(nodes_ab,nodes_z) == 0.9, "Incorrect link weight between [A,B] , [Z]");
	
	return this->didPass();
}
示例#2
0
  virtual void processNode(InternalNode &u) {
    int id=u.getID();
    PhylogenyNode *left=u.getLeft(), *right=u.getRight();
    NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
    NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
    Array2D<double>::RowIn2DArray<double> row=L[id];
    for(Symbol a=0 ; a<numAlpha ; ++a) {
      row[a]=
	processInternalChild(a,left,leftPt,&u)+
	processInternalChild(a,right,rightPt,&u);
    }
  }
示例#3
0
  virtual void processNode(InternalNode &u) 
  {
    int id=u.getID();
    Array2D<double>::RowIn2DArray<double> row=L[id];
    Taxon *taxon=static_cast<Taxon*>(u.getDecoration());
    SubstitutionMatrix &leftPt=getMatrix(*taxon,LEFT);
    SubstitutionMatrix &rightPt=getMatrix(*taxon,RIGHT);
    int left=u.getLeft()->getID(), right=u.getRight()->getID();
    for(Symbol a=0 ; a<numAlpha ; ++a)
	if(a!=gap) row[a]=
	  processInternalChild(a,left,leftPt)+
	  processInternalChild(a,right,rightPt);
  }
示例#4
0
  virtual void processNode(InternalNode &u) {
    int id=u.getID();
    int left=u.getLeft()->getID(), right=u.getRight()->getID();
    NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
    NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
    Array2D<double>::RowIn2DArray<double> row=L[id];
    for(Symbol a=0 ; a<numAlpha ; ++a) {
      if(gapSymbols.isMember(a)) continue;
      row[a]=
	processInternalChild(a,left,leftPt,0,0)+
	processInternalChild(a,right,rightPt,0,0);
    }
  }
示例#5
0
  virtual void processNode(InternalNode &u) {
    int id=u.getID();
    Array2D<double>::RowIn2DArray<double> row=L[id];
    int left=u.getLeft()->getID(), right=u.getRight()->getID();
    NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
    NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
    Sequence nmer;
    for(int i=0 ; i<numNmers ; ++i) {
      nmer.fromInt(i,numCols,alphabetMap);
      row[i]=
	processInternalChild(nmer,left,leftPt)+
	processInternalChild(nmer,right,rightPt);
    }
  }
示例#6
0
  virtual void processNode(InternalNode &u) {
    int id=u.getID();
    NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
    NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
    int left=u.getLeft()->getID(), right=u.getRight()->getID();
    Array2D<double>::RowIn2DArray<double> row=L[id];
    Symbol a=A.getIthTrack(id)[column];
    if(gapSymbols.isMember(a))
      for(a=0 ; a<numAlpha ; ++a) {
	if(gapSymbols.isMember(a)) continue;
	row[a]=
	  processInternalChild(a,id,left,leftPt)+
	  processInternalChild(a,id,right,rightPt);
      }
    else {
      for(Symbol b=0 ; b<numAlpha ; ++b) row[b]=NEGATIVE_INFINITY;
      double l=processInternalChild(a,id,left,leftPt);
      double r=processInternalChild(a,id,right,rightPt);
      row[a]=l+r;
    }
  }