Permalink
Browse files

Dead code removal

  • Loading branch information...
1 parent 1607b44 commit b6a40a8441555d1bd7dd8c23528c4fc420b37d0f @jts committed Mar 12, 2013
Showing with 7 additions and 290 deletions.
  1. +0 −2 src/SGA/assemble.cpp
  2. +0 −29 src/StringGraph/SGAlgorithms.cpp
  3. +3 −3 src/StringGraph/SGAlgorithms.h
  4. +4 −256 src/StringGraph/SGVisitors.cpp
@@ -139,8 +139,6 @@ void assemble()
SGRemodelVisitor remodelVisit;
SGEdgeStatsVisitor edgeStatsVisit;
SGTrimVisitor trimVisit(opt::trimLengthThreshold);
- SGBubbleVisitor bubbleVisit;
- SGBubbleEdgeVisitor bubbleEdgeVisit;
SGContainRemoveVisitor containVisit;
SGValidateStructureVisitor validationVisit;
@@ -117,35 +117,6 @@ Edge* SGAlgorithms::createEdgesFromOverlap(StringGraph* pGraph, const Overlap& o
void SGAlgorithms::remodelVertexForExcision(StringGraph* pGraph, Vertex* pVertex, Edge* pDeleteEdge)
{
assert(pVertex == pDeleteEdge->getStart());
- double maxER = pGraph->getErrorRate();
- int minLength = pGraph->getMinOverlap();
-
- CompleteOverlapSet vertexOverlapSet(pVertex, maxER, minLength);
-
- vertexOverlapSet.removeOverlapsTo(pDeleteEdge->getEnd());
- EdgeDescOverlapMap addMap;
- EdgeDescOverlapMap removeMap;
- EdgeDescOverlapMap containMap;
- vertexOverlapSet.computeIrreducible(NULL, &containMap);
-
- vertexOverlapSet.getDiffMap(addMap, removeMap);
-
- //assert(removeMap.size() == 0);
- for(EdgeDescOverlapMap::iterator iter = addMap.begin();
- iter != addMap.end(); ++iter)
- {
- //std::cout << "Adding edge " << iter->second << "\n";
- createEdgesFromOverlap(pGraph, iter->second, false);
- }
-
- // Set the contain flags based on newly discovered edges
- updateContainFlags(pGraph, pVertex, containMap);
-}
-
-// Find new edges for pVertex that are required if pDeleteEdge is removed from the graph
-void SGAlgorithms::remodelVertexForExcision2(StringGraph* pGraph, Vertex* pVertex, Edge* pDeleteEdge)
-{
- assert(pVertex == pDeleteEdge->getStart());
// If the edge is a containment edge, nothing needs to be done. No edges can be transitive
// through containments
if(pDeleteEdge->getOverlap().isContainment())
@@ -24,7 +24,7 @@ namespace SGAlgorithms
typedef std::pair<EdgeDesc, Overlap> EdgeDescOverlapPair;
typedef std::set<VertexID> VertexIDSet;
-// Comparator
+// Compare two edges by their overlap length
struct EDOPairCompare
{
bool operator()(const EdgeDescOverlapPair& edpXY, const EdgeDescOverlapPair& edpXZ)
@@ -41,9 +41,9 @@ typedef std::priority_queue<EdgeDescOverlapPair,
typedef std::map<EdgeDesc, Overlap> EdgeDescOverlapMap;
typedef std::set<EdgeDesc> EdgeDescSet;
-// Find new edges for pVertex that are required if pDeleteEdge is removed from the graph
+// Remodel the graph by finding new edges for the given vertex to avoid
+// causing a disconnection when removing pDeleteEdge
void remodelVertexForExcision(StringGraph* pGraph, Vertex* pVertex, Edge* pDeleteEdge);
-void remodelVertexForExcision2(StringGraph* pGraph, Vertex* pVertex, Edge* pDeleteEdge);
// Create the edges described by the overlap.
Edge* createEdgesFromOverlap(StringGraph* pGraph, const Overlap& o, bool allowContained, size_t maxEdges = -1);
@@ -257,9 +257,9 @@ bool SGContainRemoveVisitor::visit(StringGraph* pGraph, Vertex* pVertex)
{
Vertex* pRemodelVert = neighborEdges[j]->getEnd();
Edge* pRemodelEdge = neighborEdges[j]->getTwin();
- SGAlgorithms::remodelVertexForExcision2(pGraph,
- pRemodelVert,
- pRemodelEdge);
+ SGAlgorithms::remodelVertexForExcision(pGraph,
+ pRemodelVert,
+ pRemodelEdge);
}
}
@@ -776,261 +776,9 @@ void SGOverlapRatioVisitor::postvisit(StringGraph* pGraph)
pGraph->sweepEdges(GC_RED);
}
-
-//
-// SGBubbleVisitor - Find and collapse variant
-// "bubbles" in the graph
-//
-void SGBubbleVisitor::previsit(StringGraph* pGraph)
-{
- pGraph->setColors(GC_WHITE);
- num_bubbles = 0;
-}
-
-// Find bubbles (nodes where there is a split and then immediate rejoin) and mark them for removal
-bool SGBubbleVisitor::visit(StringGraph* /*pGraph*/, Vertex* pVertex)
-{
- bool bubble_found = false;
- for(size_t idx = 0; idx < ED_COUNT; idx++)
- {
- EdgeDir dir = EDGE_DIRECTIONS[idx];
- EdgePtrVec edges = pVertex->getEdges(dir);
- if(edges.size() > 1)
- {
- Vertex* pStart = pVertex;
- Vertex* pEnd = NULL;
- // Check the vertices
- for(size_t i = 0; i < edges.size(); ++i)
- {
- Edge* pVWEdge = edges[i];
- Vertex* pWVert = pVWEdge->getEnd();
-
- // Get the edges from w in the same direction
- EdgeDir transDir = !pVWEdge->getTwinDir();
- EdgePtrVec wEdges = pWVert->getEdges(transDir);
-
- if(pWVert->getColor() == GC_RED)
- return false;
-
- // If the bubble has collapsed, there should only be one edge
- if(wEdges.size() == 1)
- {
- Vertex* pBubbleEnd = wEdges.front()->getEnd();
- if(pBubbleEnd->getColor() == GC_RED)
- return false;
- }
- }
-
- // Mark the vertices
- for(size_t i = 0; i < edges.size(); ++i)
- {
- Edge* pVWEdge = edges[i];
- Vertex* pWVert = pVWEdge->getEnd();
-
- // Get the edges from w in the same direction
- EdgeDir transDir = !pVWEdge->getTwinDir();
- EdgePtrVec wEdges = pWVert->getEdges(transDir);
-
- // If the bubble has collapsed, there should only be one edge
- if(wEdges.size() == 1)
- {
- Vertex* pBubbleEnd = wEdges.front()->getEnd();
- if(pBubbleEnd->getColor() == GC_BLACK)
- {
- // The endpoint has been visited, set this vertex as needing removal
- // and set the endpoint as unvisited
- pWVert->setColor(GC_RED);
- bubble_found = true;
- pEnd = pBubbleEnd;
- }
- else
- {
- pBubbleEnd->setColor(GC_BLACK);
- pWVert->setColor(GC_BLUE);
- }
- }
- }
-
- // Unmark vertices
- for(size_t i = 0; i < edges.size(); ++i)
- {
- Edge* pVWEdge = edges[i];
- Vertex* pWVert = pVWEdge->getEnd();
-
- // Get the edges from w in the same direction
- EdgeDir transDir = !pVWEdge->getTwinDir();
- EdgePtrVec wEdges = pWVert->getEdges(transDir);
-
- // If the bubble has collapsed, there should only be one edge
- if(wEdges.size() == 1)
- {
- Vertex* pBubbleEnd = wEdges.front()->getEnd();
- pBubbleEnd->setColor(GC_WHITE);
- }
- if(pWVert->getColor() == GC_BLUE)
- pWVert->setColor(GC_WHITE);
- }
-
- (void)pStart;
- (void)pEnd;
- if(bubble_found)
- {
- /*
- SGWalkVector walkVector;
- SGSearch::findWalks(pStart, pEnd, dir, 1000, 20, walkVector);
-
- if(walkVector.size() == 2)
- {
- SGWalk& walk1 = walkVector[0];
- SGWalk& walk2 = walkVector[1];
-
- int len1 = walk1.getStartToEndDistance();
- int len2 = walk2.getStartToEndDistance();
- int diff = len1 - len2;
- std::string type = "SNP";
- if(diff != 0)
- {
- type = "INDEL";
- }
- std::cout << "Bubble " << pStart->getID() << " to " << pEnd->getID() << " is a "
- << type << "(d: " << diff << ")\n";
- }
- */
- ++num_bubbles;
- }
- }
- }
- return bubble_found;
-}
-
-// Remove all the marked edges
-void SGBubbleVisitor::postvisit(StringGraph* pGraph)
-{
- pGraph->sweepVertices(GC_RED);
- printf("bubbles: %d\n", num_bubbles);
- assert(pGraph->checkColors(GC_WHITE));
-}
-
//
-// SGBubbleEdgeVisitor
+// SGSuperRepeatVisitor
//
-void SGBubbleEdgeVisitor::previsit(StringGraph* pGraph)
-{
- pGraph->setColors(GC_WHITE);
- num_bubbles = 0;
-}
-
-// Find bubbles (nodes where there is a split and then immediate rejoin) and mark them for removal
-bool SGBubbleEdgeVisitor::visit(StringGraph* /*pGraph*/, Vertex* pX)
-{
- bool bubble_found = false;
- for(size_t idx = 0; idx < ED_COUNT; idx++)
- {
- EdgeDir dir = EDGE_DIRECTIONS[idx];
- EdgePtrVec edges = pX->getEdges(dir);
- if(edges.size() == 2) // di-bubbles only for now
- {
- // Determine which edge has a shorter overlap to pX
- // Call the longer overlap pY, the shorter pZ
- Edge* pXY;
- Edge* pXZ;
-
- if(edges[0]->getOverlap().getOverlapLength(0) > edges[1]->getOverlap().getOverlapLength(0))
- {
- pXY = edges[0];
- pXZ = edges[1];
- }
- else if(edges[1]->getOverlap().getOverlapLength(0) > edges[0]->getOverlap().getOverlapLength(0))
-
- {
- pXY = edges[1];
- pXZ = edges[0];
- }
- else
- {
- break; // equal length overlaps, cannot be a bubble or else the vertices would be contained
- }
-
- // Mark the neighbors of pZ as the "target" vertices
- // if they can be reached by pY we mark pY as being unreliable and remove it
- typedef std::list<Vertex*> VertexPtrList;
- VertexPtrList targetList;
-
- EdgeDir targetDir = pXZ->getTransitiveDir();
- EdgePtrVec targetEdges = pXZ->getEnd()->getEdges(targetDir);
- for(size_t i = 0; i < targetEdges.size(); ++i)
- targetList.push_back(targetEdges[i]->getEnd());
-
- // Start exploring from pY
- ExploreQueue queue;
- Overlap ovrXY = pXY->getOverlap();
- EdgeDesc edXY = pXY->getDesc();
- queue.push(ExploreElement(edXY, ovrXY));
-
- int numSteps = 100;
- WARN_ONCE("USING FIXED NUMBER OF STEPS IN BUBBLE EDGE");
- while(!queue.empty() && numSteps-- > 0)
- {
- ExploreElement ee = queue.front();
- EdgeDesc& edXY = ee.ed;
- Vertex* pY = edXY.pVertex;
- Overlap& ovrXY = ee.ovr;
-
- queue.pop();
-
- // Check if Y is on the target list
- VertexPtrList::iterator iter = targetList.begin();
- while(iter != targetList.end())
- {
- if(*iter == edXY.pVertex)
- targetList.erase(iter++);
- else
- ++iter;
- }
-
- if(targetList.empty())
- break;
-
- // Enqueue the neighbors of pY
- EdgeDir dirY = edXY.getTransitiveDir();
- EdgePtrVec edges = pY->getEdges(dirY);
- for(size_t i = 0; i < edges.size(); ++i)
- {
- Edge* pEdge = edges[i];
- Vertex* pZ = pEdge->getEnd();
-
- // Compute the edgeDesc and overlap on pX for this edge
- Overlap ovrYZ = pEdge->getOverlap();
-
- if(SGAlgorithms::hasTransitiveOverlap(ovrXY, ovrYZ))
- {
- Overlap ovrXZ = SGAlgorithms::inferTransitiveOverlap(ovrXY, ovrYZ);
- EdgeDesc edXZ = SGAlgorithms::overlapToEdgeDesc(pZ, ovrXZ);
- queue.push(ExploreElement(edXZ, ovrXZ));
- }
- }
- }
-
- if(targetList.empty())
- {
- // bubble found
- pXZ->getEnd()->deleteEdges();
- pXZ->getEnd()->setColor(GC_RED);
- bubble_found = true;
- ++num_bubbles;
- }
- }
- }
- return bubble_found;
-}
-
-// Remove all the marked vertices
-void SGBubbleEdgeVisitor::postvisit(StringGraph* pGraph)
-{
- pGraph->sweepVertices(GC_RED);
- printf("bubbles: %d\n", num_bubbles);
- assert(pGraph->checkColors(GC_WHITE));
-}
// Remove all edges of nodes that have been marked as super repeats
void SGSuperRepeatVisitor::previsit(StringGraph*)

0 comments on commit b6a40a8

Please sign in to comment.