@teselagen/sequence-utils 0.3.31 → 0.3.32-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Find approximate matches of a search sequence within a target sequence
3
+ *
4
+ * @param {string} searchSeq - The sequence to search for
5
+ * @param {string} targetSeq - The sequence to search within
6
+ * @param {number} maxMismatches - Maximum number of mismatches allowed
7
+ * @param {boolean} circular - Whether to treat the target sequence as circular (default: false)
8
+ * @returns {Array} - Array of objects containing { index, match, mismatchPositions }
9
+ */
10
+ export default function findApproxMatches(searchSeq: string, targetSeq: string, maxMismatches: number, circular?: boolean): any[];
@@ -0,0 +1 @@
1
+ export {};
@@ -7,5 +7,5 @@ export default function findOrfsInPlasmid(sequence: any, circular: any, minimumO
7
7
  forward: any;
8
8
  annotationTypePlural: string;
9
9
  isOrf: boolean;
10
- id: any;
10
+ id: string;
11
11
  }[];
@@ -16,5 +16,5 @@ export default function getOrfsFromSequence(options: any): {
16
16
  forward: any;
17
17
  annotationTypePlural: string;
18
18
  isOrf: boolean;
19
- id: any;
19
+ id: string;
20
20
  }[];
package/index.cjs CHANGED
@@ -2736,30 +2736,31 @@ function adjustRangeToDeletionOfAnotherRange(rangeToBeAdjusted, anotherRange, ma
2736
2736
  anotherRange,
2737
2737
  maxLength
2738
2738
  );
2739
- if (trimmedRange) {
2740
- const nonCircularDeletionRanges = splitRangeIntoTwoPartsIfItIsCircular(
2741
- anotherRange,
2742
- maxLength
2743
- );
2744
- nonCircularDeletionRanges.forEach(function(nonCircularDeletionRange) {
2745
- const deletionLength = nonCircularDeletionRange.end - nonCircularDeletionRange.start + 1;
2746
- if (trimmedRange.start > trimmedRange.end) {
2747
- if (nonCircularDeletionRange.start < trimmedRange.end) {
2748
- trimmedRange.start -= deletionLength;
2749
- trimmedRange.end -= deletionLength;
2750
- } else if (nonCircularDeletionRange.start < trimmedRange.start) {
2751
- trimmedRange.start -= deletionLength;
2752
- } else ;
2753
- } else {
2754
- if (nonCircularDeletionRange.start < trimmedRange.start) {
2755
- trimmedRange.start -= deletionLength;
2756
- trimmedRange.end -= deletionLength;
2757
- } else if (nonCircularDeletionRange.start < trimmedRange.end) {
2758
- trimmedRange.end -= deletionLength;
2759
- } else ;
2760
- }
2761
- });
2739
+ if (!trimmedRange) {
2740
+ return null;
2762
2741
  }
2742
+ const nonCircularDeletionRanges = splitRangeIntoTwoPartsIfItIsCircular(
2743
+ anotherRange,
2744
+ maxLength
2745
+ );
2746
+ nonCircularDeletionRanges.forEach(function(nonCircularDeletionRange) {
2747
+ const deletionLength = nonCircularDeletionRange.end - nonCircularDeletionRange.start + 1;
2748
+ if (trimmedRange.start > trimmedRange.end) {
2749
+ if (nonCircularDeletionRange.start < trimmedRange.end) {
2750
+ trimmedRange.start -= deletionLength;
2751
+ trimmedRange.end -= deletionLength;
2752
+ } else if (nonCircularDeletionRange.start < trimmedRange.start) {
2753
+ trimmedRange.start -= deletionLength;
2754
+ } else ;
2755
+ } else {
2756
+ if (nonCircularDeletionRange.start < trimmedRange.start) {
2757
+ trimmedRange.start -= deletionLength;
2758
+ trimmedRange.end -= deletionLength;
2759
+ } else if (nonCircularDeletionRange.start < trimmedRange.end) {
2760
+ trimmedRange.end -= deletionLength;
2761
+ } else ;
2762
+ }
2763
+ });
2763
2764
  return trimmedRange;
2764
2765
  }
