export default function calculateTickMarkPositionsForGivenRange({
  tickSpacing: _tickSpacing = 10,
  range,
  sequenceLength,
  isProtein
}) {
  if (sequenceLength === 0) {
    return [];
  }
  let tickSpacing = _tickSpacing;
  if (isProtein) {
    tickSpacing = Math.floor((_tickSpacing / 2) * 3);
  }
  let rangeLength = getRangeLength(range, sequenceLength);

  let firstTickOffsetFromRangeStart;
  if (range.start > range.end) {
    // range spans origin, so make sure the 0 bp is included!
    firstTickOffsetFromRangeStart =
      ((sequenceLength - range.start) % tickSpacing) + 1;
  } else {
    firstTickOffsetFromRangeStart = tickSpacing - (range.start % tickSpacing);
  }
  let tickMarks = [];
  if (range.start === 0) tickMarks.push(isProtein ? 2 : 0);
  for (
    let tick = firstTickOffsetFromRangeStart - 1;
    tick < rangeLength;
    tick += tickSpacing
  ) {
    tickMarks.push(norm(tick, sequenceLength));
  }
  return tickMarks;
}
Example #2
0
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 {
      selectionLayerUpdate({
        start: 0,
        end: sequenceLength - 1
      });
    }
  }
};
Example #3
0
 let sortedAnnotations = sortBy(annotations, function(annotation) {
   return -getRangeLength(annotation);
 });