Skip to content

Commit

Permalink
Merge pull request #273 from Lattice-Automation/crossing-zero-cut-sites
Browse files Browse the repository at this point in the history
Crossing zero cut sites
  • Loading branch information
guzmanvig authored Oct 29, 2024
2 parents 803fc90 + b0457db commit dbca15c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/Circular/CutSites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
48 changes: 42 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,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
Expand All @@ -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,
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 dbca15c

Please sign in to comment.