2765
2766
  __name(adjustRangeToDeletionOfAnotherRange, "adjustRangeToDeletionOfAnotherRange");
@@ -3666,307 +3667,15 @@ const getFeatureToColorMap = /* @__PURE__ */ __name(({ includeHidden } = {}) =>
3666
3667
  const getFeatureTypes = /* @__PURE__ */ __name(({ includeHidden } = {}) => filter(getMergedFeatureMap(), (f) => includeHidden ? true : !f.isHidden).map(
3667
3668
  (f) => f.name
3668
3669
  ), "getFeatureTypes");
3669
- function getDefaultExportFromCjs(x) {
3670
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3671
- }
3672
- __name(getDefaultExportFromCjs, "getDefaultExportFromCjs");
3673
- var lib = { exports: {} };
3674
- var randomFromSeed;
3675
- var hasRequiredRandomFromSeed;
3676
- function requireRandomFromSeed() {
3677
- if (hasRequiredRandomFromSeed) return randomFromSeed;
3678
- hasRequiredRandomFromSeed = 1;
3679
- var seed = 1;
3680
- function getNextValue() {
3681
- seed = (seed * 9301 + 49297) % 233280;
3682
- return seed / 233280;
3683
- }
3684
- __name(getNextValue, "getNextValue");
3685
- function setSeed(_seed_) {
3686
- seed = _seed_;
3687
- }
3688
- __name(setSeed, "setSeed");
3689
- randomFromSeed = {
3690
- nextValue: getNextValue,
3691
- seed: setSeed
3692
- };
3693
- return randomFromSeed;
3694
- }
3695
- __name(requireRandomFromSeed, "requireRandomFromSeed");
3696
- var alphabet_1;
3697
- var hasRequiredAlphabet;
3698
- function requireAlphabet() {
3699
- if (hasRequiredAlphabet) return alphabet_1;
3700
- hasRequiredAlphabet = 1;
3701
- var randomFromSeed2 = requireRandomFromSeed();
3702
- var ORIGINAL = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
3703
- var alphabet;
3704
- var previousSeed;
3705
- var shuffled;
3706
- function reset() {
3707
- shuffled = false;
3708
- }
3709
- __name(reset, "reset");
3710
- function setCharacters(_alphabet_) {
3711
- if (!_alphabet_) {
3712
- if (alphabet !== ORIGINAL) {
3713
- alphabet = ORIGINAL;
3714
- reset();
3715
- }
3716
- return;
3717
- }
3718
- if (_alphabet_ === alphabet) {
3719
- return;
3720
- }
3721
- if (_alphabet_.length !== ORIGINAL.length) {
3722
- throw new Error("Custom alphabet for shortid must be " + ORIGINAL.length + " unique characters. You submitted " + _alphabet_.length + " characters: " + _alphabet_);
3723
- }
3724
- var unique = _alphabet_.split("").filter(function(item, ind, arr) {
3725
- return ind !== arr.lastIndexOf(item);
3726
- });
3727
- if (unique.length) {
3728
- throw new Error("Custom alphabet for shortid must be " + ORIGINAL.length + " unique characters. These characters were not unique: " + unique.join(", "));
3729
- }
3730
- alphabet = _alphabet_;
3731
- reset();
3732
- }
3733
- __name(setCharacters, "setCharacters");
3734
- function characters(_alphabet_) {
3735
- setCharacters(_alphabet_);
3736
- return alphabet;
3737
- }
3738
- __name(characters, "characters");
3739
- function setSeed(seed) {
3740
- randomFromSeed2.seed(seed);
3741
- if (previousSeed !== seed) {
3742
- reset();
3743
- previousSeed = seed;
3744
- }
3745
- }
3746
- __name(setSeed, "setSeed");
3747
- function shuffle() {
3748
- if (!alphabet) {
3749
- setCharacters(ORIGINAL);
3750
- }
3751
- var sourceArray = alphabet.split("");
3752
- var targetArray = [];
3753
- var r = randomFromSeed2.nextValue();
3754
- var characterIndex;
3755
- while (sourceArray.length > 0) {
3756
- r = randomFromSeed2.nextValue();
3757
- characterIndex = Math.floor(r * sourceArray.length);
3758
- targetArray.push(sourceArray.splice(characterIndex, 1)[0]);
3759
- }
3760
- return targetArray.join("");
3761
- }
3762
- __name(shuffle, "shuffle");
3763
- function getShuffled() {
3764
- if (shuffled) {
3765
- return shuffled;
3766
- }
3767
- shuffled = shuffle();
3768
- return shuffled;
3769
- }
3770
- __name(getShuffled, "getShuffled");
3771
- function lookup(index) {
3772
- var alphabetShuffled = getShuffled();
3773
- return alphabetShuffled[index];
3774
- }
3775
- __name(lookup, "lookup");
3776
- function get2() {
3777
- return alphabet || ORIGINAL;
3778
- }
3779
- __name(get2, "get");
3780
- alphabet_1 = {
3781
- get: get2,
3782
- characters,
3783
- seed: setSeed,
3784
- lookup,
3785
- shuffled: getShuffled
3786
- };
3787
- return alphabet_1;
3788
- }
3789
- __name(requireAlphabet, "requireAlphabet");
3790
- var randomByteBrowser;
3791
- var hasRequiredRandomByteBrowser;
3792
- function requireRandomByteBrowser() {
3793
- if (hasRequiredRandomByteBrowser) return randomByteBrowser;
3794
- hasRequiredRandomByteBrowser = 1;
3795
- var crypto = typeof window === "object" && (window.crypto || window.msCrypto);
3796
- var randomByte;
3797
- if (!crypto || !crypto.getRandomValues) {
3798
- randomByte = /* @__PURE__ */ __name(function(size) {
3799
- var bytes = [];
3800
- for (var i = 0; i < size; i++) {
3801
- bytes.push(Math.floor(Math.random() * 256));
3802
- }
3803
- return bytes;
3804
- }, "randomByte");
3805
- } else {
3806
- randomByte = /* @__PURE__ */ __name(function(size) {
3807
- return crypto.getRandomValues(new Uint8Array(size));
3808
- }, "randomByte");
3809
- }
3810
- randomByteBrowser = randomByte;
3811
- return randomByteBrowser;
3812
- }
3813
- __name(requireRandomByteBrowser, "requireRandomByteBrowser");
3814
- var format_browser;
3815
- var hasRequiredFormat_browser;
3816
- function requireFormat_browser() {
3817
- if (hasRequiredFormat_browser) return format_browser;
3818
- hasRequiredFormat_browser = 1;
3819
- format_browser = /* @__PURE__ */ __name(function(random, alphabet, size) {
3820
- var mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1;
3821
- var step = -~(1.6 * mask * size / alphabet.length);
3822
- var id = "";
3823
- while (true) {
3824
- var bytes = random(step);
3825
- var i = step;
3826
- while (i--) {
3827
- id += alphabet[bytes[i] & mask] || "";
3828
- if (id.length === +size) return id;
3829
- }
3830
- }
3831
- }, "format_browser");
3832
- return format_browser;
3833
- }
3834
- __name(requireFormat_browser, "requireFormat_browser");
3835
- var generate_1;
3836
- var hasRequiredGenerate;
3837
- function requireGenerate() {
3838
- if (hasRequiredGenerate) return generate_1;
3839
- hasRequiredGenerate = 1;
3840
- var alphabet = requireAlphabet();
3841
- var random = requireRandomByteBrowser();
3842
- var format = /* @__PURE__ */ requireFormat_browser();
3843
- function generate(number) {
3844
- var loopCounter = 0;
3845
- var done;
3846
- var str = "";
3847
- while (!done) {
3848
- str = str + format(random, alphabet.get(), 1);
3849
- done = number < Math.pow(16, loopCounter + 1);
3850
- loopCounter++;
3851
- }
3852
- return str;
3853
- }
3854
- __name(generate, "generate");
3855
- generate_1 = generate;
3856
- return generate_1;
3857
- }
3858
- __name(requireGenerate, "requireGenerate");
3859
- var build_1;
3860
- var hasRequiredBuild;
3861
- function requireBuild() {
3862
- if (hasRequiredBuild) return build_1;
3863
- hasRequiredBuild = 1;
3864
- var generate = requireGenerate();
3865
- requireAlphabet();
3866
- var REDUCE_TIME = 1567752802062;
3867
- var version = 7;
3868
- var counter;
3869
- var previousSeconds;
3870
- function build(clusterWorkerId) {
3871
- var str = "";
3872
- var seconds = Math.floor((Date.now() - REDUCE_TIME) * 1e-3);
3873
- if (seconds === previousSeconds) {
3874
- counter++;
3875
- } else {
3876
- counter = 0;
3877
- previousSeconds = seconds;
3878
- }
3879
- str = str + generate(version);
3880
- str = str + generate(clusterWorkerId);
3881
- if (counter > 0) {
3882
- str = str + generate(counter);
3883
- }
3884
- str = str + generate(seconds);
3885
- return str;
3886
- }
3887
- __name(build, "build");
3888
- build_1 = build;
3889
- return build_1;
3890
- }
3891
- __name(requireBuild, "requireBuild");
3892
- var isValid;
3893
- var hasRequiredIsValid;
3894
- function requireIsValid() {
3895
- if (hasRequiredIsValid) return isValid;
3896
- hasRequiredIsValid = 1;
3897
- var alphabet = requireAlphabet();
3898
- function isShortId(id) {
3899
- if (!id || typeof id !== "string" || id.length < 6) {
3900
- return false;
3901
- }
3902
- var nonAlphabetic = new RegExp("[^" + alphabet.get().replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&") + "]");
3903
- return !nonAlphabetic.test(id);
3904
- }
3905
- __name(isShortId, "isShortId");
3906
- isValid = isShortId;
3907
- return isValid;
3908
- }
3909
- __name(requireIsValid, "requireIsValid");
3910
- var clusterWorkerIdBrowser;
3911
- var hasRequiredClusterWorkerIdBrowser;
3912
- function requireClusterWorkerIdBrowser() {
3913
- if (hasRequiredClusterWorkerIdBrowser) return clusterWorkerIdBrowser;
3914
- hasRequiredClusterWorkerIdBrowser = 1;
3915
- clusterWorkerIdBrowser = 0;
3916
- return clusterWorkerIdBrowser;
3917
- }
3918
- __name(requireClusterWorkerIdBrowser, "requireClusterWorkerIdBrowser");
3919
- var hasRequiredLib;
3920
- function requireLib() {
3921
- if (hasRequiredLib) return lib.exports;
3922
- hasRequiredLib = 1;
3923
- (function(module2) {
3924
- var alphabet = requireAlphabet();
3925
- var build = requireBuild();
3926
- var isValid2 = requireIsValid();
3927
- var clusterWorkerId = requireClusterWorkerIdBrowser() || 0;
3928
- function seed(seedValue) {
3929
- alphabet.seed(seedValue);
3930
- return module2.exports;
3931
- }
3932
- __name(seed, "seed");
3933
- function worker(workerId) {
3934
- clusterWorkerId = workerId;
3935
- return module2.exports;
3936
- }
3937
- __name(worker, "worker");
3938
- function characters(newCharacters) {
3939
- if (newCharacters !== void 0) {
3940
- alphabet.characters(newCharacters);
3941
- }
3942
- return alphabet.shuffled();
3943
- }
3944
- __name(characters, "characters");
3945
- function generate() {
3946
- return build(clusterWorkerId);
3947
- }
3948
- __name(generate, "generate");
3949
- module2.exports = generate;
3950
- module2.exports.generate = generate;
3951
- module2.exports.seed = seed;
3952
- module2.exports.worker = worker;
3953
- module2.exports.characters = characters;
3954
- module2.exports.isValid = isValid2;
3955
- })(lib);
3956
- return lib.exports;
3957
- }
3958
- __name(requireLib, "requireLib");
3959
- var shortid$1;
3960
- var hasRequiredShortid;
3961
- function requireShortid() {
3962
- if (hasRequiredShortid) return shortid$1;
3963
- hasRequiredShortid = 1;
3964
- shortid$1 = requireLib();
3965
- return shortid$1;
3966
- }
3967
- __name(requireShortid, "requireShortid");
3968
- var shortidExports = requireShortid();
3969
- const shortid = /* @__PURE__ */ getDefaultExportFromCjs(shortidExports);
3670
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3671
+ let nanoid = /* @__PURE__ */ __name((size = 21) => {
3672
+ let id = "";
3673
+ let bytes = crypto.getRandomValues(new Uint8Array(size |= 0));
3674
+ while (size--) {
3675
+ id += urlAlphabet[bytes[size] & 63];
3676
+ }
3677
+ return id;
3678
+ }, "nanoid");
3970
3679
  function cutSequenceByRestrictionEnzyme(pSequence, circular, restrictionEnzyme) {
3971
3680
  if (restrictionEnzyme.forwardRegex.length === 0 || restrictionEnzyme.reverseRegex.length === 0) {
3972
3681
  const returnArray = [];
@@ -4174,7 +3883,7 @@ function cutSequence(forwardRegExpPattern, restrictionEnzyme, sequence, circular
4174
3883
  }
4175
3884
  const overhangBps = getSequenceWithinRange(cutRange, originalSequence);
4176
3885
  restrictionCutSite = {
4177
- id: shortid(),
3886
+ id: nanoid(),
4178
3887
  start,
4179
3888
  end,
4180
3889
  topSnipPosition,
@@ -4232,7 +3941,7 @@ function computeDigestFragments({
4232
3941
  });
4233
3942
  if (!circular && cutsites.length) {
4234
3943
  sortedCutsites.push({
4235
- id: "seqTerm_" + shortid(),
3944
+ id: "seqTerm_" + nanoid(),
4236
3945
  start: 0,
4237
3946
  end: 0,
4238
3947
  overhangBps: "",
@@ -4366,6 +4075,10 @@ function getDigestFragsForSeqAndEnzymes({
4366
4075
  });
4367
4076
  }
4368
4077
  __name(getDigestFragsForSeqAndEnzymes, "getDigestFragsForSeqAndEnzymes");
4078
+ function getDefaultExportFromCjs(x) {
4079
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4080
+ }
4081
+ __name(getDefaultExportFromCjs, "getDefaultExportFromCjs");
4369
4082
  var jsondiffpatch_umd$1 = { exports: {} };
4370
4083
  var empty = {};
4371
4084
  var hasRequiredEmpty;
@@ -8964,10 +8677,10 @@ function tidyUpAnnotation(_annotation, {
8964
8677
  annotation.name = "Untitled annotation";
8965
8678
  }
8966
8679
  if (provideNewIdsForAnnotations) {
8967
- annotation.id = shortid();
8680
+ annotation.id = nanoid();
8968
8681
  }
8969
8682
  if (!annotation.id && annotation.id !== 0 && !doNotProvideIdsForAnnotations) {
8970
- annotation.id = shortid();
8683
+ annotation.id = nanoid();
8971
8684
  messages.push(
8972
8685
  "Unable to detect valid ID for annotation, setting ID to " + annotation.id
8973
8686
  );
@@ -9211,7 +8924,7 @@ function tidyUpSequenceData(pSeqData, options = {}) {
9211
8924
  if (item.id || item.id === 0) {
9212
8925
  itemId = item.id;
9213
8926
  } else {
9214
- itemId = shortid();
8927
+ itemId = nanoid();
9215
8928
  if (!doNotProvideIdsForAnnotations) {
9216
8929
  item.id = itemId;
9217
8930
  }
@@ -9514,6 +9227,36 @@ function insertGapsIntoRefSeq(refSeq, seqReads) {
9514
9227
  return refSeqWithGaps.join("");
9515
9228
  }
9516
9229
  __name(insertGapsIntoRefSeq, "insertGapsIntoRefSeq");
9230
+ function findApproxMatches(searchSeq, targetSeq, maxMismatches, circular = false) {
9231
+ const matches = [];
9232
+ const lenA = searchSeq.length;
9233
+ const lenB = targetSeq.length;
9234
+ const targetSeqExtended = circular ? targetSeq + targetSeq.slice(0, lenA - 1) : targetSeq;
9235
+ const limit = circular ? lenB : lenB - lenA + 1;
9236
+ for (let i = 0; i < limit; i++) {
9237
+ const window2 = targetSeqExtended.slice(i, i + lenA);
9238
+ let mismatchCount = 0;
9239
+ const mismatchPositions = [];
9240
+ for (let j = 0; j < lenA; j++) {
9241
+ if (searchSeq[j] !== window2[j]) {
9242
+ mismatchPositions.push(j);
9243
+ mismatchCount++;
9244
+ if (mismatchCount > maxMismatches) break;
9245
+ }
9246
+ }
9247
+ if (mismatchCount <= maxMismatches) {
9248
+ matches.push({
9249
+ index: i,
9250
+ match: window2,
9251
+ mismatchPositions,
9252
+ numMismatches: mismatchPositions.length
9253
+ // Keep for backwards compatibility
9254
+ });
9255
+ }
9256
+ }
9257
+ return matches;
9258
+ }
9259
+ __name(findApproxMatches, "findApproxMatches");
9517
9260
  var spliceString$1;
9518
9261
  var hasRequiredSpliceString;
9519
9262
  function requireSpliceString() {
@@ -17751,7 +17494,7 @@ function generateAnnotation(start, end, maxLength) {
17751
17494
  return __spreadProps(__spreadValues({}, range), {
17752
17495
  name: getRandomInt(0, 1e5).toString(),
17753
17496
  type: "misc_feature",
17754
- id: shortid(),
17497
+ id: nanoid(),
17755
17498
  forward: Math.random() > 0.5,
17756
17499
  notes: {}
17757
17500
  });
@@ -17874,7 +17617,7 @@ function getOrfsFromSequence(options) {
17874
17617
  forward,
17875
17618
  annotationTypePlural: "orfs",
17876
17619
  isOrf: true,
17877
- id: shortid()
17620
+ id: nanoid()
17878
17621
  });
17879
17622
  }
17880
17623
  }
@@ -19322,6 +19065,7 @@ exports.doesEnzymeChopOutsideOfRecognitionSite = doesEnzymeChopOutsideOfRecognit
19322
19065
  exports.featureColors = featureColors;
19323
19066
  exports.filterRnaString = filterRnaString;
19324
19067
  exports.filterSequenceString = filterSequenceString;
19068
+ exports.findApproxMatches = findApproxMatches;
19325
19069
  exports.findNearestRangeOfSequenceOverlapToPosition = findNearestRangeOfSequenceOverlapToPosition;
19326
19070
  exports.findOrfsInPlasmid = findOrfsInPlasmid;
19327
19071
  exports.findSequenceMatches = findSequenceMatches;
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { default as getDegenerateRnaStringFromAAString } from './getDegenerateRn
11
11
  export { default as getVirtualDigest } from './getVirtualDigest';
12
12
  export { default as isEnzymeType2S } from './isEnzymeType2S';
13
13
  export { default as insertGapsIntoRefSeq } from './insertGapsIntoRefSeq';
14
+ export { default as findApproxMatches } from './findApproxMatches';
14
15
  export { default as adjustBpsToReplaceOrInsert } from './adjustBpsToReplaceOrInsert';
15
16
  export { default as calculatePercentGC } from './calculatePercentGC';
16
17
  export { default as calculateTm } from './calculateTm';