diff --git a/src/Circular/CutSites.tsx b/src/Circular/CutSites.tsx index 98247916a..e9271971c 100644 --- a/src/Circular/CutSites.tsx +++ b/src/Circular/CutSites.tsx @@ -20,11 +20,9 @@ interface CutSitesProps { } export const CutSites = (props: CutSitesProps) => { - let { cutSites } = props; + const { cutSites } = props; if (!cutSites.length) return null; - cutSites = cutSites.filter(c => c.end > c.start); - const calculateLinePath = (index: number, startRadius: number, endRadius: number): string => { const { findCoor } = props; const lineStart = findCoor(index, startRadius); @@ -55,14 +53,18 @@ const SingleCutSite = (props: { const { id, start } = cutSite; let { end, fcut, rcut } = cutSite; - // crosses the zero index - if (start + fcut > end + rcut) { - end = start > end ? end + seqLength : end; - if (fcut > rcut) { - rcut += seqLength; - } else { + // If any of the end or cut values are greater than the start, it's corssing the zero index + if (start > end || start > fcut || start > rcut) { + // So add the length of the sequence to all values that are crossing the zero index + if (start > end) { + end += seqLength; + } + if (start > fcut) { fcut += seqLength; } + if (start > rcut) { + rcut += seqLength; + } } // length for highlighted recog area diff --git a/src/Linear/CutSites.tsx b/src/Linear/CutSites.tsx index ff06b2187..da729b0fd 100644 --- a/src/Linear/CutSites.tsx +++ b/src/Linear/CutSites.tsx @@ -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 @@ -162,9 +162,6 @@ 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 @@ -184,14 +181,53 @@ 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, diff --git a/src/elementsToRows.ts b/src/elementsToRows.ts index da174573f..5ad36ab22 100644 --- a/src/elementsToRows.ts +++ b/src/elementsToRows.ts @@ -159,16 +159,7 @@ export const createSingleRows = ( // 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);