@teselagen/bio-parsers 0.4.36 → 0.4.38

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.cjs CHANGED
@@ -17145,17 +17145,20 @@ function snapgeneToJson(_0) {
17145
17145
  const b = new fxpExports.XMLParser({
17146
17146
  ignoreAttributes: false,
17147
17147
  attributeNamePrefix: "",
17148
- isArray: /* @__PURE__ */ __name((name) => name === "Feature" || name === "Segment", "isArray")
17148
+ isArray: /* @__PURE__ */ __name((name) => ["Feature", "Segment", "Q", "V"].includes(name), "isArray")
17149
17149
  }).parse(xml);
17150
17150
  const { Features: { Feature = [] } = {} } = b;
17151
17151
  data.features = [];
17152
17152
  Feature.forEach((feat) => {
17153
+ var _a2, _b2, _c, _d;
17153
17154
  const { directionality, Segment = [], name, type } = feat;
17155
+ let color2;
17154
17156
  let maxStart = 0;
17155
17157
  let maxEnd = 0;
17156
17158
  const locations = Segment && Segment.map((seg) => {
17157
17159
  if (!seg) throw new Error("invalid feature definition");
17158
17160
  const { range } = seg;
17161
+ if (seg.color) color2 = seg.color;
17159
17162
  let { start, end } = getStartAndEndFromRangeString(range);
17160
17163
  start = isProtein ? start * 3 : start;
17161
17164
  end = isProtein ? end * 3 + 2 : end;
@@ -17166,6 +17169,10 @@ function snapgeneToJson(_0) {
17166
17169
  end
17167
17170
  };
17168
17171
  });
17172
+ const colorQual = (_a2 = feat.Q) == null ? void 0 : _a2.find((q) => q.name === "color");
17173
+ if (colorQual) {
17174
+ color2 = ((_c = (_b2 = colorQual.V) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) || ((_d = colorQual.V) == null ? void 0 : _d[0]);
17175
+ }
17169
17176
  data.features.push(__spreadProps(__spreadValues({
17170
17177
  name,
17171
17178
  type
@@ -17173,8 +17180,8 @@ function snapgeneToJson(_0) {
17173
17180
  strand: directionality ? strand_dict[directionality][0] : 1,
17174
17181
  arrowheadType: directionality ? strand_dict[directionality][1] : "NONE",
17175
17182
  start: maxStart,
17176
- end: maxEnd
17177
- // color,
17183
+ end: maxEnd,
17184
+ color: color2
17178
17185
  }));
17179
17186
  });
17180
17187
  } else if (ord(next_byte) === 6) {
@@ -23674,6 +23681,38 @@ function cutUpStr(val2, start, end) {
23674
23681
  return val2.slice(start, end);
23675
23682
  }
23676
23683
  __name(cutUpStr, "cutUpStr");
23684
+ function featureToGenbankLocationString(feat, options) {
23685
+ const { inclusive1BasedStart, inclusive1BasedEnd, isProtein } = options;
23686
+ let locStr = "";
23687
+ if (feat.locations && feat.locations.length > 1) {
23688
+ feat.locations.forEach((loc, i) => {
23689
+ locStr += getProteinStart(
23690
+ parseInt(loc.start, 10) + (inclusive1BasedStart ? 0 : 1),
23691
+ isProtein
23692
+ ) + ".." + getProteinEnd(
23693
+ parseInt(loc.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23694
+ isProtein
23695
+ );
23696
+ if (i !== feat.locations.length - 1) {
23697
+ locStr += ",";
23698
+ }
23699
+ });
23700
+ locStr = "join(" + locStr + ")";
23701
+ } else {
23702
+ locStr += getProteinStart(
23703
+ parseInt(feat.start, 10) + (inclusive1BasedStart ? 0 : 1),
23704
+ isProtein
23705
+ ) + ".." + getProteinEnd(
23706
+ parseInt(feat.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23707
+ isProtein
23708
+ );
23709
+ }
23710
+ if (feat.strand === -1) {
23711
+ locStr = "complement(" + locStr + ")";
23712
+ }
23713
+ return locStr;
23714
+ }
23715
+ __name(featureToGenbankLocationString, "featureToGenbankLocationString");
23677
23716
  function jsonToGenbank(_serSeq, options) {
23678
23717
  options = options || {};
23679
23718
  options.reformatSeqName = options.reformatSeqName !== false;
@@ -23868,33 +23907,7 @@ function featureToGenbankString(feat, options) {
23868
23907
  feat.type = "primer_bind";
23869
23908
  }
23870
23909
  const line = " " + StringUtil.rpad(feat.type || "misc_feature", " ", options.featurePadLength);
23871
- let locStr = "";
23872
- if (feat.locations && feat.locations.length > 1) {
23873
- feat.locations.forEach((loc, i) => {
23874
- locStr += getProteinStart(
23875
- parseInt(loc.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23876
- options.isProtein
23877
- ) + ".." + getProteinEnd(
23878
- parseInt(loc.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23879
- options.isProtein
23880
- );
23881
- if (i !== feat.locations.length - 1) {
23882
- locStr += ",";
23883
- }
23884
- });
23885
- locStr = "join(" + locStr + ")";
23886
- } else {
23887
- locStr += getProteinStart(
23888
- parseInt(feat.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23889
- options.isProtein
23890
- ) + ".." + getProteinEnd(
23891
- parseInt(feat.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23892
- options.isProtein
23893
- );
23894
- }
23895
- if (feat.strand === -1) {
23896
- locStr = "complement(" + locStr + ")";
23897
- }
23910
+ const locStr = featureToGenbankLocationString(feat, options);
23898
23911
  lines.push(line + locStr);
23899
23912
  lines.push(
23900
23913
  featureNoteInDataToGenbankString(
package/index.js CHANGED
@@ -17143,17 +17143,20 @@ function snapgeneToJson(_0) {
17143
17143
  const b = new fxpExports.XMLParser({
17144
17144
  ignoreAttributes: false,
17145
17145
  attributeNamePrefix: "",
17146
- isArray: /* @__PURE__ */ __name((name) => name === "Feature" || name === "Segment", "isArray")
17146
+ isArray: /* @__PURE__ */ __name((name) => ["Feature", "Segment", "Q", "V"].includes(name), "isArray")
17147
17147
  }).parse(xml);
17148
17148
  const { Features: { Feature = [] } = {} } = b;
17149
17149
  data.features = [];
17150
17150
  Feature.forEach((feat) => {
17151
+ var _a2, _b2, _c, _d;
17151
17152
  const { directionality, Segment = [], name, type } = feat;
17153
+ let color2;
17152
17154
  let maxStart = 0;
17153
17155
  let maxEnd = 0;
17154
17156
  const locations = Segment && Segment.map((seg) => {
17155
17157
  if (!seg) throw new Error("invalid feature definition");
17156
17158
  const { range } = seg;
17159
+ if (seg.color) color2 = seg.color;
17157
17160
  let { start, end } = getStartAndEndFromRangeString(range);
17158
17161
  start = isProtein ? start * 3 : start;
17159
17162
  end = isProtein ? end * 3 + 2 : end;
@@ -17164,6 +17167,10 @@ function snapgeneToJson(_0) {
17164
17167
  end
17165
17168
  };
17166
17169
  });
17170
+ const colorQual = (_a2 = feat.Q) == null ? void 0 : _a2.find((q) => q.name === "color");
17171
+ if (colorQual) {
17172
+ color2 = ((_c = (_b2 = colorQual.V) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) || ((_d = colorQual.V) == null ? void 0 : _d[0]);
17173
+ }
17167
17174
  data.features.push(__spreadProps(__spreadValues({
17168
17175
  name,
17169
17176
  type
@@ -17171,8 +17178,8 @@ function snapgeneToJson(_0) {
17171
17178
  strand: directionality ? strand_dict[directionality][0] : 1,
17172
17179
  arrowheadType: directionality ? strand_dict[directionality][1] : "NONE",
17173
17180
  start: maxStart,
17174
- end: maxEnd
17175
- // color,
17181
+ end: maxEnd,
17182
+ color: color2
17176
17183
  }));
17177
17184
  });
17178
17185
  } else if (ord(next_byte) === 6) {
@@ -23672,6 +23679,38 @@ function cutUpStr(val2, start, end) {
23672
23679
  return val2.slice(start, end);
23673
23680
  }
23674
23681
  __name(cutUpStr, "cutUpStr");
23682
+ function featureToGenbankLocationString(feat, options) {
23683
+ const { inclusive1BasedStart, inclusive1BasedEnd, isProtein } = options;
23684
+ let locStr = "";
23685
+ if (feat.locations && feat.locations.length > 1) {
23686
+ feat.locations.forEach((loc, i) => {
23687
+ locStr += getProteinStart(
23688
+ parseInt(loc.start, 10) + (inclusive1BasedStart ? 0 : 1),
23689
+ isProtein
23690
+ ) + ".." + getProteinEnd(
23691
+ parseInt(loc.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23692
+ isProtein
23693
+ );
23694
+ if (i !== feat.locations.length - 1) {
23695
+ locStr += ",";
23696
+ }
23697
+ });
23698
+ locStr = "join(" + locStr + ")";
23699
+ } else {
23700
+ locStr += getProteinStart(
23701
+ parseInt(feat.start, 10) + (inclusive1BasedStart ? 0 : 1),
23702
+ isProtein
23703
+ ) + ".." + getProteinEnd(
23704
+ parseInt(feat.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23705
+ isProtein
23706
+ );
23707
+ }
23708
+ if (feat.strand === -1) {
23709
+ locStr = "complement(" + locStr + ")";
23710
+ }
23711
+ return locStr;
23712
+ }
23713
+ __name(featureToGenbankLocationString, "featureToGenbankLocationString");
23675
23714
  function jsonToGenbank(_serSeq, options) {
23676
23715
  options = options || {};
23677
23716
  options.reformatSeqName = options.reformatSeqName !== false;
@@ -23866,33 +23905,7 @@ function featureToGenbankString(feat, options) {
23866
23905
  feat.type = "primer_bind";
23867
23906
  }
23868
23907
  const line = " " + StringUtil.rpad(feat.type || "misc_feature", " ", options.featurePadLength);
23869
- let locStr = "";
23870
- if (feat.locations && feat.locations.length > 1) {
23871
- feat.locations.forEach((loc, i) => {
23872
- locStr += getProteinStart(
23873
- parseInt(loc.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23874
- options.isProtein
23875
- ) + ".." + getProteinEnd(
23876
- parseInt(loc.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23877
- options.isProtein
23878
- );
23879
- if (i !== feat.locations.length - 1) {
23880
- locStr += ",";
23881
- }
23882
- });
23883
- locStr = "join(" + locStr + ")";
23884
- } else {
23885
- locStr += getProteinStart(
23886
- parseInt(feat.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23887
- options.isProtein
23888
- ) + ".." + getProteinEnd(
23889
- parseInt(feat.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23890
- options.isProtein
23891
- );
23892
- }
23893
- if (feat.strand === -1) {
23894
- locStr = "complement(" + locStr + ")";
23895
- }
23908
+ const locStr = featureToGenbankLocationString(feat, options);
23896
23909
  lines.push(line + locStr);
23897
23910
  lines.push(
23898
23911
  featureNoteInDataToGenbankString(
package/index.umd.cjs CHANGED
@@ -17147,17 +17147,20 @@ var __async = (__this, __arguments, generator) => {
17147
17147
  const b = new fxpExports.XMLParser({
17148
17148
  ignoreAttributes: false,
17149
17149
  attributeNamePrefix: "",
17150
- isArray: /* @__PURE__ */ __name((name) => name === "Feature" || name === "Segment", "isArray")
17150
+ isArray: /* @__PURE__ */ __name((name) => ["Feature", "Segment", "Q", "V"].includes(name), "isArray")
17151
17151
  }).parse(xml);
17152
17152
  const { Features: { Feature = [] } = {} } = b;
17153
17153
  data.features = [];
17154
17154
  Feature.forEach((feat) => {
17155
+ var _a2, _b2, _c, _d;
17155
17156
  const { directionality, Segment = [], name, type } = feat;
17157
+ let color2;
17156
17158
  let maxStart = 0;
17157
17159
  let maxEnd = 0;
17158
17160
  const locations = Segment && Segment.map((seg) => {
17159
17161
  if (!seg) throw new Error("invalid feature definition");
17160
17162
  const { range } = seg;
17163
+ if (seg.color) color2 = seg.color;
17161
17164
  let { start, end } = getStartAndEndFromRangeString(range);
17162
17165
  start = isProtein ? start * 3 : start;
17163
17166
  end = isProtein ? end * 3 + 2 : end;
@@ -17168,6 +17171,10 @@ var __async = (__this, __arguments, generator) => {
17168
17171
  end
17169
17172
  };
17170
17173
  });
17174
+ const colorQual = (_a2 = feat.Q) == null ? void 0 : _a2.find((q) => q.name === "color");
17175
+ if (colorQual) {
17176
+ color2 = ((_c = (_b2 = colorQual.V) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) || ((_d = colorQual.V) == null ? void 0 : _d[0]);
17177
+ }
17171
17178
  data.features.push(__spreadProps(__spreadValues({
17172
17179
  name,
17173
17180
  type
@@ -17175,8 +17182,8 @@ var __async = (__this, __arguments, generator) => {
17175
17182
  strand: directionality ? strand_dict[directionality][0] : 1,
17176
17183
  arrowheadType: directionality ? strand_dict[directionality][1] : "NONE",
17177
17184
  start: maxStart,
17178
- end: maxEnd
17179
- // color,
17185
+ end: maxEnd,
17186
+ color: color2
17180
17187
  }));
17181
17188
  });
17182
17189
  } else if (ord(next_byte) === 6) {
@@ -23676,6 +23683,38 @@ ${seq.sequence}
23676
23683
  return val2.slice(start, end);
23677
23684
  }
23678
23685
  __name(cutUpStr, "cutUpStr");
23686
+ function featureToGenbankLocationString(feat, options) {
23687
+ const { inclusive1BasedStart, inclusive1BasedEnd, isProtein } = options;
23688
+ let locStr = "";
23689
+ if (feat.locations && feat.locations.length > 1) {
23690
+ feat.locations.forEach((loc, i2) => {
23691
+ locStr += getProteinStart(
23692
+ parseInt(loc.start, 10) + (inclusive1BasedStart ? 0 : 1),
23693
+ isProtein
23694
+ ) + ".." + getProteinEnd(
23695
+ parseInt(loc.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23696
+ isProtein
23697
+ );
23698
+ if (i2 !== feat.locations.length - 1) {
23699
+ locStr += ",";
23700
+ }
23701
+ });
23702
+ locStr = "join(" + locStr + ")";
23703
+ } else {
23704
+ locStr += getProteinStart(
23705
+ parseInt(feat.start, 10) + (inclusive1BasedStart ? 0 : 1),
23706
+ isProtein
23707
+ ) + ".." + getProteinEnd(
23708
+ parseInt(feat.end, 10) + (inclusive1BasedEnd ? 0 : 1),
23709
+ isProtein
23710
+ );
23711
+ }
23712
+ if (feat.strand === -1) {
23713
+ locStr = "complement(" + locStr + ")";
23714
+ }
23715
+ return locStr;
23716
+ }
23717
+ __name(featureToGenbankLocationString, "featureToGenbankLocationString");
23679
23718
  function jsonToGenbank(_serSeq, options) {
23680
23719
  options = options || {};
23681
23720
  options.reformatSeqName = options.reformatSeqName !== false;
@@ -23870,33 +23909,7 @@ ${seq.sequence}
23870
23909
  feat.type = "primer_bind";
23871
23910
  }
23872
23911
  const line = " " + StringUtil.rpad(feat.type || "misc_feature", " ", options.featurePadLength);
23873
- let locStr = "";
23874
- if (feat.locations && feat.locations.length > 1) {
23875
- feat.locations.forEach((loc, i2) => {
23876
- locStr += getProteinStart(
23877
- parseInt(loc.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23878
- options.isProtein
23879
- ) + ".." + getProteinEnd(
23880
- parseInt(loc.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23881
- options.isProtein
23882
- );
23883
- if (i2 !== feat.locations.length - 1) {
23884
- locStr += ",";
23885
- }
23886
- });
23887
- locStr = "join(" + locStr + ")";
23888
- } else {
23889
- locStr += getProteinStart(
23890
- parseInt(feat.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
23891
- options.isProtein
23892
- ) + ".." + getProteinEnd(
23893
- parseInt(feat.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
23894
- options.isProtein
23895
- );
23896
- }
23897
- if (feat.strand === -1) {
23898
- locStr = "complement(" + locStr + ")";
23899
- }
23912
+ const locStr = featureToGenbankLocationString(feat, options);
23900
23913
  lines.push(line + locStr);
23901
23914
  lines.push(
23902
23915
  featureNoteInDataToGenbankString(
@@ -1 +1,2 @@
1
+ export function featureToGenbankLocationString(feat: any, options: any): string;
1
2
  export default function _default(_serSeq: any, options: any): string | false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/bio-parsers",
3
- "version": "0.4.36",
3
+ "version": "0.4.38",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/TeselaGen/tg-oss",
6
6
  "dependencies": {
@@ -76,6 +76,47 @@ function cutUpStr(val, start, end) {
76
76
  return val.slice(start, end);
77
77
  }
78
78
 
79
+ export function featureToGenbankLocationString(feat, options) {
80
+ const { inclusive1BasedStart, inclusive1BasedEnd, isProtein } = options;
81
+ let locStr = "";
82
+
83
+ if (feat.locations && feat.locations.length > 1) {
84
+ feat.locations.forEach((loc, i) => {
85
+ locStr +=
86
+ getProteinStart(
87
+ parseInt(loc.start, 10) + (inclusive1BasedStart ? 0 : 1),
88
+ isProtein
89
+ ) +
90
+ ".." +
91
+ getProteinEnd(
92
+ parseInt(loc.end, 10) + (inclusive1BasedEnd ? 0 : 1),
93
+ isProtein
94
+ );
95
+
96
+ if (i !== feat.locations.length - 1) {
97
+ locStr += ",";
98
+ }
99
+ });
100
+ locStr = "join(" + locStr + ")";
101
+ } else {
102
+ locStr +=
103
+ getProteinStart(
104
+ parseInt(feat.start, 10) + (inclusive1BasedStart ? 0 : 1),
105
+ isProtein
106
+ ) +
107
+ ".." +
108
+ getProteinEnd(
109
+ parseInt(feat.end, 10) + (inclusive1BasedEnd ? 0 : 1),
110
+ isProtein
111
+ );
112
+ }
113
+
114
+ if (feat.strand === -1) {
115
+ locStr = "complement(" + locStr + ")";
116
+ }
117
+ return locStr;
118
+ }
119
+
79
120
  export default function (_serSeq, options) {
80
121
  options = options || {};
81
122
  options.reformatSeqName = options.reformatSeqName !== false;
@@ -325,49 +366,8 @@ function featureToGenbankString(feat, options) {
325
366
  const line =
326
367
  " " +
327
368
  StringUtil.rpad(feat.type || "misc_feature", " ", options.featurePadLength);
328
- let locStr = "";
329
-
330
- //for(var i=0;i<feat.locations.length;i++) {
331
- // var loc = feat.locations[i];
332
- // locStr.push((loc.start+1) + '..' + loc.end);
333
- //}
334
369
 
335
- if (feat.locations && feat.locations.length > 1) {
336
- feat.locations.forEach((loc, i) => {
337
- locStr +=
338
- getProteinStart(
339
- parseInt(loc.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
340
- options.isProtein
341
- ) +
342
- ".." +
343
- getProteinEnd(
344
- parseInt(loc.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
345
- options.isProtein
346
- );
347
-
348
- if (i !== feat.locations.length - 1) {
349
- locStr += ",";
350
- }
351
- });
352
- locStr = "join(" + locStr + ")";
353
- } else {
354
- locStr +=
355
- getProteinStart(
356
- parseInt(feat.start, 10) + (options.inclusive1BasedStart ? 0 : 1),
357
- options.isProtein
358
- ) +
359
- ".." +
360
- getProteinEnd(
361
- parseInt(feat.end, 10) + (options.inclusive1BasedEnd ? 0 : 1),
362
- options.isProtein
363
- );
364
- }
365
-
366
- // locStr = locStr.join(",");
367
-
368
- if (feat.strand === -1) {
369
- locStr = "complement(" + locStr + ")";
370
- }
370
+ const locStr = featureToGenbankLocationString(feat, options);
371
371
 
372
372
  lines.push(line + locStr);
373
373
 
@@ -113,13 +113,13 @@ async function snapgeneToJson(fileObj, options = {}) {
113
113
  const b = new XMLParser({
114
114
  ignoreAttributes: false,
115
115
  attributeNamePrefix: "",
116
- isArray: name => name === "Feature" || name === "Segment"
116
+ isArray: name => ["Feature", "Segment", "Q", "V"].includes(name)
117
117
  }).parse(xml);
118
118
  const { Features: { Feature = [] } = {} } = b;
119
119
  data.features = [];
120
120
  Feature.forEach(feat => {
121
121
  const { directionality, Segment = [], name, type } = feat;
122
- // let color;
122
+ let color;
123
123
  let maxStart = 0;
124
124
  let maxEnd = 0;
125
125
  const locations =
@@ -127,7 +127,7 @@ async function snapgeneToJson(fileObj, options = {}) {
127
127
  Segment.map(seg => {
128
128
  if (!seg) throw new Error("invalid feature definition");
129
129
  const { range } = seg;
130
- // color = seg.color;
130
+ if (seg.color) color = seg.color;
131
131
  let { start, end } = getStartAndEndFromRangeString(range);
132
132
  start = isProtein ? start * 3 : start;
133
133
  end = isProtein ? end * 3 + 2 : end;
@@ -139,6 +139,11 @@ async function snapgeneToJson(fileObj, options = {}) {
139
139
  };
140
140
  });
141
141
 
142
+ const colorQual = feat.Q?.find(q => q.name === "color");
143
+ if (colorQual) {
144
+ color = colorQual.V?.[0]?.text || colorQual.V?.[0];
145
+ }
146
+
142
147
  data.features.push({
143
148
  name,
144
149
  type,
@@ -148,8 +153,8 @@ async function snapgeneToJson(fileObj, options = {}) {
148
153
  ? strand_dict[directionality][1]
149
154
  : "NONE",
150
155
  start: maxStart,
151
- end: maxEnd
152
- // color,
156
+ end: maxEnd,
157
+ color
153
158
  });
154
159
  });
155
160
  } else if (ord(next_byte) === 6) {