@teselagen/bio-parsers 0.4.35 → 0.4.37

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) {
@@ -23821,7 +23828,44 @@ function getCurrentDateString() {
23821
23828
  return day + "-" + month + "-" + year;
23822
23829
  }
23823
23830
  __name(getCurrentDateString, "getCurrentDateString");
23831
+ const standardLineLength = 79;
23824
23832
  function featureNoteInDataToGenbankString(name, value, options) {
23833
+ const valueString = mangleOrStripUrls(value, options);
23834
+ if (valueString.length > standardLineLength - 25 - name.length) {
23835
+ const lines = [];
23836
+ let currentIndex = 0;
23837
+ while (currentIndex < valueString.length) {
23838
+ if (currentIndex === 0) {
23839
+ const chunk = valueString.substring(
23840
+ currentIndex,
23841
+ currentIndex + standardLineLength - name.length - 24
23842
+ );
23843
+ lines.push(
23844
+ StringUtil.lpad("/", " ", 22) + name + '="' + chunk + (currentIndex + standardLineLength - 22 - name.length >= valueString.length ? '"' : "")
23845
+ );
23846
+ currentIndex += standardLineLength - name.length - 24;
23847
+ } else {
23848
+ const chunk = valueString.substring(
23849
+ currentIndex,
23850
+ currentIndex + standardLineLength - 21
23851
+ );
23852
+ if (currentIndex + standardLineLength - 21 >= valueString.length) {
23853
+ const lineString = " ".repeat(21) + chunk;
23854
+ if (lineString.length === standardLineLength) {
23855
+ lines.push(lineString);
23856
+ lines.push(" ".repeat(21) + '"');
23857
+ } else {
23858
+ lines.push(lineString + '"');
23859
+ }
23860
+ } else {
23861
+ const lineString = " ".repeat(21) + chunk;
23862
+ lines.push(lineString);
23863
+ }
23864
+ currentIndex += standardLineLength - 21;
23865
+ }
23866
+ }
23867
+ return lines.join("\r\n");
23868
+ }
23825
23869
  return StringUtil.lpad("/", " ", 22) + name + '="' + mangleOrStripUrls(value, options) + '"';
23826
23870
  }
23827
23871
  __name(featureNoteInDataToGenbankString, "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) {
@@ -23819,7 +23826,44 @@ function getCurrentDateString() {
23819
23826
  return day + "-" + month + "-" + year;
23820
23827
  }
23821
23828
  __name(getCurrentDateString, "getCurrentDateString");
23829
+ const standardLineLength = 79;
23822
23830
  function featureNoteInDataToGenbankString(name, value, options) {
23831
+ const valueString = mangleOrStripUrls(value, options);
23832
+ if (valueString.length > standardLineLength - 25 - name.length) {
23833
+ const lines = [];
23834
+ let currentIndex = 0;
23835
+ while (currentIndex < valueString.length) {
23836
+ if (currentIndex === 0) {
23837
+ const chunk = valueString.substring(
23838
+ currentIndex,
23839
+ currentIndex + standardLineLength - name.length - 24
23840
+ );
23841
+ lines.push(
23842
+ StringUtil.lpad("/", " ", 22) + name + '="' + chunk + (currentIndex + standardLineLength - 22 - name.length >= valueString.length ? '"' : "")
23843
+ );
23844
+ currentIndex += standardLineLength - name.length - 24;
23845
+ } else {
23846
+ const chunk = valueString.substring(
23847
+ currentIndex,
23848
+ currentIndex + standardLineLength - 21
23849
+ );
23850
+ if (currentIndex + standardLineLength - 21 >= valueString.length) {
23851
+ const lineString = " ".repeat(21) + chunk;
23852
+ if (lineString.length === standardLineLength) {
23853
+ lines.push(lineString);
23854
+ lines.push(" ".repeat(21) + '"');
23855
+ } else {
23856
+ lines.push(lineString + '"');
23857
+ }
23858
+ } else {
23859
+ const lineString = " ".repeat(21) + chunk;
23860
+ lines.push(lineString);
23861
+ }
23862
+ currentIndex += standardLineLength - 21;
23863
+ }
23864
+ }
23865
+ return lines.join("\r\n");
23866
+ }
23823
23867
  return StringUtil.lpad("/", " ", 22) + name + '="' + mangleOrStripUrls(value, options) + '"';
23824
23868
  }
23825
23869
  __name(featureNoteInDataToGenbankString, "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) {
@@ -23823,7 +23830,44 @@ ${seq.sequence}
23823
23830
  return day + "-" + month + "-" + year;
23824
23831
  }
23825
23832
  __name(getCurrentDateString, "getCurrentDateString");
23833
+ const standardLineLength = 79;
23826
23834
  function featureNoteInDataToGenbankString(name, value, options) {
23835
+ const valueString = mangleOrStripUrls(value, options);
23836
+ if (valueString.length > standardLineLength - 25 - name.length) {
23837
+ const lines = [];
23838
+ let currentIndex = 0;
23839
+ while (currentIndex < valueString.length) {
23840
+ if (currentIndex === 0) {
23841
+ const chunk = valueString.substring(
23842
+ currentIndex,
23843
+ currentIndex + standardLineLength - name.length - 24
23844
+ );
23845
+ lines.push(
23846
+ StringUtil.lpad("/", " ", 22) + name + '="' + chunk + (currentIndex + standardLineLength - 22 - name.length >= valueString.length ? '"' : "")
23847
+ );
23848
+ currentIndex += standardLineLength - name.length - 24;
23849
+ } else {
23850
+ const chunk = valueString.substring(
23851
+ currentIndex,
23852
+ currentIndex + standardLineLength - 21
23853
+ );
23854
+ if (currentIndex + standardLineLength - 21 >= valueString.length) {
23855
+ const lineString = " ".repeat(21) + chunk;
23856
+ if (lineString.length === standardLineLength) {
23857
+ lines.push(lineString);
23858
+ lines.push(" ".repeat(21) + '"');
23859
+ } else {
23860
+ lines.push(lineString + '"');
23861
+ }
23862
+ } else {
23863
+ const lineString = " ".repeat(21) + chunk;
23864
+ lines.push(lineString);
23865
+ }
23866
+ currentIndex += standardLineLength - 21;
23867
+ }
23868
+ }
23869
+ return lines.join("\r\n");
23870
+ }
23827
23871
  return StringUtil.lpad("/", " ", 22) + name + '="' + mangleOrStripUrls(value, options) + '"';
23828
23872
  }
23829
23873
  __name(featureNoteInDataToGenbankString, "featureNoteInDataToGenbankString");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/bio-parsers",
3
- "version": "0.4.35",
3
+ "version": "0.4.37",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/TeselaGen/tg-oss",
6
6
  "dependencies": {
@@ -6,6 +6,7 @@ import pragmasAndTypes from "./utils/pragmasAndTypes.js";
6
6
  import { mangleOrStripUrls } from "./utils/unmangleUrls.js";
7
7
  import { reformatName } from "./utils/NameUtils.js";
8
8
  import { getFeatureToColorMap } from "@teselagen/sequence-utils";
9
+
9
10
  const StringUtil = {
10
11
  /** Trims white space at beginning and end of string
11
12
  * @param {string} line
@@ -206,11 +207,11 @@ function createGenbankLocus(serSeq, options) {
206
207
  } else if (serSeq.type === "RNA") {
207
208
  dnaType = serSeq?.doubleStranded
208
209
  ? "RNA"
209
- : serSeq?.sequenceTypeFromLocus ?? "ss-RNA";
210
+ : (serSeq?.sequenceTypeFromLocus ?? "ss-RNA");
210
211
  } else {
211
212
  dnaType = serSeq?.doubleStranded
212
213
  ? "DNA"
213
- : serSeq?.sequenceTypeFromLocus ?? "DNA";
214
+ : (serSeq?.sequenceTypeFromLocus ?? "DNA");
214
215
  }
215
216
  const date = getCurrentDateString();
216
217
 
@@ -257,7 +258,56 @@ function getCurrentDateString() {
257
258
  return day + "-" + month + "-" + year;
258
259
  }
259
260
 
261
+ const standardLineLength = 79;
260
262
  function featureNoteInDataToGenbankString(name, value, options) {
263
+ const valueString = mangleOrStripUrls(value, options);
264
+ // if valueString.length is larger than standardLineLength - 25 - name.length,
265
+ // we need to split it up into multiple lines, to make sure each line has 21 spaces
266
+ // a maximum of 59 additional characters
267
+ // 25 is the length of '/', '=', two '"' and the 21 spaces.
268
+ if (valueString.length > standardLineLength - 25 - name.length) {
269
+ const lines = [];
270
+ let currentIndex = 0;
271
+ while (currentIndex < valueString.length) {
272
+ if (currentIndex === 0) {
273
+ const chunk = valueString.substring(
274
+ currentIndex,
275
+ currentIndex + standardLineLength - name.length - 24
276
+ );
277
+ lines.push(
278
+ StringUtil.lpad("/", " ", 22) +
279
+ name +
280
+ '="' +
281
+ chunk +
282
+ (currentIndex + standardLineLength - 22 - name.length >=
283
+ valueString.length
284
+ ? '"'
285
+ : "")
286
+ );
287
+ currentIndex += standardLineLength - name.length - 24;
288
+ } else {
289
+ const chunk = valueString.substring(
290
+ currentIndex,
291
+ currentIndex + standardLineLength - 21
292
+ );
293
+ if (currentIndex + standardLineLength - 21 >= valueString.length) {
294
+ const lineString = " ".repeat(21) + chunk;
295
+ if (lineString.length === standardLineLength) {
296
+ lines.push(lineString);
297
+ lines.push(" ".repeat(21) + '"');
298
+ } else {
299
+ lines.push(lineString + '"');
300
+ }
301
+ } else {
302
+ const lineString = " ".repeat(21) + chunk;
303
+ lines.push(lineString);
304
+ }
305
+ currentIndex += standardLineLength - 21;
306
+ }
307
+ }
308
+ return lines.join("\r\n");
309
+ }
310
+
261
311
  return (
262
312
  StringUtil.lpad("/", " ", 22) +
263
313
  name +
@@ -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) {