Esempio n. 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);
 }
Esempio n. 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;
  }
Esempio n. 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);
     }
   }
 }
Esempio n. 4
0
 private boolean checkTree(MyPhyloTree net) {
   MyPhyloTree n = new MyPhyloTree(net);
   n.setTimeDegree(null);
   HashSet<MyEdge> criticalEdges = new HashSet<MyEdge>();
   for (MyEdge e : n.getEdges()) {
     if (e.isCritical()) criticalEdges.add(e);
   }
   for (MyEdge e : criticalEdges) {
     MyNode s = e.getSource();
     MyNode t = e.getTarget();
     s.removeOutEdge(e);
     MyNode x = n.newNode();
     n.newEdge(s, x);
     n.newEdge(x, t);
   }
   CheckTimeConsistency checker = new CheckTimeConsistency();
   int k = checker.run(n, 0, false, true, -1);
   if (k != 0) return false;
   return true;
 }
Esempio n. 5
0
 private void assingPreds(
     MyNode v, HashSet<MyNode> preds, HashMap<MyNode, HashSet<MyNode>> nodeToPreds) {
   boolean isCritical = false;
   Iterator<MyEdge> it = v.getOutEdges();
   while (it.hasNext()) {
     MyEdge e = it.next();
     if (v.getOwner().isSpecial(e)) {
       if (!nodeToPreds.containsKey(v)) nodeToPreds.put(v, (HashSet<MyNode>) preds.clone());
       else nodeToPreds.get(v).addAll(preds);
       isCritical = true;
       break;
     }
   }
   if (isCritical) preds.add(v);
   it = v.getOutEdges();
   while (it.hasNext()) {
     MyEdge e = it.next();
     assingPreds(e.getTarget(), (HashSet<MyNode>) preds.clone(), nodeToPreds);
   }
 }
 private void computeClusterRec(MyPhyloTree n, MyNode v, BitSet cluster, int treeIndex) {
   if (v.getOutDegree() == 0) cluster.set(taxaOrdering.indexOf(n.getLabel(v)));
   else {
     Iterator<MyEdge> it = n.getOutEdges(v);
     while (it.hasNext()) {
       MyEdge e = it.next();
       HashSet<Integer> indices = (HashSet<Integer>) e.getInfo();
       if (indices.contains(treeIndex)) {
         MyNode c = e.getTarget();
         computeClusterRec(n, c, cluster, treeIndex);
       }
     }
   }
 }
  public void computeOcurrences() {

    int networksFactor = 0;
    for (HybridNetwork n : networks) {
      Vector<BitSet> hybridClusters = new Vector<BitSet>();
      int netFactor = 1;
      Iterator<MyNode> it = n.getNodes().iterator();
      while (it.hasNext()) {
        MyNode v = it.next();
        if (v.getInDegree() > 1) {
          BitSet cluster = computeReticulationCluster(n, v);
          hybridClusters.add(cluster);
          netFactor *= v.getInDegree() - 1;
        }
      }
      for (BitSet cluster : hybridClusters) {
        if (clusterToNumber.containsKey(cluster)) {
          int num = clusterToNumber.get(cluster) + netFactor;
          clusterToNumber.remove(cluster);
          clusterToNumber.put(cluster, num);
        } else clusterToNumber.put(cluster, netFactor);
      }
      networksFactor += netFactor;
    }

    for (HybridNetwork n : networks) {
      double sumOcc = 0;
      Iterator<MyNode> it = n.nodeIterator();
      while (it.hasNext()) {
        MyNode v = it.next();
        if (v.getInDegree() > 1 && !isClusterNode(v)) {
          if (getWeight(n, v) != null) {
            double w = getWeight(n, v);
            double s = networksFactor;
            double occProc = (w / s) * 100;
            occProc = Math.round(occProc * 100) / 100.;
            v.setLabel((int) Math.floor(occProc) + "%");
            sumOcc += occProc;
          }
        }
      }
      networkToOcc.put(n, sumOcc);
    }

    //		Collections.sort(networks, new NetworkSorter());
  }
 private boolean isClusterNode(MyNode v) {
   MyEdge outEdge = v.getOutEdges().next();
   if (((HashSet<Integer>) outEdge.getInfo()).contains(-1)) return true;
   return false;
 }