Пример #1
0
void Vertex::removeFromGraph()
{
    for(Edge *e : outEdges()) {
        e->removeLinks();
    }

    for(Edge *e : inEdges()) {
        e->removeLinks();
    }
}
Пример #2
0
void Vertex::printDump()
{
    qDebug() << "Vertex id: " << id() << "\nOut edges: ";
    for(Edge *e : outEdges()){
        qDebug() << "\tid: " << e->id() << "target: " << e->targetVertex()->id();
    }

    qDebug() << "In edges: ";
    for(Edge *e : inEdges()) {
        qDebug() << "\tid: " << e->id() << "source: " << e->sourceVertex()->id();
    }
}
Пример #3
0
double ScoreRFunction::global(const EssentialGraph& dag) const
{
	// Create list of in-edges to pass to R function;
	// adapt indices to R convention...
	std::vector<std::vector<uint> > inEdges(_vertexCount);
	std::set<uint> parents;
	std::set<uint>::iterator si;
	uint v;
	for (v = 0; v < _vertexCount; ++v) {
		parents = dag.getParents(v);
		inEdges[v].reserve(parents.size());
		for (si = parents.begin(); si != parents.end(); ++si)
			inEdges[v].push_back(*si + 1);
	}

	// Call R function for global score
	return Rcpp::as<double>(_rfunction[R_FCN_INDEX_GLOBAL_SCORE](inEdges));
}
Пример #4
0
void Vertex::addVertexLink(Vertex *otherVertex, int edgeWeight)
{
    if(otherVertex == nullptr) {
        qFatal("Trying to add nullptr vertex");
    }

    //    _vertices->contains(...);
    for(Edge *edge : outEdges()) {
        if(edge->targetVertex() == otherVertex) {
            qWarning() << "Trying to add an existing link";
            return;
        }
    }

    if(this == otherVertex) {
        Edge *outEdge = new Edge(this, otherVertex, edgeWeight);
        _edges.insert(id(), outEdge);
        _inEdges.insert(id(), outEdge);
        return;
    }

    for(Edge *edge : inEdges()) {
        if(edge->sourceVertex() == otherVertex) {
            _edges.insert(otherVertex->id(), edge->reverseEdge());
            otherVertex->_inEdges.insert(id(), edge->reverseEdge());
            return;
        }
    }

    Edge *outEdge = new Edge(this, otherVertex, edgeWeight);

    _edges.insert(otherVertex->id(), outEdge);
    otherVertex->_inEdges.insert(id(), outEdge);

    if(parentGraph().graphType() == graphTypes::notOrientGraph && !outEdge->isLoop()) {
        Edge *inEdge  = outEdge->reverseEdge();

        otherVertex->_edges.insert(id(), inEdge);
        _inEdges.insert(otherVertex->id(), inEdge);
    }
}
Пример #5
0
std::vector< std::vector<double> > ScoreRFunction::globalMLE(const EssentialGraph& dag) const
{
	// Construct list of in-edges
	std::set<uint> parents;
	Rcpp::IntegerVector shiftParents;
	Rcpp::List inEdges(dag.getVertexCount());
	for (uint v = 0; v < _vertexCount; ++v) {
		// Get parents of vertex v and adapt their indices to the R convention
		parents = dag.getParents(v);
		shiftParents = Rcpp::IntegerVector(parents.begin(), parents.end());
		for (R_len_t i = 0; i < shiftParents.size(); ++i)
			shiftParents[i]++;

		// Add parents to list of in-edges
		inEdges[v] = shiftParents;
	}

	// Calculate (and return) global MLE
	Rcpp::List listMLE = _rfunction[R_FCN_INDEX_GLOBAL_MLE](inEdges);
	std::vector< std::vector<double> > result(listMLE.size());
	for (R_len_t i = 0; i < listMLE.size(); ++i)
		result[i] = Rcpp::as<std::vector<double> >(listMLE[i]);
	return result;
}
std::vector<VD> PoaGraphImpl::consensusPath(AlignMode mode, int minCoverage) const
{
    // Pat's note on the approach here:
    //
    // "A node gets a score of NumReads if all reads go through
    //  it, and a score of -NumReads if no reads go through it The
    //  shift of -0.0001 breaks ties in favor of skipping
    //  half-full nodes.  In the 2 reads case this will get rid of
    //  insertions which are the more common error."
    //
    // The interpretation of minCoverage (which is applicable only
    // for LOCAL, SEMIGLOBAL modes) is that it represents
    // application-specific knowledge of the basal coverage level
    // of reads in the template, such that if a node is contained
    // in fewer than minCoverage reads, it will be penalized
    // against inclusion in the consensus.
    int totalReads = NumReads();

    std::list<VD> path;
    std::list<VD> sortedVertices(num_vertices(g_));
    topological_sort(g_, sortedVertices.rbegin());
    unordered_map<VD, VD> bestPrevVertex;

    // ignore ^ and $
    // TODO(dalexander): find a cleaner way to do this
    vertexInfoMap_[sortedVertices.front()].ReachingScore = 0;
    sortedVertices.pop_back();
    sortedVertices.pop_front();

    VD bestVertex = null_vertex;
    float bestReachingScore = -FLT_MAX;
    for (const VD v : sortedVertices) {
        PoaNode& vInfo = vertexInfoMap_[v];
        int containingReads = vInfo.Reads;
        int spanningReads = vInfo.SpanningReads;
        float score =
            (mode != AlignMode::GLOBAL)
                ? (2 * containingReads - 1 * std::max(spanningReads, minCoverage) - 0.0001f)
                : (2 * containingReads - 1 * totalReads - 0.0001f);
        vInfo.Score = score;
        vInfo.ReachingScore = score;
        bestPrevVertex[v] = null_vertex;
        for (const ED& e : inEdges(v, g_)) {
            VD sourceVertex = source(e, g_);
            float rsc = score + vertexInfoMap_[sourceVertex].ReachingScore;
            if (rsc > vInfo.ReachingScore) {
                vInfo.ReachingScore = rsc;
                bestPrevVertex[v] = sourceVertex;
            }
            if (rsc > bestReachingScore) {
                bestVertex = v;
                bestReachingScore = rsc;
            }
            // if the score is the same, the order we've encountered vertices
            //   might not be deterministic. Fix this by comparing on
            //   vertex_index
            else if (rsc == bestReachingScore) {
                if (get(vertex_index, g_, v) < get(vertex_index, g_, bestVertex)) bestVertex = v;
            }
        }
    }
    assert(bestVertex != null_vertex);

    // trace back from best-scoring vertex
    VD v = bestVertex;
    while (v != null_vertex) {
        path.push_front(v);
        v = bestPrevVertex[v];
    }
    return std::vector<VD>(path.begin(), path.end());
}