Package org.broadinstitute.gatk.tools.walkers.haplotypecaller.readthreading

Examples of org.broadinstitute.gatk.tools.walkers.haplotypecaller.readthreading.MultiDeBruijnVertex


        final Set<MultiDeBruijnVertex> haplotypeVertices = haplotypeRoute.vertexSet();
        final Map<GATKSAMRecord, ReadCost> readCostByRead = new HashMap<>();
        final Set<MultiDeBruijnVertex> visitedVertices = new HashSet<>(haplotypeVertices.size());
        final List<MultiSampleEdge> edgeList = haplotypeRoute.getEdges();

        MultiDeBruijnVertex currentVertex = haplotypeRoute.getFirstVertex();
        Route<MultiDeBruijnVertex, MultiSampleEdge> pathSoFar = new Route<>(currentVertex, haplotypeGraph);
        final Iterator<MultiSampleEdge> edgeIterator = edgeList.iterator();

        while (true) {
            visitedVertices.add(currentVertex);
View Full Code Here


     * Add a new read-segment-cost to an ending vertex indexed map.
     * @param destination where to add the read-segment-cost.
     * @param cost the read-segment-cost to add.
     */
    private void addReadSegmentCost(final Map<MultiDeBruijnVertex,Set<ReadSegmentCost>> destination, final ReadSegmentCost cost) {
        final MultiDeBruijnVertex endVertex = cost.path.getLastVertex();
        Set<ReadSegmentCost> vpcSet = destination.get(endVertex);
        if (vpcSet == null)
            destination.put(endVertex, vpcSet = new HashSet<>(10));
        vpcSet.add(cost);
    }
View Full Code Here

            return result;
        }
        // General return cases:
        final ListIterator<MultiDeBruijnVertex> it = vertices.listIterator(includePathEnds ? 0 : 1); // skip the vertex (exclusive)
        for (int i = 0; i < resultLength; i++) { // i < resultLength implicitly skips the last vertex (exclusive).
            final MultiDeBruijnVertex vertex = it.next();
            if (i == 0 && includePathEnds && pathStartsAtSource) {
                System.arraycopy(vertex.getSequence(), 0, result, 0, kmerSize);
                i = kmerSize - 1;
            } else
                result[i] = vertex.getSuffix();
        }
        return result;
    }
