Skip to content

Commit

Permalink
Adding special case for zero-index crossing
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmanvig committed Sep 25, 2024
1 parent 803fc90 commit 52995ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
40 changes: 34 additions & 6 deletions src/Linear/CutSites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const CutSites = (props: {
// TODO: remove this exclusion of cut-sites that cross the zero index after even more
// zero-index accounting. This file is already hairy enough, so not in a rush to add zero-index
// accounting here, yet.
cutSites.filter(c => c.end > c.start),
cutSites,
firstBase,
lastBase,
findXAndWidth
Expand Down Expand Up @@ -162,9 +162,7 @@ const enhanceCutSites = (
findXAndWidth: FindXAndWidthType
): CutSiteEnhanced[] =>
cutSites.map((c: CutSite) => {
const { x: topX } = findXAndWidth(c.fcut, c.fcut);
const { x: bottomX } = findXAndWidth(c.rcut, c.rcut);


// Prevent double rendering of cut-site lines across SeqBlocks. Without the shenanigans below,
// if a cut site lands on the last or first base of a SeqBlock, it will also render at the end of a SeqBlock
// and the start of the next. Below, we only show a cut if 1. it's wholly within this SeqBlock or
Expand All @@ -184,14 +182,44 @@ const enhanceCutSites = (
showBottomLine = true;
}

// Special case for cut sites that cross the zero index
let enhancedCutSite = c;
if (c.end < c.start) {
// If this is the part of the cut site that is on the last block
if (c.start > firstBase && c.start < lastBase) {
// Use the last base of the block to close the cut site
enhancedCutSite = { ...c, end: lastBase };
//If cuts are on the other block, use the last base as cut instead
if (c.fcut < c.start) {
enhancedCutSite = { ...enhancedCutSite, fcut: lastBase };
}
if (c.rcut < c.start) {
enhancedCutSite = { ...enhancedCutSite, rcut: lastBase };
}
} else {
// This is the part of the cut site that is on the first block, use the first base as the start of the cut site
enhancedCutSite = { ...c, start: firstBase };
// If cuts are on the other block, use the first base as cut instead
if (c.fcut > c.end) {
enhancedCutSite = { ...enhancedCutSite, fcut: firstBase };
}
if (c.rcut > c.end) {
enhancedCutSite = { ...enhancedCutSite, rcut: firstBase };
}
}
}

const { x: topX } = findXAndWidth(enhancedCutSite.fcut, enhancedCutSite.fcut);
const { x: bottomX } = findXAndWidth(enhancedCutSite.rcut, enhancedCutSite.rcut);

return {
bottom: {
render: showBottomLine,
x: bottomX,
},
c,
connector: calcConnector(c, topX, bottomX, firstBase, lastBase, showTopLine, showBottomLine, findXAndWidth),
highlight: calcHighlight(c, firstBase, lastBase, findXAndWidth),
connector: calcConnector(enhancedCutSite, topX, bottomX, firstBase, lastBase, showTopLine, showBottomLine, findXAndWidth),
highlight: calcHighlight(enhancedCutSite, firstBase, lastBase, findXAndWidth),
top: {
render: showTopLine,
x: topX,
Expand Down
11 changes: 1 addition & 10 deletions src/elementsToRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,7 @@ export const createSingleRows = <T extends NameRange>(

// assign each element to its respective array
for (let i = 0; i < elements.length; i += 1) {
let { end, start } = elements[i];

// special case for enzymes that have cut-sites away from recog (BsaI)
// @ts-expect-error this is some hack for cut-sites
if (elements[i].fcut !== undefined) {
// @ts-expect-error this is some hack for cut-sites
const { fcut, rcut } = elements[i];
start = fcut > end || fcut < start ? fcut : start;
end = rcut > end || rcut < start ? rcut : end;
}
const { end, start } = elements[i];

if (start < end) {
let k = Math.floor(start / rowLength);
Expand Down

0 comments on commit 52995ed

Please sign in to comment.