Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
start: caretPosition,
end: normalizePositionByRangeLength(
nearestCaretPos - 1,
sequenceLength,
true
)
};
let dragStart = {
start: nearestCaretPos,
end: normalizePositionByRangeLength(caretPosition - 1, sequenceLength, true)
};
if (caretPosition === nearestCaretPos) {
return; // do nothing because nearestCaretPos === caretPosition
} else if (
getRangeLength(dragEnd, sequenceLength) <
getRangeLength(dragStart, sequenceLength)
) {
draggingEnd = true; //the caret becomes the "selection end"
selectionLayerUpdate(dragEnd);
caretPositionOnDragStart = null;
} else {
draggingEnd = false; //the caret becomes the "selection end"
selectionLayerUpdate(dragStart);
caretPositionOnDragStart = null;
}
}
export function handleCaretDrag({
export function getSelectionMessage({
caretPosition = -1,
selectionLayer = { start: -1, end: -1 },
customTitle,
sequenceLength,
sequenceData,
showGCContent,
GCDecimalDigits,
isProtein
}) {
let isSelecting = selectionLayer.start > -1;
if (isSelecting) {
let length = getRangeLength(selectionLayer, sequenceLength);
const GCContent = (numDecimalDigits = 0) =>
calculatePercentGC(
getSequenceDataBetweenRange(sequenceData, selectionLayer).sequence
).toFixed(numDecimalDigits);
const seqLen = divideBy3(length, isProtein);
return `${customTitle || "Selecting"} ${seqLen} ${(isProtein
? "AA"
: "bp") + (seqLen === 1 ? "" : "s")} from ${divideBy3(
selectionLayer.start,
isProtein
) + 1} to ${divideBy3(selectionLayer.end + 1, isProtein)}${
showGCContent && !isProtein ? ` (${GCContent(GCDecimalDigits)}% GC)` : ""
}`;
} else if (caretPosition > -1) {
let insertBetween = getInsertBetweenVals(
caretPosition,
const featuresToUse = map(features, feature => {
return {
...feature,
...(feature.strand === undefined && {
strand: feature.forward ? 1 : -1
}),
size: getRangeLength(feature, sequenceLength)
};
});
return (
const orfsToUse = map(orfs, orf => {
return {
...orf,
color: getOrfColor(orf),
frame: orf.frame + 1,
...(orf.strand === undefined && {
strand: orf.forward ? 1 : -1
}),
size: getRangeLength(orf, sequenceLength),
sizeAa: Math.floor(getRangeLength(orf, sequenceLength) / 3)
};
});
return (
export const handleInverse = props => () => {
const {
sequenceLength,
selectionLayer,
caretPosition,
selectionLayerUpdate,
caretPositionUpdate
} = props;
if (sequenceLength <= 0) {
return false;
}
if (selectionLayer.start > -1) {
if (getRangeLength(selectionLayer, sequenceLength) === sequenceLength) {
caretPositionUpdate(selectionLayer.start);
} else {
selectionLayerUpdate(invertRange(selectionLayer, sequenceLength));
}
} else {
if (caretPosition > -1) {
selectionLayerUpdate(
normalizeRange(
{
start: caretPosition,
end: caretPosition - 1
},
sequenceLength
)
);
} else {
function getMinRangeLength(start, end, sequenceLength) {
let range1 = getRangeLength({ start, end }, sequenceLength);
let range2 = getRangeLength({ start: end, end: start }, sequenceLength);
return range1 < range2 ? range1 : range2;
}
function getMinRangeLength(start, end, sequenceLength) {
let range1 = getRangeLength({ start, end }, sequenceLength);
let range2 = getRangeLength({ start: end, end: start }, sequenceLength);
return range1 < range2 ? range1 : range2;
}
selectionLayer
);
let { newRange: range1 } = expandOrContractRangeToPosition(
selectionLayer,
newRange.start,
sequenceLength
);
let { newRange: range2 } = expandOrContractRangeToPosition(
selectionLayer,
newRange.end + 1,
sequenceLength
); //+1 to go from range end to position
let range1Shorter =
getRangeLength(range1, sequenceLength) <
getRangeLength(range2, sequenceLength);
if (newRangeFullyContained) {
range1Shorter
? selectionLayerUpdate(range1)
: selectionLayerUpdate(range2);
} else {
selectionLayerUpdate({
start: selectionLayer.start,
end: newRange.end
});
}
}
} else {
//no caret, no selection, so just do a simple update
simpleUpdate();
}