@teselagen/sequence-utils 0.3.15 → 0.3.17

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.
package/index.js CHANGED
@@ -12323,6 +12323,20 @@ const modifiableTypes = [
12323
12323
  "primers",
12324
12324
  "guides"
12325
12325
  ];
12326
+ let allWarnings = [];
12327
+ let makeToast = /* @__PURE__ */ __name(() => {
12328
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
12329
+ window.toastr.warning(allWarnings.join("\n"));
12330
+ }
12331
+ allWarnings = [];
12332
+ }, "makeToast");
12333
+ makeToast = lodashExports.debounce(makeToast, 200);
12334
+ function showWarnings(warnings) {
12335
+ allWarnings = allWarnings.concat(warnings);
12336
+ makeToast.cancel();
12337
+ makeToast();
12338
+ }
12339
+ __name(showWarnings, "showWarnings");
12326
12340
  function filterSequenceString(sequenceString = "", {
12327
12341
  additionalValidChars = "",
12328
12342
  isOligo,
@@ -12370,14 +12384,10 @@ function filterSequenceString(sequenceString = "", {
12370
12384
  });
12371
12385
  if (sequenceString.length !== sanitizedVal.length) {
12372
12386
  warnings.push(
12373
- `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
12387
+ `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).slice(0, 100).join(", ")} `
12374
12388
  );
12375
12389
  }
12376
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
12377
- warnings.forEach((warning) => {
12378
- window.toastr.warning(warning);
12379
- });
12380
- }
12390
+ showWarnings(warnings);
12381
12391
  return [sanitizedVal, warnings];
12382
12392
  }
12383
12393
  __name(filterSequenceString, "filterSequenceString");
package/index.mjs CHANGED
@@ -12321,6 +12321,20 @@ const modifiableTypes = [
12321
12321
  "primers",
12322
12322
  "guides"
12323
12323
  ];
12324
+ let allWarnings = [];
12325
+ let makeToast = /* @__PURE__ */ __name(() => {
12326
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
12327
+ window.toastr.warning(allWarnings.join("\n"));
12328
+ }
12329
+ allWarnings = [];
12330
+ }, "makeToast");
12331
+ makeToast = lodashExports.debounce(makeToast, 200);
12332
+ function showWarnings(warnings) {
12333
+ allWarnings = allWarnings.concat(warnings);
12334
+ makeToast.cancel();
12335
+ makeToast();
12336
+ }
12337
+ __name(showWarnings, "showWarnings");
12324
12338
  function filterSequenceString(sequenceString = "", {
12325
12339
  additionalValidChars = "",
12326
12340
  isOligo,
@@ -12368,14 +12382,10 @@ function filterSequenceString(sequenceString = "", {
12368
12382
  });
12369
12383
  if (sequenceString.length !== sanitizedVal.length) {
12370
12384
  warnings.push(
12371
- `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
12385
+ `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).slice(0, 100).join(", ")} `
12372
12386
  );
12373
12387
  }
12374
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
12375
- warnings.forEach((warning) => {
12376
- window.toastr.warning(warning);
12377
- });
12378
- }
12388
+ showWarnings(warnings);
12379
12389
  return [sanitizedVal, warnings];
12380
12390
  }
12381
12391
  __name(filterSequenceString, "filterSequenceString");
package/index.umd.js CHANGED
@@ -12325,6 +12325,20 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
12325
12325
  "primers",
12326
12326
  "guides"
12327
12327
  ];
12328
+ let allWarnings = [];
12329
+ let makeToast = /* @__PURE__ */ __name(() => {
12330
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
12331
+ window.toastr.warning(allWarnings.join("\n"));
12332
+ }
12333
+ allWarnings = [];
12334
+ }, "makeToast");
12335
+ makeToast = lodashExports.debounce(makeToast, 200);
12336
+ function showWarnings(warnings) {
12337
+ allWarnings = allWarnings.concat(warnings);
12338
+ makeToast.cancel();
12339
+ makeToast();
12340
+ }
12341
+ __name(showWarnings, "showWarnings");
12328
12342
  function filterSequenceString(sequenceString = "", {
12329
12343
  additionalValidChars = "",
12330
12344
  isOligo,
@@ -12372,14 +12386,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
12372
12386
  });
