Пример #1
0
 private void cmpTrivialInteractions(MyPhyloTree n, HashMap<MyNode, HashSet<MyNode>> nodeToPreds) {
   HashSet<MyNode> retNodes = new HashSet<MyNode>();
   for (MyNode v : n.getNodes()) {
     if (v.getInDegree() > 1) {
       retNodes.add(v);
     }
   }
   HashSet<MyEdge> toResolve = new HashSet<MyEdge>();
   for (MyNode v : retNodes) {
     Vector<MyNode> parentNodes = new Vector<MyNode>();
     Vector<MyEdge> parentEdges = new Vector<MyEdge>();
     Iterator<MyEdge> it = v.getInEdges();
     while (it.hasNext()) {
       MyEdge e = it.next();
       parentNodes.add(e.getSource());
       parentEdges.add(e);
     }
     for (MyNode p1 : parentNodes) {
       for (MyNode p2 : parentNodes) {
         if (nodeToPreds.get(p1).contains(p2)) {
           if (ancestorCheck(p1, p2)) toResolve.add(parentEdges.get(parentNodes.indexOf(p2)));
         }
       }
     }
   }
   for (MyEdge e : toResolve) trivialEdges.add(e);
 }
Пример #2
0
  public int run(MyPhyloTree net, int border, boolean storeNetworkInfo, boolean smartMode) {

    int result = 0;
    for (MyPhyloTree n : new GetNetworkCluster().run(net)) {

      trivialEdges = new HashSet<MyEdge>();

      if (smartMode) {
        HashMap<MyNode, HashSet<MyNode>> nodeToPreds = new HashMap<MyNode, HashSet<MyNode>>();
        assingPreds(n.getRoot(), new HashSet<MyNode>(), nodeToPreds);
        cmpTrivialInteractions(n, nodeToPreds);
      }

      Vector<MyEdge> retEdges = new Vector<MyEdge>();
      for (MyNode v : n.getNodes()) {
        if (v.getInDegree() > 1) {
          Iterator<MyEdge> it = v.getInEdges();
          while (it.hasNext()) {
            MyEdge e = it.next();
            if (!trivialEdges.contains(e)) retEdges.add(e);
          }
        }
      }

      int addTaxaDegree = -1;
      for (int k = trivialEdges.size(); k <= border; k++) {
        HashSet<Vector<MyEdge>> allSubsets = new HashSet<Vector<MyEdge>>();
        getAllSubsets(0, retEdges, k - trivialEdges.size(), new Vector<MyEdge>(), allSubsets);
        for (Vector<MyEdge> subset : allSubsets) {
          clearEdges(n);
          setEdges(subset);
          if (checkTree(n)) {
            if (storeNetworkInfo) {
              n.setAddTaxaDegree(k);
              setEdges(subset);
            } else clearEdges(n);
            addTaxaDegree = k;
            break;
          }
        }
        if (addTaxaDegree != -1) break;
      }

      if (addTaxaDegree == -1) return -1;
      else {
        result += addTaxaDegree;
        border -= addTaxaDegree;
      }
    }

    if (result != -1) net.setAddTaxaDegree(result);

    return result;
  }
Пример #3
0
 private void cmpImplicitAncestorsRec(boolean b, MyNode v, Vector<MyNode> implicitAncestors) {
   if (v.getInDegree() > 1 || b) {
     Iterator<MyEdge> it = v.getInEdges();
     while (it.hasNext()) {
       MyEdge e = it.next();
       MyNode a = e.getSource();
       implicitAncestors.add(a);
       cmpImplicitAncestorsRec(v.getInDegree() != 1, a, implicitAncestors);
     }
   }
 }