Пример #1
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);
     }
   }
 }
Пример #2
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);
 }
Пример #3
0
  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());
  }
Пример #4
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;
  }