How to use the ve-range-utils.convertRangeTo0Based function in ve-range-utils

To help you get started, we’ve selected a few ve-range-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TeselaGen / openVectorEditor / demo / src / EditorDemo / AddEditFeatureOverrideExample.js View on Github external
validate: (values, { sequenceLength }) => {
      let errors = {};
      if (
        !isRangeWithinRange(
          convertRangeTo0Based(values, sequenceLength),
          { start: 0, end: sequenceLength - 1 },
          sequenceLength
        )
      ) {
        errors.start = "Range must fit within sequence";
        errors.end = "Range must fit within sequence";
      }

      values.locations &&
        values.locations.length > 1 &&
        values.locations.forEach((loc, index) => {
          // if (!isRangeWithinRange(loc, values, sequenceLength)) {
          //   errors.locations = errors.locations || {};
          //   errors.locations[index] = {
          //     start: "Range must fit within feature",
          //     end: "Range must fit within feature"
github TeselaGen / openVectorEditor / demo / src / EditorDemo / AddEditFeatureOverrideExample.js View on Github external
onClick={handleSubmit(data => {
              let updatedData;
              if (data.forward === true && data.strand !== 1) {
                updatedData = { ...data, strand: 1 };
              } else if (data.forward === false && data.strand !== -1) {
                updatedData = { ...data, strand: -1 };
              } else {
                updatedData = data;
              }
              const hasJoinedLocations =
                updatedData.locations && updatedData.locations.length > 1;

              const newFeat = tidyUpAnnotation(
                convertRangeTo0Based({
                  ...updatedData,
                  locations: undefined, //by default clear locations
                  ...(hasJoinedLocations && {
                    //only add locations if there are locations
                    start: updatedData.locations[0].start, //override the start and end to use the start and end of the joined locations
                    end:
                      updatedData.locations[updatedData.locations.length - 1]
                        .end,
                    locations: updatedData.locations.map(convertRangeTo0Based)
                  })
                }),
                {
                  sequenceData,
                  annotationType: "features"
                }
              );
github TeselaGen / openVectorEditor / src / helperComponents / AddOrEditPrimerDialog / index.js View on Github external
onClick={handleSubmit(data => {
              let updatedData;
              if (data.forward === true && data.strand !== 1) {
                updatedData = { ...data, strand: 1 };
              } else if (data.forward === false && data.strand !== -1) {
                updatedData = { ...data, strand: -1 };
              } else {
                updatedData = data;
              }
              upsertPrimer(convertRangeTo0Based(updatedData));
              hideModal();
            })}
            intent={Intent.PRIMARY}
github TeselaGen / openVectorEditor / src / helperComponents / AddOrEditAnnotationDialog / index.js View on Github external
onClick={handleSubmit(data => {
              let updatedData;
              if (data.forward === true && data.strand !== 1) {
                updatedData = { ...data, strand: 1 };
              } else if (data.forward === false && data.strand !== -1) {
                updatedData = { ...data, strand: -1 };
              } else {
                updatedData = data;
              }
              const hasJoinedLocations =
                updatedData.locations && updatedData.locations.length > 1;

              const newFeat = tidyUpAnnotation(
                convertRangeTo0Based({
                  ...updatedData,
                  ...(annotationTypePlural === "primers" //if we're making a primer it should automatically have a type of primer
                    ? { type: "primer" }
                    : {}),
                  locations: undefined, //by default clear locations
                  ...(hasJoinedLocations && {
                    //only add locations if there are locations
                    start: updatedData.locations[0].start, //override the start and end to use the start and end of the joined locations
                    end:
                      updatedData.locations[updatedData.locations.length - 1]
                        .end,
                    locations: updatedData.locations.map(convertRangeTo0Based)
                  })
                }),
                {
                  sequenceData,
github TeselaGen / openVectorEditor / src / helperComponents / AddOrEditPartDialog / index.js View on Github external
onClick={handleSubmit(data => {
              let updatedData;
              if (data.forward === true && data.strand !== 1) {
                updatedData = { ...data, strand: 1 };
              } else if (data.forward === false && data.strand !== -1) {
                updatedData = { ...data, strand: -1 };
              } else {
                updatedData = data;
              }
              upsertPart(convertRangeTo0Based(updatedData));
              hideModal();
            })}
            intent={Intent.PRIMARY}
github TeselaGen / openVectorEditor / src / helperComponents / AddOrEditAnnotationDialog / index.js View on Github external
validate: (values, { sequenceLength, sequenceData }) => {
        let errors = {};
        const { circular } = sequenceData || {};
        if (!circular && values.start > values.end) {
          errors.start = "Start must be less than End for a linear sequence";
          errors.end = "Start must be less than End for a linear sequence";
        }
        if (
          !isRangeWithinRange(
            convertRangeTo0Based(values, sequenceLength),
            { start: 0, end: sequenceLength - 1 },
            sequenceLength
          )
        ) {
          errors.start = "Range must fit within sequence";
          errors.end = "Range must fit within sequence";
        }
        if (values.locations && values.locations.length > 1) {
          const entireLocationSpan = {
            start: values.locations[0].start,
            end: values.locations[values.locations.length - 1].end
          };
          if (entireLocationSpan.start > entireLocationSpan.end && !circular) {
            errors.locations = errors.locations || {};
            errors.locations[0] = {
              start:
github TeselaGen / openVectorEditor / src / helperComponents / AddOrEditPartDialog / index.js View on Github external
validate: (values, { sequenceLength }) => {
      let errors = {};
      if (
        !isRangeWithinRange(
          convertRangeTo0Based(values, sequenceLength),
          { start: 0, end: sequenceLength - 1 },
          sequenceLength
        )
      ) {
        errors.start = "Range must fit within sequence";
        errors.end = "Range must fit within sequence";
        return errors;
      }
    }
  })
github TeselaGen / openVectorEditor / src / helperComponents / SelectDialog.js View on Github external
updateTempHighlight = ({ isStart, isEnd } = {}) => val => {
      const { selectionLayerUpdate, from, to, invalid } = this.props;
      if (invalid) return;
      selectionLayerUpdate(
        convertRangeTo0Based({
          start: isStart ? Math.round(val) : from,
          end: isEnd ? Math.round(val) : to
        })
      );
    };
    componentDidMount() {
github TeselaGen / openVectorEditor / src / commands / index.js View on Github external
onSubmit: values => {
          const newRange = convertRangeTo0Based({
            start: isProtein(props) ? values.from * 3 : values.from,
            end: isProtein(props) ? values.to * 3 : values.to
          });

          return props.selectionLayerUpdate({
            start: isProtein(props) ? newRange.start - 2 : newRange.start,
            end: newRange.end
          });
        }
      });