Esempio n. 1
1
 /**
  * create a new vertex, with the exact same name and weights, and only the depth is like the old
  * one + its length
  *
  * @param id
  * @param v
  */
 public SeqVertex(int id, SeqVertex v) {
   this(id, v.getName());
   int len = v.getWeights().size();
   _weights.ensureCapacity(len);
   for (int i = 0; i < len; i++) _weights.add(i, v.getWeights().get(i));
   _depth = v.getDepth() + v.getName().length();
 }
Esempio n. 2
0
 /**
  * Would factoring out this suffix result in elimating the reference source vertex?
  *
  * @param graph the graph
  * @param commonSuffix the common suffix of all toSplits
  * @param toSplits the list of vertices we're are trying to split
  * @return true if toSplit contains the reference source and this ref source has all and only the
  *     bases of commonSuffix
  */
 private boolean wouldEliminateRefSource(
     final SeqGraph graph, final SeqVertex commonSuffix, final Collection<SeqVertex> toSplits) {
   for (final SeqVertex toSplit : toSplits) {
     if (graph.isRefSource(toSplit)) return toSplit.length() == commonSuffix.length();
   }
   return false;
 }
Esempio n. 3
0
  /**
   * Would all vertices that we'd split just result in the common suffix?
   *
   * <p>That is, suppose we have prefix nodes ABC and ABC. After splitting all of the vertices would
   * just be ABC again, and we'd enter into an infinite loop.
   *
   * @param commonSuffix the common suffix of all vertices in toSplits
   * @param toSplits the collection of vertices we want to split
   * @return true if all of the vertices are equal to the common suffix
   */
  private boolean allVerticesAreTheCommonSuffix(
      final SeqVertex commonSuffix, final Collection<SeqVertex> toSplits) {
    for (final SeqVertex toSplit : toSplits) {
      if (toSplit.length() != commonSuffix.length()) return false;
    }

    return true;
  }
Esempio n. 4
0
  /**
   * Create a new seqvertex, with all ids from vWithL as prevID
   *
   * @param nextID
   * @param l
   * @param origVers
   */
  public SeqVertex(int id, String name, Collection<SeqVertex> origVers) {
    this(id, name);
    Vector<Integer> thisNewLetter = new Vector<Integer>();
    for (SeqVertex v : origVers) {
      Vector<Integer> vID = v.getAndRemoveLastID(); // this was for the last letter graphs
      thisNewLetter.addAll(vID);
    }

    _prevVerticesID.add(thisNewLetter);
  }
Esempio n. 5
0
 /**
  * create a new seqVertex, and give it the first id in this prev IDs remove the first prevIDS.
  *
  * @return
  */
 public SeqVertex generateNewVerWithFirstIDasID() {
   Integer firstID = getAndRemoveFirstID();
   if (firstID == getID()) return this;
   SeqVertex newV = new SeqVertex(firstID, getName());
   newV._prevVerticesID = getPrevVerIDs();
   newV._dfsFinishTime = _dfsFinishTime;
   //		newV._height = _height;
   newV._depth = _depth;
   newV._weights = _weights;
   return newV;
 }
Esempio n. 6
0
  public void addIDsAsFirstPrevIDs(Collection<SeqVertex> vWithL, int lAST_REAL_ID) {
    Vector<Integer> prevIDs = new Vector<Integer>();
    for (SeqVertex v : vWithL) {
      int vid = v.getID();
      if (vid >= 0)
        if (vid <= lAST_REAL_ID) prevIDs.add(vid);
        else if (!v.getPrevVerIDs().isEmpty()) {
          prevIDs.addAll(v.getPrevVerIDs().get(0));
          v.getPrevVerIDs().remove(0);
        }
    }

    _prevVerticesID.add(prevIDs);
  }
Esempio n. 7
0
  /*
   * add the given vertex info into this vertex
   * combine name and weights
   */
  public void concatVertex(SeqVertex vertex, Double w, int lastRealID) {
    int prevLen = getName().length();
    setName(getName() + vertex.getName());
    _weights.add(w);
    _weights.addAll(vertex.getWeights());
    // System.out.println(toStringWeights());
    Vector<Integer> newV = new Vector<Integer>();
    if (vertex.getID() <= lastRealID) {
      newV.add(vertex.getID());
      _prevVerticesID.add(newV);
    }
    _prevVerticesID.addAll(vertex.getPrevVerIDs());

    if (vertex.getDegenerativeFreq().size() > 0) {
      // 			System.err.println(vertex.getID()+":"+vertex.getDegenerativeFreq());
      // 			System.err.println(vertex.getID()+":"+vertex.getDegenerativeLocations());
      // 			System.err.println(vertex.getID()+":"+vertex.getDegenerativeLetters());
      // 			System.err.println(getID()+":"+getName());
      // 			System.err.println(prevLen);

      _degenerativeLocations.add(prevLen + 1);
      _degenerativeFreq.addAll(vertex.getDegenerativeFreq());
      _degenerativeLetters.addAll(vertex.getDegenerativeLetters());
    }
  }
