Skip to content

Commit

Permalink
Merge pull request #396 from ducku/issues/395-Reads-Vertical-Transiti…
Browse files Browse the repository at this point in the history
…ons-Out-Of-Order

Fix Out of Order Veritcal Transitions
  • Loading branch information
adamnovak authored Feb 26, 2024
2 parents e23ffed + 3c4707a commit 7b31d04
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/util/tubemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,37 @@ function compareReadIncomingSegmentsByComingFrom(a, b) {
); // neither has y-property
}

// Compare tracks based on ordering at their first convergence
function compareTrackByInitialOrdering(trackA, trackB) {
// Find the first node where the two tracks converge, sort by layer
if (!trackA.hasOwnProperty("path")) return -1;
if (!trackB.hasOwnProperty("path")) return 1;

const pathA = trackA.path;
const pathB = trackB.path;

let AIndex = 0;
let BIndex = 0;
while (AIndex < pathA.length && BIndex < pathB.length) {
let trackAOrder = pathA[AIndex].order;
let trackBOrder = pathB[BIndex].order;
if (trackAOrder === trackBOrder && pathA[AIndex].node && pathB[BIndex].node) {
return pathB[BIndex].y - pathA[AIndex].y;
} else if (trackAOrder < trackBOrder) {
AIndex += 1;
} else if (trackAOrder > trackBOrder) {
BIndex += 1;
} else {
// Orders are equal but are traversing out of nodes
AIndex += 1;
BIndex += 1;
}
}

// Tracks do not converge, keep the same ordering
return 0;
}

// compare 2 reads which are completely within a single node
function compareInternalReads(idxA, idxB) {
const a = reads[idxA];
Expand Down Expand Up @@ -2664,6 +2695,9 @@ function generateSVGShapesFromPath() {
}
});

// Helps generation of verticalRectangles, correct increments of extraRight and extraLeft
tracks.sort(compareTrackByInitialOrdering);

tracks.forEach((track) => {
highlight = "plain";
trackColor = generateTrackColor(track, highlight);
Expand Down Expand Up @@ -2998,6 +3032,8 @@ function createFeatureRectangle(
return { xStart: rectXStart, highlight: currentHighlight };
}



const MIN_BEND_WIDTH = 7;

function generateForwardToReverse(
Expand All @@ -3016,6 +3052,7 @@ function generateForwardToReverse(
const yBottom = Math.max(yStart, yEnd);
const radius = MIN_BEND_WIDTH;


trackVerticalRectangles.push({
// elongate incoming rectangle a bit to the right
xStart: x - 10 * extraRight[order],
Expand Down Expand Up @@ -3049,6 +3086,7 @@ function generateForwardToReverse(
type,
}); // elongate outgoing rectangle a bit to the right


let d = `M ${x + 5} ${yBottom}`;
d += ` Q ${x + 5 + radius} ${yBottom} ${x + 5 + radius} ${yBottom - radius}`;
d += ` H ${x + 5 + radius + Math.min(MIN_BEND_WIDTH, trackWidth)}`;
Expand Down

0 comments on commit 7b31d04

Please sign in to comment.