@teselagen/bio-parsers 0.4.9 → 0.4.11

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.
@@ -1,3 +1,3 @@
1
- export function parseFeatureLocation(locStr: any, isProtein: any, inclusive1BasedStart: any, inclusive1BasedEnd: any): any[];
1
+ export function parseFeatureLocation(locStr: any, isProtein: any, inclusive1BasedStart: any, inclusive1BasedEnd: any, isCircular: any, sequenceLength: any): any[];
2
2
  export default genbankToJson;
3
3
  declare function genbankToJson(string: any, options?: {}): any;
package/index.js CHANGED
@@ -993,7 +993,7 @@ lodash.exports;
993
993
  return new LodashWrapper(value);
994
994
  }
995
995
  __name(lodash2, "lodash");
996
- var baseCreate = function() {
996
+ var baseCreate = /* @__PURE__ */ function() {
997
997
  function object() {
998
998
  }
999
999
  __name(object, "object");
@@ -4618,7 +4618,7 @@ lodash.exports;
4618
4618
  var gte = createRelationalOperation(function(value, other) {
4619
4619
  return value >= other;
4620
4620
  });
4621
- var isArguments = baseIsArguments(function() {
4621
+ var isArguments = baseIsArguments(/* @__PURE__ */ function() {
4622
4622
  return arguments;
4623
4623
  }()) ? baseIsArguments : function(value) {
4624
4624
  return isObjectLike(value) && hasOwnProperty2.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
@@ -6169,7 +6169,7 @@ lodash.exports;
6169
6169
  }).call(commonjsGlobal);
6170
6170
  })(lodash, lodash.exports);
6171
6171
  var lodashExports = lodash.exports;
6172
- const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO";
6172
+ const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO*";
6173
6173
  const ambiguous_dna_letters = "GATCRYWSMKHBVDN";
6174
6174
  const ambiguous_rna_letters = "GAUCRYWSMKHBVDN";
6175
6175
  const aminoAcidToDegenerateDnaMap = {
@@ -6884,7 +6884,7 @@ __name(requireEmpty, "requireEmpty");
6884
6884
  throw new TypeError("Cannot call a class as a function");
6885
6885
  }
6886
6886
  }, "classCallCheck");