Esempio n. 8
0
  /**
   * Simple single-function interface to split and then update a graph
   *
   * @param graph the graph containing the vertices in toMerge
   * @param v The bottom node whose incoming vertices we'd like to split
   * @return true if some useful splitting was done, false otherwise
   */
  public boolean split(final SeqGraph graph, final SeqVertex v) {
    if (graph == null) throw new IllegalArgumentException("graph cannot be null");
    if (v == null) throw new IllegalArgumentException("v cannot be null");
    if (!graph.vertexSet().contains(v))
      throw new IllegalArgumentException("graph doesn't contain vertex v " + v);

    final Collection<SeqVertex> toSplit = graph.incomingVerticesOf(v);
    if (toSplit.size() < 2)
      // Can only split at least 2 vertices
      return false;
    else if (!safeToSplit(graph, v, toSplit)) {
      return false;
    } else {
      final SeqVertex suffixVTemplate = commonSuffix(toSplit);
      if (suffixVTemplate.isEmpty()) {
        return false;
      } else if (wouldEliminateRefSource(graph, suffixVTemplate, toSplit)) {
        return false;
      } else if (allVerticesAreTheCommonSuffix(suffixVTemplate, toSplit)) {
        return false;
      } else {
        final List<BaseEdge> edgesToRemove = new LinkedList<BaseEdge>();

        //                graph.printGraph(new File("split.pre_" + v.getSequenceString() + "." +
        // counter + ".dot"), 0);
        for (final SeqVertex mid : toSplit) {
          // create my own copy of the suffix
          final SeqVertex suffixV = new SeqVertex(suffixVTemplate.getSequence());
          graph.addVertex(suffixV);
          final SeqVertex prefixV = mid.withoutSuffix(suffixV.getSequence());
          final BaseEdge out = graph.outgoingEdgeOf(mid);

          final SeqVertex incomingTarget;
          if (prefixV == null) {
            // this node is entirely explained by suffix
            incomingTarget = suffixV;
          } else {
            incomingTarget = prefixV;
            graph.addVertex(prefixV);
            graph.addEdge(prefixV, suffixV, new BaseEdge(out.isRef(), 1));
            edgesToRemove.add(out);
          }

          graph.addEdge(suffixV, graph.getEdgeTarget(out), out.copy());

          for (final BaseEdge in : graph.incomingEdgesOf(mid)) {
            graph.addEdge(graph.getEdgeSource(in), incomingTarget, in.copy());
            edgesToRemove.add(in);
          }
        }

        graph.removeAllVertices(toSplit);
        graph.removeAllEdges(edgesToRemove);
        //                graph.printGraph(new File("split.post_" + v.getSequenceString() + "." +
        // counter++ + ".dot"), 0);

        return true;
      }
    }
  }
Esempio n. 9
0
  /**
   * add the ver id from the vToRemove to this vertex previous ids
   *
   * @param vToKeep
   * @param vToRemove
   */
  public void addToPrevIDs(SeqVertex vToKeep, SeqVertex vToRemove, int lastRealID) {
    if (_prevVerticesID.isEmpty()) {
      Vector<Integer> thisV = new Vector<Integer>();
      if (vToKeep.getID() >= lastRealID) thisV.add(vToKeep.getID());
      if (vToRemove.getID() >= lastRealID) thisV.add(vToRemove.getID());
      if (!vToKeep.getPrevVerIDs().isEmpty()) thisV.addAll(vToKeep.getPrevVerIDs().firstElement());
      if (!vToRemove.getPrevVerIDs().isEmpty())
        thisV.addAll(vToRemove.getPrevVerIDs().firstElement());

      _prevVerticesID.add(thisV);
    } else {
      assert (true);
    }
  }
Esempio n. 10
0
 /**
  * add the name of v1 to this name
  *
  * @param v1
  */
 public void addToName(SeqVertex v1) {
   _name = _name + v1.getName();
 }
Esempio n. 11
0
 public void copyTheRest(SeqVertex v) {
   _prevVerticesID = v.getPrevVerIDs();
   _dfsFinishTime = v._dfsFinishTime;
   _depth = v._depth;
   _weights = v._weights;
 }