View Full Code Here

        final Deque<Pair<Route<MultiDeBruijnVertex, MultiSampleEdge>, Set<HaplotypeRoute>>> queue = new LinkedList<>();
        queue.add(new Pair<>(new Route<>(start, haplotypeGraph), validHaplotypeRoutes));
        while (!queue.isEmpty()) {
            final Pair<Route<MultiDeBruijnVertex, MultiSampleEdge>, Set<HaplotypeRoute>> current = queue.remove();
            final Route<MultiDeBruijnVertex, MultiSampleEdge> path = current.getFirst();
            final MultiDeBruijnVertex vertex = forward ? path.getLastVertex() : path.getFirstVertex();
            final Set<HaplotypeRoute> validRoutes = current.getSecond();
            for (final HaplotypeRoute hr : validRoutes) {
                final MultiDeBruijnVertex routeEndVertex = forward ? hr.getLastVertex() : hr.getFirstVertex();
                if (vertex.equals(routeEndVertex)) {
                    result.add(path);
                    break;
                }
            }
View Full Code Here

        referenceAlignment = calculateUniqueKmerAlignment(0, readBases.length, haplotypeGraph.getReferenceRoute(), vertexOffset, haplotypeGraph.getKmerSize());
        leftAnchorIndex = -1;
        leftAnchorVertex = null;
        for (int i = 0; i < readBases.length - haplotypeGraph.getKmerSize() + 1; i++) {
            if (referenceAlignment[i] == -1) continue;
            final MultiDeBruijnVertex candidate = haplotypeGraph.findKmer(readKmers.get(i));
            if (candidate != null && haplotypeGraph.getAnchorableVertices().contains(candidate)) {
                leftAnchorIndex = i;
                leftAnchorVertex = candidate;
                break;
            }
        }
        rightAnchorIndex = leftAnchorIndex;
        rightAnchorVertex = leftAnchorVertex;
        if (leftAnchorIndex != -1) {
            for (int i = readBases.length - haplotypeGraph.getKmerSize(); i > leftAnchorIndex; i--) {
                if (referenceAlignment[i] == -1) continue;
                final MultiDeBruijnVertex candidate = haplotypeGraph.findKmer(readKmers.get(i));
                if (candidate != null && haplotypeGraph.getAnchorableVertices().contains(candidate)) {
                    rightAnchorIndex = i;
                    rightAnchorVertex = candidate;
                    break;
                }
View Full Code Here

            final MultiDeBruijnVertex leftAnchorVertex, final MultiDeBruijnVertex rightAnchorVertex) {
        if (leftAnchorVertex == null)
            return Collections.emptyMap();

        final Map<MultiDeBruijnVertex, Integer> result = new HashMap<>();
        MultiDeBruijnVertex nextVertex = leftAnchorVertex;

        int leftAnchorOffset = 0;
        while (nextVertex != null) {
            result.put(nextVertex, leftAnchorOffset++);
            if (nextVertex == rightAnchorVertex)
View Full Code Here

        final HaplotypeRoute referenceRoute = graph.getReferenceRoute();

        while (!queue.isEmpty()) {
            final Route<MultiDeBruijnVertex, MultiSampleEdge> route = queue.remove();
            final MultiDeBruijnVertex routeEndVertex = route.getLastVertex();

            if (routeEndVertex == sink) // bingo!!!
                result.add(route);
            else { // only queue promising extension of this route.
                final int routeEndPosition = referenceRoute.getVertexPosition(routeEndVertex);
View Full Code Here

     */
    private EventBlock findEventBlock(
            final ReadAnchoring anchoring, final boolean backwards,
            final MultiDeBruijnVertex leftVertex, final MultiDeBruijnVertex rightVertex) {

        MultiDeBruijnVertex currentVertex = backwards ? rightVertex : leftVertex;
        boolean foundEvent = false;
        final CountSet pathSizes = new CountSet(10); // typically more than enough.
        pathSizes.setTo(0);

        // Map between reference vertices where there is some expected open alternative path rejoining and the
        // predicted length of paths rejoining at that point counting from the beginning of the block.
        final Map<MultiDeBruijnVertex, CountSet> expectedAlternativePathRejoins = new HashMap<>(4);

        // Keeps record of possible left-clipping veritces; those that are located before any event path furcation
        // has been found. The value indicates the blockLength at the time we traverse that node.
        final Deque<Pair<MultiDeBruijnVertex, Integer>> possibleClippingPoints = new LinkedList<>();

        // We keep the distance from the beggining of the block (leftVertex).
        int blockLength = 0;
        while (currentVertex != null) {
            int openingDegree = backwards ? graph.outDegreeOf(currentVertex) : graph.inDegreeOf(currentVertex);
            if (openingDegree > 1) {
                final CountSet joiningPathLengths = expectedAlternativePathRejoins.remove(currentVertex);
                if (joiningPathLengths != null)
                    pathSizes.addAll(joiningPathLengths);
            }
            final boolean isValidBlockEnd = isValidBlockEnd(anchoring, currentVertex, expectedAlternativePathRejoins);
            if (foundEvent && isValidBlockEnd) // !gotcha we found a valid block end.
                break;
            else if (!foundEvent && isValidBlockEnd) // if no event has been found yet, still is a good clipping point.
                possibleClippingPoints.addLast(new Pair<>(currentVertex, blockLength));

            // We reached the end:
            if (currentVertex == (backwards ? leftVertex : rightVertex))
                break;

            // process next vertices, the next one on the reference and also possible start of alternative paths,
            // updates traversal structures accordingly.
            currentVertex = advanceOnReferencePath(anchoring, backwards, currentVertex, pathSizes, expectedAlternativePathRejoins);
            foundEvent |= expectedAlternativePathRejoins.size() > 0;
            pathSizes.incAll(1);
            blockLength++;
        }

        // we have not found an event, thus there is no block to report:
        if (!foundEvent)
            return null;

        // We try to clip off as much as we can from the beginning of the block before any event, but at least
        // leaving enough block length to meet the shortest path unless all paths have the same size (SNPs only)
        final int maxClipping = pathSizes.size() <= 1 ? blockLength : pathSizes.min();
        MultiDeBruijnVertex clippingEnd = backwards ? anchoring.rightAnchorVertex : anchoring.leftAnchorVertex;
        while (!possibleClippingPoints.isEmpty()) {
            final Pair<MultiDeBruijnVertex, Integer> candidate = possibleClippingPoints.removeLast();
            if (candidate.getSecond() <= maxClipping) {
                clippingEnd = candidate.getFirst();
                break;
View Full Code Here

     * @param expectedAlternativePathRejoins information about location of vertices along the reference path where open alternative paths will rejoin.
     * @return the next current-vertex, never {@code null} unless there is a bug.
     */
    private MultiDeBruijnVertex advanceOnReferencePath(final ReadAnchoring anchoring, final boolean backwards, final MultiDeBruijnVertex currentVertex, final CountSet pathSizes, final Map<MultiDeBruijnVertex, CountSet> expectedAlternativePathRejoins) {
        final Set<MultiSampleEdge> nextEdges = backwards ? graph.incomingEdgesOf(currentVertex) : graph.outgoingEdgesOf(currentVertex);
        MultiDeBruijnVertex nextReferenceVertex = null;
        for (final MultiSampleEdge e : nextEdges) {
            final MultiDeBruijnVertex nextVertex = backwards ? graph.getEdgeSource(e) : graph.getEdgeTarget(e);
            if (e.isRef())
                nextReferenceVertex = nextVertex;
            else {
                final CountSet pathSizesPlusOne = pathSizes.clone();
                pathSizesPlusOne.incAll(1);
View Full Code Here

TOP

Related Classes of org.broadinstitute.gatk.tools.walkers.haplotypecaller.readthreading.MultiDeBruijnVertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.