6887
- var createClass = function() {
6887
+ var createClass = /* @__PURE__ */ function() {
6888
6888
  function defineProperties(target, props) {
6889
6889
  for (var i = 0; i < props.length; i++) {
6890
6890
  var descriptor = props[i];
@@ -6946,7 +6946,7 @@ __name(requireEmpty, "requireEmpty");
6946
6946
  }
6947
6947
  return call && (typeof call === "object" || typeof call === "function") ? call : self2;
6948
6948
  }, "possibleConstructorReturn");
6949
- var slicedToArray = function() {
6949
+ var slicedToArray = /* @__PURE__ */ function() {
6950
6950
  function sliceIterator(arr, i) {
6951
6951
  var _arr = [];
6952
6952
  var _n = true;
@@ -11274,6 +11274,20 @@ const annotationTypes = [
11274
11274
  "primers",
11275
11275
  "guides"
11276
11276
  ];
11277
+ let allWarnings = [];
11278
+ let makeToast = /* @__PURE__ */ __name(() => {
11279
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
11280
+ window.toastr.warning(lodashExports.uniq(allWarnings).join("\n"));
11281
+ }
11282
+ allWarnings = [];
11283
+ }, "makeToast");
11284
+ makeToast = lodashExports.debounce(makeToast, 200);
11285
+ function showWarnings(warnings) {
11286
+ allWarnings = allWarnings.concat(warnings);
11287
+ makeToast.cancel();
11288
+ makeToast();
11289
+ }
11290
+ __name(showWarnings, "showWarnings");
11277
11291
  function filterSequenceString(sequenceString = "", {
11278
11292
  additionalValidChars = "",
11279
11293
  isOligo,
@@ -11321,14 +11335,15 @@ function filterSequenceString(sequenceString = "", {
11321
11335
  });
11322
11336
  if (sequenceString.length !== sanitizedVal.length) {
11323
11337
  warnings.push(
11324
- `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
11338
+ `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).map((c) => {
11339
+ if (c === " ") {
11340
+ return "space";
11341
+ }
11342
+ return c;
11343
+ }).slice(0, 100).join(", ")} `
11325
11344
  );
11326
11345
  }
11327
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
11328
- warnings.forEach((warning) => {
11329
- window.toastr.warning(warning);
11330
- });
11331
- }
11346
+ showWarnings(warnings);
11332
11347
  return [sanitizedVal, warnings];
11333
11348
  }
11334
11349
  __name(filterSequenceString, "filterSequenceString");
@@ -11668,12 +11683,12 @@ const calcTmMethods = {
11668
11683
  // Monovalent salt concentration. 50mM is typical for PCR.
11669
11684
  /**
11670
11685
  * Calculates temperature for DNA sequence using a given algorithm.
11671
- * @param {String} sequence The DNA sequence to use.
11672
- * @param {String} type Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11673
- * @param {Double} A Helix initation for deltaS. Defaults to -10.8.
11674
- * @param {Double} R The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11675
- * @param {Double} Na THe monovalent salt concentration. Defaults to 50e-3M.
11676
- * @return {Double} Temperature for the given sequence, in Celsius.
11686
+ * sequence - The DNA sequence to use.
11687
+ * type - Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11688
+ * A - Helix initation for deltaS. Defaults to -10.8.
11689
+ * R - The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11690
+ * Na - THe monovalent salt concentration. Defaults to 50e-3M.
11691
+ * return - Temperature for the given sequence, in Celsius.
11677
11692
  */
11678
11693
  calculateTemperature: function(sequence, type, A, R, C, Na) {
11679
11694
  if (typeof type === "undefined") {
@@ -19772,7 +19787,7 @@ function flattenSequenceArray(parsingResultArray, opts) {
19772
19787
  return parsingResultArray;
19773
19788
  }
19774
19789
  __name(flattenSequenceArray, "flattenSequenceArray");
19775
- function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd) {
19790
+ function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd, isCircular, sequenceLength) {
19776
19791
  locStr = locStr.trim();
19777
19792
  const locArr = [];
19778
19793
  locStr.replace(/(\d+)/g, function(string, match) {
@@ -19793,6 +19808,19 @@ function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive
19793
19808
  isProtein ? convertAACaretPositionOrRangeToDna(location) : location
19794
19809
  );
19795
19810
  }
19811
+ if (isCircular) {
19812
+ for (let i = 0; i < locArray.length; i += 2) {
19813
+ const firstFeature = locArray[i];
19814
+ const secondFeature = locArray[i + 1];
19815
+ if (firstFeature.end === sequenceLength - (inclusive1BasedEnd ? 0 : 1) && secondFeature.start === 1 - (inclusive1BasedStart ? 0 : 1)) {
19816
+ locArray[i] = {
19817
+ start: firstFeature.start,
19818
+ end: secondFeature.end
19819
+ };
19820
+ locArray.splice(i + 1, 1);
19821
+ }
19822
+ }
19823
+ }
19796
19824
  return locArray;
19797
19825
  }
19798
19826
  __name(parseFeatureLocation, "parseFeatureLocation");
@@ -20126,7 +20154,9 @@ function genbankToJson(string, options = {}) {
20126
20154
  line.trim(),
20127
20155
  options.isProtein,
20128
20156
  inclusive1BasedStart,
20129
- inclusive1BasedEnd
20157
+ inclusive1BasedEnd,
20158
+ result.parsedSequence.circular,
20159
+ result.parsedSequence.sequence.length
20130
20160
  )
20131
20161
  );
20132
20162
  lastLineWasLocation = true;
@@ -20159,7 +20189,9 @@ function genbankToJson(string, options = {}) {
20159
20189
  val2,
20160
20190
  options.isProtein,
20161
20191
  inclusive1BasedStart,
20162
- inclusive1BasedEnd
20192
+ inclusive1BasedEnd,
20193
+ result.parsedSequence.circular,
20194
+ result.parsedSequence.sequence.length
20163
20195
  )
20164
20196
  );
20165
20197
  lastLineWasLocation = true;
@@ -21047,7 +21079,6 @@ const util$1 = util$4;
21047
21079
  const xmlNode = xmlNode$1;
21048
21080
  const readDocType = DocTypeReader;
21049
21081
  const toNumber = strnum;
21050
- "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util$1.nameRegexp);
21051
21082
  let OrderedObjParser$1 = (_a = class {
21052
21083
  constructor(options) {
21053
21084
  this.options = options;
@@ -21261,18 +21292,19 @@ const parseXml = /* @__PURE__ */ __name(function(xmlData) {
21261
21292
  const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
21262
21293
  const tagExp = xmlData.substring(i + 9, closeIndex);
21263
21294
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
21295
+ let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
21296
+ if (val2 == void 0)
21297
+ val2 = "";
21264
21298
  if (this.options.cdataPropName) {
21265
21299
  currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
21266
21300
  } else {
21267
- let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
21268
- if (val2 == void 0)
21269
- val2 = "";
21270
21301
  currentNode.add(this.options.textNodeName, val2);
21271
21302
  }
21272
21303
  i = closeIndex + 2;
21273
21304
  } else {
21274
21305
  let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
21275
21306
  let tagName = result.tagName;
21307
+ const rawTagName = result.rawTagName;
21276
21308
  let tagExp = result.tagExp;
21277
21309
  let attrExpPresent = result.attrExpPresent;
21278
21310
  let closeIndex = result.closeIndex;
@@ -21299,9 +21331,9 @@ const parseXml = /* @__PURE__ */ __name(function(xmlData) {
21299
21331
  } else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
21300
21332
  i = result.closeIndex;
21301
21333
  } else {
21302
- const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
21334
+ const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
21303
21335
  if (!result2)
21304
- throw new Error(`Unexpected end of ${tagName}`);
21336
+ throw new Error(`Unexpected end of ${rawTagName}`);
21305
21337
  i = result2.i;
21306
21338
  tagContent = result2.tagContent;
21307
21339
  }
@@ -21463,9 +21495,10 @@ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
21463
21495
  let tagName = tagExp;
21464
21496
  let attrExpPresent = true;
21465
21497
  if (separatorIndex !== -1) {
21466
- tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
21467
- tagExp = tagExp.substr(separatorIndex + 1);
21498
+ tagName = tagExp.substring(0, separatorIndex);
21499
+ tagExp = tagExp.substring(separatorIndex + 1).trimStart();
21468
21500
  }
21501
+ const rawTagName = tagName;
21469
21502
  if (removeNSPrefix) {
21470
21503
  const colonIndex = tagName.indexOf(":");
21471
21504
  if (colonIndex !== -1) {
@@ -21477,7 +21510,8 @@ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
21477
21510
  tagName,
21478
21511
  tagExp,
21479
21512
  closeIndex,
21480
- attrExpPresent
21513
+ attrExpPresent,
21514
+ rawTagName
21481
21515
  };
21482
21516
  }
21483
21517
  __name(readTagExp, "readTagExp");
@@ -21707,6 +21741,8 @@ function arrToStr(arr, options, jPath, indentation) {
21707
21741
  for (let i = 0; i < arr.length; i++) {
21708
21742
  const tagObj = arr[i];
21709
21743
  const tagName = propName(tagObj);
21744
+ if (tagName === void 0)
21745
+ continue;
21710
21746
  let newJPath = "";
21711
21747
  if (jPath.length === 0)
21712
21748
  newJPath = tagName;
@@ -21778,6 +21814,8 @@ function propName(obj) {
21778
21814
  const keys = Object.keys(obj);
21779
21815
  for (let i = 0; i < keys.length; i++) {
21780
21816
  const key = keys[i];
21817
+ if (!obj.hasOwnProperty(key))
21818
+ continue;
21781
21819
  if (key !== ":@")
21782
21820
  return key;
21783
21821
  }
@@ -21787,6 +21825,8 @@ function attr_to_str(attrMap, options) {
21787
21825
  let attrStr = "";
21788
21826
  if (attrMap && !options.ignoreAttributes) {
21789
21827
  for (let attr in attrMap) {
21828
+ if (!attrMap.hasOwnProperty(attr))
21829
+ continue;
21790
21830
  let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
21791
21831
  attrVal = replaceEntitiesValue(attrVal, options);
21792
21832
  if (attrVal === true && options.suppressBooleanAttributes) {
@@ -21895,6 +21935,8 @@ Builder.prototype.j2x = function(jObj, level) {
21895
21935
  let attrStr = "";
21896
21936
  let val2 = "";
21897
21937
  for (let key in jObj) {
21938
+ if (!Object.prototype.hasOwnProperty.call(jObj, key))
21939
+ continue;
21898
21940
  if (typeof jObj[key] === "undefined") {
21899
21941
  if (this.isAttribute(key)) {
21900
21942
  val2 += "";
@@ -30334,9 +30376,7 @@ var slc = /* @__PURE__ */ __name(function(v, s, e) {
30334
30376
  s = 0;
30335
30377
  if (e == null || e > v.length)
30336
30378
  e = v.length;
30337
- var n = new u8(e - s);
30338
- n.set(v.subarray(s, e));
30339
- return n;
30379
+ return new u8(v.subarray(s, e));
30340
30380
  }, "slc");
30341
30381
  var ec = [
30342
30382
  "unexpected EOF",
@@ -30368,9 +30408,10 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30368
30408
  var sl = dat.length, dl = dict ? dict.length : 0;
30369
30409
  if (!sl || st.f && !st.l)
30370
30410
  return buf || new u8(0);
30371
- var noBuf = !buf || st.i != 2;
30411
+ var noBuf = !buf;
30412
+ var resize = noBuf || st.i != 2;
30372
30413
  var noSt = st.i;
30373
- if (!buf)
30414
+ if (noBuf)
30374
30415
  buf = new u8(sl * 3);
30375
30416
  var cbuf = /* @__PURE__ */ __name(function(l2) {
30376
30417
  var bl = buf.length;
@@ -30394,7 +30435,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30394
30435
  err(0);
30395
30436
  break;
30396
30437
  }
30397
- if (noBuf)
30438
+ if (resize)
30398
30439
  cbuf(bt + l);
30399
30440
  buf.set(dat.subarray(s, t), bt);
30400
30441
  st.b = bt += l, st.p = pos = t * 8, st.f = final;
@@ -30444,7 +30485,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30444
30485
  break;
30445
30486
  }
30446
30487
  }
30447
- if (noBuf)
30488
+ if (resize)
30448
30489
  cbuf(bt + 131072);
30449
30490
  var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
30450
30491
  var lpos = pos;
@@ -30484,7 +30525,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30484
30525
  err(0);
30485
30526
  break;
30486
30527
  }
30487
- if (noBuf)
30528
+ if (resize)
30488
30529
  cbuf(bt + 131072);
30489
30530
  var end = bt + add;
30490
30531
  if (bt < dt) {
@@ -30494,20 +30535,15 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30494
30535
  for (; bt < dend; ++bt)
30495
30536
  buf[bt] = dict[shift + bt];
30496
30537
  }
30497
- for (; bt < end; bt += 4) {
30538
+ for (; bt < end; ++bt)
30498
30539
  buf[bt] = buf[bt - dt];
30499
- buf[bt + 1] = buf[bt + 1 - dt];
30500
- buf[bt + 2] = buf[bt + 2 - dt];
30501
- buf[bt + 3] = buf[bt + 3 - dt];
30502
- }
30503
- bt = end;
30504
30540
  }
30505
30541
  }
30506
30542
  st.l = lm, st.p = lpos, st.b = bt, st.f = final;
30507
30543
  if (lm)
30508
30544
  final = 1, st.m = lbt, st.d = dm, st.n = dbt;
30509
30545
  } while (!final);
30510
- return bt == buf.length ? buf : slc(buf, 0, bt);
30546
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
30511
30547
  }, "inflt");
30512
30548
  var et = /* @__PURE__ */ new u8(0);
30513
30549
  var b2 = /* @__PURE__ */ __name(function(d, b) {
@@ -32671,13 +32707,12 @@ function jsonToFasta(jsonSequence, options) {
32671
32707
  proteinSize,
32672
32708
  proteinSequence
32673
32709
  } = cleanedData;
32674
- options = options || {};
32675
- let seqToUse = sequence;
32676
- let sizeToUse = size;
32677
- if (isProtein && proteinSequence) {
32678
- seqToUse = proteinSequence;
32679
- sizeToUse = proteinSize;
32680
- }
32710
+ options = __spreadValues({
32711
+ sequence: isProtein && proteinSequence ? proteinSequence : sequence,
32712
+ size: isProtein && proteinSequence ? proteinSize : size
32713
+ }, options);
32714
+ const seqToUse = options.sequence;
32715
+ const sizeToUse = options.size;
32681
32716
  let fastaString = "";
32682
32717
  fastaString += `>${name || "Untitled Sequence"}|`;
32683
32718
  fastaString += "|" + sizeToUse;
package/index.mjs CHANGED
@@ -991,7 +991,7 @@ lodash.exports;
991
991
  return new LodashWrapper(value);
992
992
  }
993
993
  __name(lodash2, "lodash");
994
- var baseCreate = function() {
994
+ var baseCreate = /* @__PURE__ */ function() {
995
995
  function object() {
996
996
  }
997
997
  __name(object, "object");
@@ -4616,7 +4616,7 @@ lodash.exports;
4616
4616
  var gte = createRelationalOperation(function(value, other) {
4617
4617
  return value >= other;
4618
4618
  });
4619
- var isArguments = baseIsArguments(function() {
4619
+ var isArguments = baseIsArguments(/* @__PURE__ */ function() {
4620
4620
  return arguments;
4621
4621
  }()) ? baseIsArguments : function(value) {
4622
4622
  return isObjectLike(value) && hasOwnProperty2.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
@@ -6167,7 +6167,7 @@ lodash.exports;
6167
6167
  }).call(commonjsGlobal);
6168
6168
  })(lodash, lodash.exports);
6169
6169
  var lodashExports = lodash.exports;
6170
- const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO";
6170
+ const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO*";
6171
6171
  const ambiguous_dna_letters = "GATCRYWSMKHBVDN";
6172
6172
  const ambiguous_rna_letters = "GAUCRYWSMKHBVDN";
6173
6173
  const aminoAcidToDegenerateDnaMap = {
@@ -6882,7 +6882,7 @@ __name(requireEmpty, "requireEmpty");
6882
6882
  throw new TypeError("Cannot call a class as a function");
6883
6883
  }
6884
6884
  }, "classCallCheck");
6885
- var createClass = function() {
6885
+ var createClass = /* @__PURE__ */ function() {
6886
6886
  function defineProperties(target, props) {
6887
6887
  for (var i = 0; i < props.length; i++) {
6888
6888
  var descriptor = props[i];
@@ -6944,7 +6944,7 @@ __name(requireEmpty, "requireEmpty");
6944
6944
  }
6945
6945
  return call && (typeof call === "object" || typeof call === "function") ? call : self2;
6946
6946
  }, "possibleConstructorReturn");
6947
- var slicedToArray = function() {
6947
+ var slicedToArray = /* @__PURE__ */ function() {
6948
6948
  function sliceIterator(arr, i) {
6949
6949
  var _arr = [];
6950
6950
  var _n = true;
@@ -11272,6 +11272,20 @@ const annotationTypes = [
11272
11272
  "primers",
11273
11273
  "guides"
11274
11274
  ];
11275
+ let allWarnings = [];
11276
+ let makeToast = /* @__PURE__ */ __name(() => {
11277
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
11278
+ window.toastr.warning(lodashExports.uniq(allWarnings).join("\n"));
11279
+ }
11280
+ allWarnings = [];
11281
+ }, "makeToast");
11282
+ makeToast = lodashExports.debounce(makeToast, 200);
11283
+ function showWarnings(warnings) {
11284
+ allWarnings = allWarnings.concat(warnings);
11285
+ makeToast.cancel();
11286
+ makeToast();
11287
+ }
11288
+ __name(showWarnings, "showWarnings");
11275
11289
  function filterSequenceString(sequenceString = "", {
11276
11290
  additionalValidChars = "",
11277
11291
  isOligo,
@@ -11319,14 +11333,15 @@ function filterSequenceString(sequenceString = "", {
11319
11333
  });
11320
11334
  if (sequenceString.length !== sanitizedVal.length) {
11321
11335
  warnings.push(
11322
- `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
11336
+ `${name ? `Sequence ${name}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).map((c) => {
11337
+ if (c === " ") {
11338
+ return "space";
11339
+ }
11340
+ return c;
11341
+ }).slice(0, 100).join(", ")} `
11323
11342
  );
11324
11343
  }
11325
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
11326
- warnings.forEach((warning) => {
11327
- window.toastr.warning(warning);
11328
- });
11329
- }
11344
+ showWarnings(warnings);
11330
11345
  return [sanitizedVal, warnings];
11331
11346
  }
11332
11347
  __name(filterSequenceString, "filterSequenceString");
@@ -11666,12 +11681,12 @@ const calcTmMethods = {
11666
11681
  // Monovalent salt concentration. 50mM is typical for PCR.
11667
11682
  /**
11668
11683
  * Calculates temperature for DNA sequence using a given algorithm.
11669
- * @param {String} sequence The DNA sequence to use.
11670
- * @param {String} type Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11671
- * @param {Double} A Helix initation for deltaS. Defaults to -10.8.
11672
- * @param {Double} R The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11673
- * @param {Double} Na THe monovalent salt concentration. Defaults to 50e-3M.
11674
- * @return {Double} Temperature for the given sequence, in Celsius.
11684
+ * sequence - The DNA sequence to use.
11685
+ * type - Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11686
+ * A - Helix initation for deltaS. Defaults to -10.8.
11687
+ * R - The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11688
+ * Na - THe monovalent salt concentration. Defaults to 50e-3M.
11689
+ * return - Temperature for the given sequence, in Celsius.
11675
11690
  */
11676
11691
  calculateTemperature: function(sequence, type, A, R, C, Na) {
11677
11692
  if (typeof type === "undefined") {
@@ -19770,7 +19785,7 @@ function flattenSequenceArray(parsingResultArray, opts) {
19770
19785
  return parsingResultArray;
19771
19786
  }
19772
19787
  __name(flattenSequenceArray, "flattenSequenceArray");
19773
- function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd) {
19788
+ function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd, isCircular, sequenceLength) {
19774
19789
  locStr = locStr.trim();
19775
19790
  const locArr = [];
19776
19791
  locStr.replace(/(\d+)/g, function(string, match) {
@@ -19791,6 +19806,19 @@ function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive
19791
19806
  isProtein ? convertAACaretPositionOrRangeToDna(location) : location
19792
19807
  );
19793
19808
  }
19809
+ if (isCircular) {
19810
+ for (let i = 0; i < locArray.length; i += 2) {
19811
+ const firstFeature = locArray[i];
19812
+ const secondFeature = locArray[i + 1];
19813
+ if (firstFeature.end === sequenceLength - (inclusive1BasedEnd ? 0 : 1) && secondFeature.start === 1 - (inclusive1BasedStart ? 0 : 1)) {
19814
+ locArray[i] = {
19815
+ start: firstFeature.start,
19816
+ end: secondFeature.end
19817
+ };
19818
+ locArray.splice(i + 1, 1);
19819
+ }
19820
+ }
19821
+ }
19794
19822
  return locArray;
19795
19823
  }
19796
19824
  __name(parseFeatureLocation, "parseFeatureLocation");
@@ -20124,7 +20152,9 @@ function genbankToJson(string, options = {}) {
20124
20152
  line.trim(),
20125
20153
  options.isProtein,
20126
20154
  inclusive1BasedStart,
20127
- inclusive1BasedEnd
20155
+ inclusive1BasedEnd,
20156
+ result.parsedSequence.circular,
20157
+ result.parsedSequence.sequence.length
20128
20158
  )
20129
20159
  );
20130
20160
  lastLineWasLocation = true;
@@ -20157,7 +20187,9 @@ function genbankToJson(string, options = {}) {
20157
20187
  val2,
20158
20188
  options.isProtein,
20159
20189
  inclusive1BasedStart,
20160
- inclusive1BasedEnd
20190
+ inclusive1BasedEnd,
20191
+ result.parsedSequence.circular,
20192
+ result.parsedSequence.sequence.length
20161
20193
  )
20162
20194
  );
20163
20195
  lastLineWasLocation = true;
@@ -21045,7 +21077,6 @@ const util$1 = util$4;
21045
21077
  const xmlNode = xmlNode$1;
21046
21078
  const readDocType = DocTypeReader;
21047
21079
  const toNumber = strnum;
21048
- "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util$1.nameRegexp);
21049
21080
  let OrderedObjParser$1 = (_a = class {
21050
21081
  constructor(options) {
21051
21082
  this.options = options;
@@ -21259,18 +21290,19 @@ const parseXml = /* @__PURE__ */ __name(function(xmlData) {
21259
21290
  const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
21260
21291
  const tagExp = xmlData.substring(i + 9, closeIndex);
21261
21292
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
21293
+ let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
21294
+ if (val2 == void 0)
21295
+ val2 = "";
21262
21296
  if (this.options.cdataPropName) {
21263
21297
  currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
21264
21298
  } else {
21265
- let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
21266
- if (val2 == void 0)
21267
- val2 = "";
21268
21299
  currentNode.add(this.options.textNodeName, val2);
21269
21300
  }
21270
21301
  i = closeIndex + 2;
21271
21302
  } else {
21272
21303
  let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
21273
21304
  let tagName = result.tagName;
21305
+ const rawTagName = result.rawTagName;
21274
21306
  let tagExp = result.tagExp;
21275
21307
  let attrExpPresent = result.attrExpPresent;
21276
21308
  let closeIndex = result.closeIndex;
@@ -21297,9 +21329,9 @@ const parseXml = /* @__PURE__ */ __name(function(xmlData) {
21297
21329
  } else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
21298
21330
  i = result.closeIndex;
21299
21331
  } else {
21300
- const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
21332
+ const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
21301
21333
  if (!result2)
21302
- throw new Error(`Unexpected end of ${tagName}`);
21334
+ throw new Error(`Unexpected end of ${rawTagName}`);
21303
21335
  i = result2.i;
21304
21336
  tagContent = result2.tagContent;
21305
21337
  }
@@ -21461,9 +21493,10 @@ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
21461
21493
  let tagName = tagExp;
21462
21494
  let attrExpPresent = true;
21463
21495
  if (separatorIndex !== -1) {
21464
- tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
21465
- tagExp = tagExp.substr(separatorIndex + 1);
21496
+ tagName = tagExp.substring(0, separatorIndex);
21497
+ tagExp = tagExp.substring(separatorIndex + 1).trimStart();
21466
21498
  }
21499
+ const rawTagName = tagName;
21467
21500
  if (removeNSPrefix) {
21468
21501
  const colonIndex = tagName.indexOf(":");
21469
21502
  if (colonIndex !== -1) {
@@ -21475,7 +21508,8 @@ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
21475
21508
  tagName,
21476
21509
  tagExp,
21477
21510
  closeIndex,
21478
- attrExpPresent
21511
+ attrExpPresent,
21512
+ rawTagName
21479
21513
  };
21480
21514
  }
21481
21515
  __name(readTagExp, "readTagExp");
@@ -21705,6 +21739,8 @@ function arrToStr(arr, options, jPath, indentation) {
21705
21739
  for (let i = 0; i < arr.length; i++) {
21706
21740
  const tagObj = arr[i];
21707
21741
  const tagName = propName(tagObj);
21742
+ if (tagName === void 0)
21743
+ continue;
21708
21744
  let newJPath = "";
21709
21745
  if (jPath.length === 0)
21710
21746
  newJPath = tagName;
@@ -21776,6 +21812,8 @@ function propName(obj) {
21776
21812
  const keys = Object.keys(obj);
21777
21813
  for (let i = 0; i < keys.length; i++) {
21778
21814
  const key = keys[i];
21815
+ if (!obj.hasOwnProperty(key))
21816
+ continue;
21779
21817
  if (key !== ":@")
21780
21818
  return key;
21781
21819
  }
@@ -21785,6 +21823,8 @@ function attr_to_str(attrMap, options) {
21785
21823
  let attrStr = "";
21786
21824
  if (attrMap && !options.ignoreAttributes) {
21787
21825
  for (let attr in attrMap) {
21826
+ if (!attrMap.hasOwnProperty(attr))
21827
+ continue;
21788
21828
  let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
21789
21829
  attrVal = replaceEntitiesValue(attrVal, options);
21790
21830
  if (attrVal === true && options.suppressBooleanAttributes) {
@@ -21893,6 +21933,8 @@ Builder.prototype.j2x = function(jObj, level) {
21893
21933
  let attrStr = "";
21894
21934
  let val2 = "";
21895
21935
  for (let key in jObj) {
21936
+ if (!Object.prototype.hasOwnProperty.call(jObj, key))
21937
+ continue;
21896
21938
  if (typeof jObj[key] === "undefined") {
21897
21939
  if (this.isAttribute(key)) {
21898
21940
  val2 += "";
@@ -30332,9 +30374,7 @@ var slc = /* @__PURE__ */ __name(function(v, s, e) {
30332
30374
  s = 0;
30333
30375
  if (e == null || e > v.length)
30334
30376
  e = v.length;
30335
- var n = new u8(e - s);
30336
- n.set(v.subarray(s, e));
30337
- return n;
30377
+ return new u8(v.subarray(s, e));
30338
30378
  }, "slc");
30339
30379
  var ec = [
30340
30380
  "unexpected EOF",
@@ -30366,9 +30406,10 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30366
30406
  var sl = dat.length, dl = dict ? dict.length : 0;
30367
30407
  if (!sl || st.f && !st.l)
30368
30408
  return buf || new u8(0);
30369
- var noBuf = !buf || st.i != 2;
30409
+ var noBuf = !buf;
30410
+ var resize = noBuf || st.i != 2;
30370
30411
  var noSt = st.i;
30371
- if (!buf)
30412
+ if (noBuf)
30372
30413
  buf = new u8(sl * 3);
30373
30414
  var cbuf = /* @__PURE__ */ __name(function(l2) {
30374
30415
  var bl = buf.length;
@@ -30392,7 +30433,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30392
30433
  err(0);
30393
30434
  break;
30394
30435
  }
30395
- if (noBuf)
30436
+ if (resize)
30396
30437
  cbuf(bt + l);
30397
30438
  buf.set(dat.subarray(s, t), bt);
30398
30439
  st.b = bt += l, st.p = pos = t * 8, st.f = final;
@@ -30442,7 +30483,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30442
30483
  break;
30443
30484
  }
30444
30485
  }
30445
- if (noBuf)
30486
+ if (resize)
30446
30487
  cbuf(bt + 131072);
30447
30488
  var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
30448
30489
  var lpos = pos;
@@ -30482,7 +30523,7 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30482
30523
  err(0);
30483
30524
  break;
30484
30525
  }
30485
- if (noBuf)
30526
+ if (resize)
30486
30527
  cbuf(bt + 131072);
30487
30528
  var end = bt + add;
30488
30529
  if (bt < dt) {
@@ -30492,20 +30533,15 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
30492
30533
  for (; bt < dend; ++bt)
30493
30534
  buf[bt] = dict[shift + bt];
30494
30535
  }
30495
- for (; bt < end; bt += 4) {
30536
+ for (; bt < end; ++bt)
30496
30537
  buf[bt] = buf[bt - dt];
30497
- buf[bt + 1] = buf[bt + 1 - dt];
30498
- buf[bt + 2] = buf[bt + 2 - dt];
30499
- buf[bt + 3] = buf[bt + 3 - dt];
30500
- }
30501
- bt = end;
30502
30538
  }
30503
30539
  }
30504
30540
  st.l = lm, st.p = lpos, st.b = bt, st.f = final;
30505
30541
  if (lm)
30506
30542
  final = 1, st.m = lbt, st.d = dm, st.n = dbt;
30507
30543
  } while (!final);
30508
- return bt == buf.length ? buf : slc(buf, 0, bt);
30544
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
30509
30545
  }, "inflt");
30510
30546
  var et = /* @__PURE__ */ new u8(0);
30511
30547
  var b2 = /* @__PURE__ */ __name(function(d, b) {
@@ -32669,13 +32705,12 @@ function jsonToFasta(jsonSequence, options) {
32669
32705
  proteinSize,
32670
32706
  proteinSequence
32671
32707
  } = cleanedData;
32672
- options = options || {};
32673
- let seqToUse = sequence;
32674
- let sizeToUse = size;
32675
- if (isProtein && proteinSequence) {
32676
- seqToUse = proteinSequence;
32677
- sizeToUse = proteinSize;
32678
- }
32708
+ options = __spreadValues({
32709
+ sequence: isProtein && proteinSequence ? proteinSequence : sequence,
32710
+ size: isProtein && proteinSequence ? proteinSize : size
32711
+ }, options);
32712
+ const seqToUse = options.sequence;
32713
+ const sizeToUse = options.size;
32679
32714
  let fastaString = "";
32680
32715
  fastaString += `>${name || "Untitled Sequence"}|`;
32681
32716
  fastaString += "|" + sizeToUse;
package/index.umd.js CHANGED
@@ -1,4 +1,7 @@
1
- var __defProp = Object.defineProperty;
1
+ (function(global2, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.bioParsers = {}));
3
+ })(this, function(exports2) {
4
+ "use strict";var __defProp = Object.defineProperty;
2
5
  var __defProps = Object.defineProperties;
3
6
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -39,11 +42,8 @@ var __async = (__this, __arguments, generator) => {
39
42
  step((generator = generator.apply(__this, __arguments)).next());
40
43
  });
41
44
  };
42
- (function(global2, factory) {
43
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.bioParsers = {}));
44
- })(this, function(exports2) {
45
+
45
46
  var _a2, _b2;
46
- "use strict";
47
47
  const untitledSequenceName = "Untitled Sequence";
48
48
  const gbDivisions = {
49
49
  // https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html#GenBankDivisionB
@@ -995,7 +995,7 @@ var __async = (__this, __arguments, generator) => {
995
995
  return new LodashWrapper(value);
996
996
  }
997
997
  __name(lodash2, "lodash");
998
- var baseCreate = function() {
998
+ var baseCreate = /* @__PURE__ */ function() {
999
999
  function object() {
1000
1000
  }
1001
1001
  __name(object, "object");
@@ -4620,7 +4620,7 @@ var __async = (__this, __arguments, generator) => {
4620
4620
  var gte = createRelationalOperation(function(value, other) {
4621
4621
  return value >= other;
4622
4622
  });
4623
- var isArguments = baseIsArguments(function() {
4623
+ var isArguments = baseIsArguments(/* @__PURE__ */ function() {
4624
4624
  return arguments;
4625
4625
  }()) ? baseIsArguments : function(value) {
4626
4626
  return isObjectLike(value) && hasOwnProperty2.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
@@ -6171,7 +6171,7 @@ var __async = (__this, __arguments, generator) => {
6171
6171
  }).call(commonjsGlobal);
6172
6172
  })(lodash, lodash.exports);
6173
6173
  var lodashExports = lodash.exports;
6174
- const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO";
6174
+ const extended_protein_letters = "ACDEFGHIKLMNPQRSTVWYBXZJUO*";
6175
6175
  const ambiguous_dna_letters = "GATCRYWSMKHBVDN";
6176
6176
  const ambiguous_rna_letters = "GAUCRYWSMKHBVDN";
6177
6177
  const aminoAcidToDegenerateDnaMap = {
@@ -6886,7 +6886,7 @@ var __async = (__this, __arguments, generator) => {
6886
6886
  throw new TypeError("Cannot call a class as a function");
6887
6887
  }
6888
6888
  }, "classCallCheck");
6889
- var createClass = function() {
6889
+ var createClass = /* @__PURE__ */ function() {
6890
6890
  function defineProperties(target, props) {
6891
6891
  for (var i2 = 0; i2 < props.length; i2++) {
6892
6892
  var descriptor = props[i2];
@@ -6948,7 +6948,7 @@ var __async = (__this, __arguments, generator) => {
6948
6948
  }
6949
6949
  return call && (typeof call === "object" || typeof call === "function") ? call : self2;
6950
6950
  }, "possibleConstructorReturn");
6951
- var slicedToArray = function() {
6951
+ var slicedToArray = /* @__PURE__ */ function() {
6952
6952
  function sliceIterator(arr, i2) {
6953
6953
  var _arr = [];
6954
6954
  var _n = true;
@@ -11276,6 +11276,20 @@ var __async = (__this, __arguments, generator) => {
11276
11276
  "primers",
11277
11277
  "guides"
11278
11278
  ];
11279
+ let allWarnings = [];
11280
+ let makeToast = /* @__PURE__ */ __name(() => {
11281
+ if (typeof window !== "undefined" && window.toastr && allWarnings.length) {
11282
+ window.toastr.warning(lodashExports.uniq(allWarnings).join("\n"));
11283
+ }
11284
+ allWarnings = [];
11285
+ }, "makeToast");
11286
+ makeToast = lodashExports.debounce(makeToast, 200);
11287
+ function showWarnings(warnings) {
11288
+ allWarnings = allWarnings.concat(warnings);
11289
+ makeToast.cancel();
11290
+ makeToast();
11291
+ }
11292
+ __name(showWarnings, "showWarnings");
11279
11293
  function filterSequenceString(sequenceString = "", {
11280
11294
  additionalValidChars = "",
11281
11295
  isOligo,
@@ -11323,14 +11337,15 @@ var __async = (__this, __arguments, generator) => {
11323
11337
  });
11324
11338
  if (sequenceString.length !== sanitizedVal.length) {
11325
11339
  warnings.push(
11326
- `${name2 ? `Sequence ${name2}: ` : ""}Invalid character(s) detected and removed: ${invalidChars.slice(0, 100).join(", ")} `
11340
+ `${name2 ? `Sequence ${name2}: ` : ""}Invalid character(s) detected and removed: ${lodashExports.uniq(invalidChars).map((c) => {
11341
+ if (c === " ") {
11342
+ return "space";
11343
+ }
11344
+ return c;
11345
+ }).slice(0, 100).join(", ")} `
11327
11346
  );
11328
11347
  }
11329
- if (typeof window !== "undefined" && window.toastr && warnings.length) {
11330
- warnings.forEach((warning) => {
11331
- window.toastr.warning(warning);
11332
- });
11333
- }
11348
+ showWarnings(warnings);
11334
11349
  return [sanitizedVal, warnings];
11335
11350
  }
11336
11351
  __name(filterSequenceString, "filterSequenceString");
@@ -11670,12 +11685,12 @@ var __async = (__this, __arguments, generator) => {
11670
11685
  // Monovalent salt concentration. 50mM is typical for PCR.
11671
11686
  /**
11672
11687
  * Calculates temperature for DNA sequence using a given algorithm.
11673
- * @param {String} sequence The DNA sequence to use.
11674
- * @param {String} type Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11675
- * @param {Double} A Helix initation for deltaS. Defaults to -10.8.
11676
- * @param {Double} R The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11677
- * @param {Double} Na THe monovalent salt concentration. Defaults to 50e-3M.
11678
- * @return {Double} Temperature for the given sequence, in Celsius.
11688
+ * sequence - The DNA sequence to use.
11689
+ * type - Either Teselagen.bio.tools.TemperatureCalculator.TABLE_BRESLAUER, TABLE_SUGIMOTO, or TABLE_UNIFIED
11690
+ * A - Helix initation for deltaS. Defaults to -10.8.
11691
+ * R - The gas constant, in cal/(K*mol). Defaults to 0.5e-6M.
11692
+ * Na - THe monovalent salt concentration. Defaults to 50e-3M.
11693
+ * return - Temperature for the given sequence, in Celsius.
11679
11694
  */
11680
11695
  calculateTemperature: function(sequence, type, A, R, C, Na) {
11681
11696
  if (typeof type === "undefined") {
@@ -19774,7 +19789,7 @@ var __async = (__this, __arguments, generator) => {
19774
19789
  return parsingResultArray;
19775
19790
  }
19776
19791
  __name(flattenSequenceArray, "flattenSequenceArray");
19777
- function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd) {
19792
+ function parseFeatureLocation(locStr, isProtein, inclusive1BasedStart, inclusive1BasedEnd, isCircular, sequenceLength) {
19778
19793
  locStr = locStr.trim();
19779
19794
  const locArr = [];
19780
19795
  locStr.replace(/(\d+)/g, function(string, match) {
@@ -19795,6 +19810,19 @@ var __async = (__this, __arguments, generator) => {
19795
19810
  isProtein ? convertAACaretPositionOrRangeToDna(location) : location
19796
19811
  );
19797
19812
  }
19813
+ if (isCircular) {
19814
+ for (let i2 = 0; i2 < locArray.length; i2 += 2) {
19815
+ const firstFeature = locArray[i2];
19816
+ const secondFeature = locArray[i2 + 1];
19817
+ if (firstFeature.end === sequenceLength - (inclusive1BasedEnd ? 0 : 1) && secondFeature.start === 1 - (inclusive1BasedStart ? 0 : 1)) {
19818
+ locArray[i2] = {
19819
+ start: firstFeature.start,
19820
+ end: secondFeature.end
19821
+ };
19822
+ locArray.splice(i2 + 1, 1);
19823
+ }
19824
+ }
19825
+ }
19798
19826
  return locArray;
19799
19827
  }
19800
19828
  __name(parseFeatureLocation, "parseFeatureLocation");
@@ -20128,7 +20156,9 @@ var __async = (__this, __arguments, generator) => {
20128
20156
  line.trim(),
20129
20157
  options.isProtein,
20130
20158
  inclusive1BasedStart,
20131
- inclusive1BasedEnd
20159
+ inclusive1BasedEnd,
20160
+ result.parsedSequence.circular,
20161
+ result.parsedSequence.sequence.length
20132
20162
  )
20133
20163
  );
20134
20164
  lastLineWasLocation = true;
@@ -20161,7 +20191,9 @@ var __async = (__this, __arguments, generator) => {
20161
20191
  val2,
20162
20192
  options.isProtein,
20163
20193
  inclusive1BasedStart,
20164
- inclusive1BasedEnd
20194
+ inclusive1BasedEnd,
20195
+ result.parsedSequence.circular,
20196
+ result.parsedSequence.sequence.length
20165
20197
  )
20166
20198
  );
20167
20199
  lastLineWasLocation = true;
@@ -21049,7 +21081,6 @@ var __async = (__this, __arguments, generator) => {
21049
21081
  const xmlNode = xmlNode$1;
21050
21082
  const readDocType = DocTypeReader;
21051
21083
  const toNumber = strnum;
21052
- "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util$1.nameRegexp);
21053
21084
  let OrderedObjParser$1 = (_a2 = class {
21054
21085
  constructor(options) {
21055
21086
  this.options = options;
@@ -21263,18 +21294,19 @@ var __async = (__this, __arguments, generator) => {
21263
21294
  const closeIndex = findClosingIndex(xmlData, "]]>", i2, "CDATA is not closed.") - 2;
21264
21295
  const tagExp = xmlData.substring(i2 + 9, closeIndex);
21265
21296
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
21297
+ let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
21298
+ if (val2 == void 0)
21299
+ val2 = "";
21266
21300
  if (this.options.cdataPropName) {
21267
21301
  currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
21268
21302
  } else {
21269
- let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
21270
- if (val2 == void 0)
21271
- val2 = "";
21272
21303
  currentNode.add(this.options.textNodeName, val2);
21273
21304
  }
21274
21305
  i2 = closeIndex + 2;
21275
21306
  } else {
21276
21307
  let result = readTagExp(xmlData, i2, this.options.removeNSPrefix);
21277
21308
  let tagName = result.tagName;
21309
+ const rawTagName = result.rawTagName;
21278
21310
  let tagExp = result.tagExp;
21279
21311
  let attrExpPresent = result.attrExpPresent;
21280
21312
  let closeIndex = result.closeIndex;
@@ -21301,9 +21333,9 @@ var __async = (__this, __arguments, generator) => {
21301
21333
  } else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
21302
21334
  i2 = result.closeIndex;
21303
21335
  } else {
21304
- const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
21336
+ const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
21305
21337
  if (!result2)
21306
- throw new Error(`Unexpected end of ${tagName}`);
21338
+ throw new Error(`Unexpected end of ${rawTagName}`);
21307
21339
  i2 = result2.i;
21308
21340
  tagContent = result2.tagContent;
21309
21341
  }
@@ -21465,9 +21497,10 @@ var __async = (__this, __arguments, generator) => {
21465
21497
  let tagName = tagExp;
21466
21498
  let attrExpPresent = true;
21467
21499
  if (separatorIndex !== -1) {
21468
- tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
21469
- tagExp = tagExp.substr(separatorIndex + 1);
21500
+ tagName = tagExp.substring(0, separatorIndex);
21501
+ tagExp = tagExp.substring(separatorIndex + 1).trimStart();
21470
21502
  }
21503
+ const rawTagName = tagName;
21471
21504
  if (removeNSPrefix) {
21472
21505
  const colonIndex = tagName.indexOf(":");
21473
21506
  if (colonIndex !== -1) {
@@ -21479,7 +21512,8 @@ var __async = (__this, __arguments, generator) => {
21479
21512
  tagName,
21480
21513
  tagExp,
21481
21514
  closeIndex,
21482
- attrExpPresent
21515
+ attrExpPresent,
21516
+ rawTagName
21483
21517
  };
21484
21518
  }
21485
21519
  __name(readTagExp, "readTagExp");
@@ -21709,6 +21743,8 @@ var __async = (__this, __arguments, generator) => {
21709
21743
  for (let i2 = 0; i2 < arr.length; i2++) {
21710
21744
  const tagObj = arr[i2];
21711
21745
  const tagName = propName(tagObj);
21746
+ if (tagName === void 0)
21747
+ continue;
21712
21748
  let newJPath = "";
21713
21749
  if (jPath.length === 0)
21714
21750
  newJPath = tagName;
@@ -21780,6 +21816,8 @@ var __async = (__this, __arguments, generator) => {
21780
21816
  const keys = Object.keys(obj);
21781
21817
  for (let i2 = 0; i2 < keys.length; i2++) {
21782
21818
  const key = keys[i2];
21819
+ if (!obj.hasOwnProperty(key))
21820
+ continue;
21783
21821
  if (key !== ":@")
21784
21822
  return key;
21785
21823
  }
@@ -21789,6 +21827,8 @@ var __async = (__this, __arguments, generator) => {
21789
21827
  let attrStr = "";
21790
21828
  if (attrMap && !options.ignoreAttributes) {
21791
21829
  for (let attr in attrMap) {
21830
+ if (!attrMap.hasOwnProperty(attr))
21831
+ continue;
21792
21832
  let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
21793
21833
  attrVal = replaceEntitiesValue(attrVal, options);
21794
21834
  if (attrVal === true && options.suppressBooleanAttributes) {
@@ -21897,6 +21937,8 @@ var __async = (__this, __arguments, generator) => {
21897
21937
  let attrStr = "";
21898
21938
  let val2 = "";
21899
21939
  for (let key in jObj) {
21940
+ if (!Object.prototype.hasOwnProperty.call(jObj, key))
21941
+ continue;
21900
21942
  if (typeof jObj[key] === "undefined") {
21901
21943
  if (this.isAttribute(key)) {
21902
21944
  val2 += "";
@@ -30336,9 +30378,7 @@ ${seq.sequence}
30336
30378
  s = 0;
30337
30379
  if (e == null || e > v.length)
30338
30380
  e = v.length;
30339
- var n = new u8(e - s);
30340
- n.set(v.subarray(s, e));
30341
- return n;
30381
+ return new u8(v.subarray(s, e));
30342
30382
  }, "slc");
30343
30383
  var ec = [
30344
30384
  "unexpected EOF",
@@ -30370,9 +30410,10 @@ ${seq.sequence}
30370
30410
  var sl = dat.length, dl = dict ? dict.length : 0;
30371
30411
  if (!sl || st.f && !st.l)
30372
30412
  return buf || new u8(0);
30373
- var noBuf = !buf || st.i != 2;
30413
+ var noBuf = !buf;
30414
+ var resize = noBuf || st.i != 2;
30374
30415
  var noSt = st.i;
30375
- if (!buf)
30416
+ if (noBuf)
30376
30417
  buf = new u8(sl * 3);
30377
30418
  var cbuf = /* @__PURE__ */ __name(function(l2) {
30378
30419
  var bl = buf.length;
@@ -30396,7 +30437,7 @@ ${seq.sequence}
30396
30437
  err(0);
30397
30438
  break;
30398
30439
  }
30399
- if (noBuf)
30440
+ if (resize)
30400
30441
  cbuf(bt + l);
30401
30442
  buf.set(dat.subarray(s, t), bt);
30402
30443
  st.b = bt += l, st.p = pos = t * 8, st.f = final;
@@ -30446,7 +30487,7 @@ ${seq.sequence}
30446
30487
  break;
30447
30488
  }
30448
30489
  }
30449
- if (noBuf)
30490
+ if (resize)
30450
30491
  cbuf(bt + 131072);
30451
30492
  var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
30452
30493
  var lpos = pos;
@@ -30486,7 +30527,7 @@ ${seq.sequence}
30486
30527
  err(0);
30487
30528
  break;
30488
30529
  }
30489
- if (noBuf)
30530
+ if (resize)
30490
30531
  cbuf(bt + 131072);
30491
30532
  var end = bt + add;
30492
30533
  if (bt < dt) {
@@ -30496,20 +30537,15 @@ ${seq.sequence}
30496
30537
  for (; bt < dend; ++bt)
30497
30538
  buf[bt] = dict[shift + bt];
30498
30539
  }
30499
- for (; bt < end; bt += 4) {
30540
+ for (; bt < end; ++bt)
30500
30541
  buf[bt] = buf[bt - dt];
30501
- buf[bt + 1] = buf[bt + 1 - dt];
30502
- buf[bt + 2] = buf[bt + 2 - dt];
30503
- buf[bt + 3] = buf[bt + 3 - dt];
30504
- }
30505
- bt = end;
30506
30542
  }
30507
30543
  }
30508
30544
  st.l = lm, st.p = lpos, st.b = bt, st.f = final;
30509
30545
  if (lm)
30510
30546
  final = 1, st.m = lbt, st.d = dm, st.n = dbt;
30511
30547
  } while (!final);
30512
- return bt == buf.length ? buf : slc(buf, 0, bt);
30548
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
30513
30549
  }, "inflt");
30514
30550
  var et = /* @__PURE__ */ new u8(0);
30515
30551
  var b2 = /* @__PURE__ */ __name(function(d, b) {
@@ -32673,13 +32709,12 @@ ${seq.sequence}
32673
32709
  proteinSize,
32674
32710
  proteinSequence
32675
32711
  } = cleanedData;
32676
- options = options || {};
32677
- let seqToUse = sequence;
32678
- let sizeToUse = size;
32679
- if (isProtein && proteinSequence) {
32680
- seqToUse = proteinSequence;
32681
- sizeToUse = proteinSize;
32682
- }
32712
+ options = __spreadValues({
32713
+ sequence: isProtein && proteinSequence ? proteinSequence : sequence,
32714
+ size: isProtein && proteinSequence ? proteinSize : size
32715
+ }, options);
32716
+ const seqToUse = options.sequence;
32717
+ const sizeToUse = options.size;
32683
32718
  let fastaString = "";
32684
32719
  fastaString += `>${name2 || "Untitled Sequence"}|`;
32685
32720
  fastaString += "|" + sizeToUse;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@teselagen/bio-parsers",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "dependencies": {
5
- "@teselagen/sequence-utils": "0.3.15",
5
+ "@teselagen/sequence-utils": "0.3.20",
6
6
  "@teselagen/range-utils": "0.3.7",
7
7
  "@gmod/gff": "^1.2.1",
8
8
  "buffer": "^6.0.3",
@@ -12,7 +12,9 @@ export function parseFeatureLocation(
12
12
  locStr,
13
13
  isProtein,
14
14
  inclusive1BasedStart,
15
- inclusive1BasedEnd
15
+ inclusive1BasedEnd,
16
+ isCircular,
17
+ sequenceLength
16
18
  ) {
17
19
  locStr = locStr.trim();
18
20
  const locArr = [];
@@ -39,6 +41,30 @@ export function parseFeatureLocation(
39
41
  isProtein ? convertAACaretPositionOrRangeToDna(location) : location
40
42
  );
41
43
  }
44
+ // In genbank files, origin-spanning features are represented as follows:
45
+ // complement(join(490883..490885,1..879)) (for a circular sequence of length 490885)
46
+ // Then, for locations in locArray we check if there is a feature that ends at sequenceLength
47
+ // joined with a feature that starts at 1. If so, we merge them into a single feature.
48
+ // (see https://github.com/TeselaGen/tg-oss/issues/35)
49
+
50
+ if (isCircular) {
51
+ // Iterate by pairs of features
52
+ for (let i = 0; i < locArray.length; i += 2) {
53
+ const firstFeature = locArray[i];
54
+ const secondFeature = locArray[i + 1];
55
+ if (
56
+ firstFeature.end === sequenceLength - (inclusive1BasedEnd ? 0 : 1) &&
57
+ secondFeature.start === 1 - (inclusive1BasedStart ? 0 : 1)
58
+ ) {
59
+ // Merge the two features
60
+ locArray[i] = {
61
+ start: firstFeature.start,
62
+ end: secondFeature.end
63
+ };
64
+ locArray.splice(i + 1, 1);
65
+ }
66
+ }
67
+ }
42
68
  return locArray;
43
69
  }
44
70
 
@@ -468,7 +494,9 @@ function genbankToJson(string, options = {}) {
468
494
  line.trim(),
469
495
  options.isProtein,
470
496
  inclusive1BasedStart,
471
- inclusive1BasedEnd
497
+ inclusive1BasedEnd,
498
+ result.parsedSequence.circular,
499
+ result.parsedSequence.sequence.length
472
500
  )
473
501
  );
474
502
  lastLineWasLocation = true;
@@ -513,7 +541,9 @@ function genbankToJson(string, options = {}) {
513
541
  val,
514
542
  options.isProtein,
515
543
  inclusive1BasedStart,
516
- inclusive1BasedEnd
544
+ inclusive1BasedEnd,
545
+ result.parsedSequence.circular,
546
+ result.parsedSequence.sequence.length
517
547
  )
518
548
  );
519
549
  lastLineWasLocation = true;
@@ -663,8 +693,8 @@ function genbankToJson(string, options = {}) {
663
693
  feat.notes.direction[0].toUpperCase() === "BOTH"
664
694
  ? "BOTH"
665
695
  : feat.notes.direction[0].toUpperCase() === "NONE"
666
- ? "NONE"
667
- : undefined;
696
+ ? "NONE"
697
+ : undefined;
668
698
  delete feat.notes.direction;
669
699
  }
670
700
  return feat;
@@ -14,13 +14,13 @@ export default function jsonToFasta(jsonSequence, options) {
14
14
  proteinSequence
15
15
  } = cleanedData;
16
16
 
17
- options = options || {};
18
- let seqToUse = sequence;
19
- let sizeToUse = size;
20
- if (isProtein && proteinSequence) {
21
- seqToUse = proteinSequence;
22
- sizeToUse = proteinSize;
23
- }
17
+ options = {
18
+ sequence: isProtein && proteinSequence ? proteinSequence : sequence,
19
+ size: isProtein && proteinSequence ? proteinSize : size,
20
+ ...options
21
+ };
22
+ const seqToUse = options.sequence;
23
+ const sizeToUse = options.size;
24
24
  // options.reformatSeqName = options.reformatSeqName === false ? false : true;
25
25
  let fastaString = "";
26
26
  fastaString += `>${name || "Untitled Sequence"}|`;