12373
12387
  if (sequenceString.length !== sanitizedVal.length) {
12374
12388
  warnings.push(
12375
- `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
12389
+ `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).slice(0, 100).join(", ")} `
12376
12390
  );
12377
12391
  }
12378
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
12379
- warnings.forEach((warning) => {
12380
- window.toastr.warning(warning);
12381
- });
12382
- }
12392
+ showWarnings(warnings);
12383
12393
  return [sanitizedVal, warnings];
12384
12394
  }
12385
12395
  __name(filterSequenceString, "filterSequenceString");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/sequence-utils",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "dependencies": {
5
5
  "@teselagen/range-utils": "0.3.7",
6
6
  "bson-objectid": "^2.0.4",
@@ -1,9 +1,27 @@
1
+ import { debounce, uniq } from "lodash";
1
2
  import {
2
3
  ambiguous_dna_letters,
3
4
  ambiguous_rna_letters,
4
5
  extended_protein_letters
5
6
  } from "./bioData";
6
7
 
8
+ let allWarnings = [];
9
+
10
+ let makeToast = () => {
11
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
12
+ window.toastr.warning(allWarnings.join("\n"));
13
+ }
14
+ allWarnings = [];
15
+ };
16
+
17
+ makeToast = debounce(makeToast, 200);
18
+
19
+ function showWarnings(warnings) {
20
+ allWarnings = allWarnings.concat(warnings);
21
+ makeToast.cancel();
22
+ makeToast();
23
+ }
24
+
7
25
  export default function filterSequenceString(
8
26
  sequenceString = "",
9
27
  {
@@ -62,16 +80,12 @@ export default function filterSequenceString(
62
80
  warnings.push(
63
81
  `${
64
82
  name ? `Sequence ${name}: ` : ""
65
- }Invalid character(s) detected and removed: ${invalidChars
83
+ }Invalid character(s) detected and removed: ${uniq(invalidChars)
66
84
  .slice(0, 100)
67
85
  .join(", ")} `
68
86
  );
69
87
  }
70
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
71
- warnings.forEach(warning => {
72
- window.toastr.warning(warning);
73
- });
74
- }
88
+ showWarnings(warnings);
75
89
 
76
90
  return [sanitizedVal, warnings];
77
91
  }
@@ -85,13 +99,15 @@ export function getAcceptedChars({
85
99
  return isProtein
86
100
  ? `${extended_protein_letters.toLowerCase()}}`
87
101
  : isOligo
88
- ? ambiguous_rna_letters.toLowerCase() + "t"
89
- : isRna
90
- ? ambiguous_rna_letters.toLowerCase() + "t"
91
- : isMixedRnaAndDna
92
- ? ambiguous_rna_letters.toLowerCase() + ambiguous_dna_letters.toLowerCase()
93
- : //just plain old dna
94
- ambiguous_rna_letters.toLowerCase() + ambiguous_dna_letters.toLowerCase();
102
+ ? ambiguous_rna_letters.toLowerCase() + "t"
103
+ : isRna
104
+ ? ambiguous_rna_letters.toLowerCase() + "t"
105
+ : isMixedRnaAndDna
106
+ ? ambiguous_rna_letters.toLowerCase() +
107
+ ambiguous_dna_letters.toLowerCase()
108
+ : //just plain old dna
109
+ ambiguous_rna_letters.toLowerCase() +
110
+ ambiguous_dna_letters.toLowerCase();
95
111
  }
96
112
  export function getReplaceChars({
97
113
  isOligo,
@@ -102,14 +118,14 @@ export function getReplaceChars({
102
118
  return isProtein
103
119
  ? {}
104
120
  : // {".": "*"}
105
- isOligo
106
- ? {}
107
- : isRna
108
- ? { t: "u" }
109
- : isMixedRnaAndDna
110
- ? {}
111
- : //just plain old dna
112
- {};
121
+ isOligo
122
+ ? {}
123
+ : isRna
124
+ ? { t: "u" }
125
+ : isMixedRnaAndDna
126
+ ? {}
127
+ : //just plain old dna
128
+ {};
113
129
  }
114
130
 
115
131
  export const filterRnaString = (s, o) =>
@@ -1,7 +1,7 @@
1
1
  import findSequenceMatches from "./findSequenceMatches";
2
2
 
3
3
  describe("findSequenceMatches", () => {
4
- it('ambiguous protein sequence with asterisk as stop codon', () => {
4
+ it("ambiguous protein sequence with asterisk as stop codon", () => {
5
5
  expect(
6
6
  findSequenceMatches("mmhlrl*", "Mxxlrl*", {
7
7
  isAmbiguous: true,
@@ -29,7 +29,7 @@ describe("findSequenceMatches", () => {
29
29
  }
30
30
  ]);
31
31
  });
32
- it('protein sequence with asterisk as stop codon', () => {
32
+ it("protein sequence with asterisk as stop codon", () => {
33
33
  expect(
34
34
  findSequenceMatches("mmhlrl*", "mMh", {
35
35
  isProteinSequence: true /* isProteinSearch: true */
@@ -132,11 +132,11 @@ describe("findSequenceMatches", () => {
132
132
  const matches = findSequenceMatches("atg", "*", { isAmbiguous: true });
133
133
  expect(matches).toEqual([]);
134
134
  });
135
- it('ambiguous, dna searches with asterisk', () => {
135
+ it("ambiguous, dna searches with asterisk", () => {
136
136
  const matches = findSequenceMatches("atg", "", { isAmbiguous: true });
137
137
  expect(matches).toEqual([]);
138
138
  });
139
- it('AA with asterisk as stop codon in atgtaa', () => {
139
+ it("AA with asterisk as stop codon in atgtaa", () => {
140
140
  expect(
141
141
  findSequenceMatches("atgtaa", "M*", { isProteinSearch: true })
142
142
  ).toEqual([
@@ -146,7 +146,7 @@ describe("findSequenceMatches", () => {
146
146
  }
147
147
  ]);
148
148
  });
149
- it('AA with asterisk as stop codon in atgtaaccc', () => {
149
+ it("AA with asterisk as stop codon in atgtaaccc", () => {
150
150
  expect(
151
151
  findSequenceMatches("atgtaaccc", "M**", { isProteinSearch: true })
152
152
  ).toEqual([]);
@@ -164,7 +164,7 @@ describe("findSequenceMatches", () => {
164
164
  }
165
165
  ]);
166
166
  });
167
- it('works with ambiguous AA with asterisk in search string', () => {
167
+ it("works with ambiguous AA with asterisk in search string", () => {
168
168
  expect(
169
169
  findSequenceMatches("atgtaa", "M*", {
170
170
  isProteinSearch: true,
@@ -1,6 +1,9 @@
1
1
  import getAminoAcidDataForEachBaseOfDna from "./getAminoAcidDataForEachBaseOfDna";
2
2
 
3
- export default function getAminoAcidStringFromSequenceString(sequenceString, { doNotExcludeAsterisk } = {}) {
3
+ export default function getAminoAcidStringFromSequenceString(
4
+ sequenceString,
5
+ { doNotExcludeAsterisk } = {}
6
+ ) {
4
7
  const aminoAcidsPerBase = getAminoAcidDataForEachBaseOfDna(
5
8
  sequenceString,
6
9
  true
@@ -12,7 +15,11 @@ export default function getAminoAcidStringFromSequenceString(sequenceString, { d
12
15
  return;
13
16
  }
14
17
  // Check if the current amino acid is the last in the sequence and is a stop codon
15
- if (!doNotExcludeAsterisk && index >= aminoAcidsPerBase.length - 3 && aa.aminoAcid.value === '*') {
18
+ if (
19
+ !doNotExcludeAsterisk &&
20
+ index >= aminoAcidsPerBase.length - 3 &&
21
+ aa.aminoAcid.value === "*"
22
+ ) {
16
23
  return;
17
24
  }
18
25
  aaArray[aa.aminoAcidIndex] = aa.aminoAcid.value;