@teselagen/bio-parsers 0.3.7 → 0.3.9

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.
@@ -13,7 +13,7 @@ import { get } from "lodash";
13
13
  import { XMLParser } from "fast-xml-parser";
14
14
  import extractFileExtension from "./utils/extractFileExtension";
15
15
 
16
- const Buffer = buffer.Buffer
16
+ const Buffer = buffer.Buffer;
17
17
 
18
18
  async function snapgeneToJson(fileObj, options = {}) {
19
19
  try {
@@ -59,7 +59,7 @@ async function snapgeneToJson(fileObj, options = {}) {
59
59
  isDNA: !!(await unpack(2, "H")) && !isProtein,
60
60
  exportVersion: await unpack(2, "H"),
61
61
  importVersion: await unpack(2, "H"),
62
- features: [],
62
+ features: []
63
63
  };
64
64
  while (offset <= arrayBuffer.byteLength) {
65
65
  // # READ THE WHOLE FILE, BLOCK BY BLOCK, UNTIL THE END
@@ -109,24 +109,24 @@ async function snapgeneToJson(fileObj, options = {}) {
109
109
  0: [1, "NONE"], // non-directional feature (in that case, the attribute is generally absent altogether)
110
110
  1: [1, "TOP"], // forward strand
111
111
  2: [-1, "BOTTOM"], // reverse strand
112
- 3: [1, "BOTH"], // bi-directional feature
112
+ 3: [1, "BOTH"] // bi-directional feature
113
113
  };
114
114
  const xml = await read(block_size, "utf8");
115
115
  const b = new XMLParser({
116
116
  ignoreAttributes: false,
117
117
  attributeNamePrefix: "",
118
- isArray: (name) => name === "Feature" || name === "Segment",
118
+ isArray: name => name === "Feature" || name === "Segment"
119
119
  }).parse(xml);
120
120
  const { Features: { Feature = [] } = {} } = b;
121
121
  data.features = [];
122
- Feature.forEach((feat) => {
122
+ Feature.forEach(feat => {
123
123
  const { directionality, Segment = [], name, type } = feat;
124
124
  // let color;
125
125
  let maxStart = 0;
126
126
  let maxEnd = 0;
127
127
  const locations =
128
128
  Segment &&
129
- Segment.map((seg) => {
129
+ Segment.map(seg => {
130
130
  if (!seg) throw new Error("invalid feature definition");
131
131
  const { range } = seg;
132
132
  // color = seg.color;
@@ -137,7 +137,7 @@ async function snapgeneToJson(fileObj, options = {}) {
137
137
  maxEnd = Math.max(maxEnd, end);
138
138
  return {
139
139
  start,
140
- end,
140
+ end
141
141
  };
142
142
  });
143
143
 
@@ -146,9 +146,11 @@ async function snapgeneToJson(fileObj, options = {}) {
146
146
  type,
147
147
  ...(locations?.length > 1 && { locations }),
148
148
  strand: directionality ? strand_dict[directionality][0] : 1,
149
- arrowheadType: directionality ? strand_dict[directionality][1] : "NONE",
149
+ arrowheadType: directionality
150
+ ? strand_dict[directionality][1]
151
+ : "NONE",
150
152
  start: maxStart,
151
- end: maxEnd,
153
+ end: maxEnd
152
154
  // color,
153
155
  });
154
156
  });
@@ -183,8 +185,8 @@ async function snapgeneToJson(fileObj, options = {}) {
183
185
  return [
184
186
  {
185
187
  success: false,
186
- messages: ["Import Error: Invalid File"],
187
- },
188
+ messages: ["Import Error: Invalid File"]
189
+ }
188
190
  ];
189
191
  }
190
192
  }
@@ -193,7 +195,7 @@ function getStartAndEndFromRangeString(rangestring) {
193
195
  const [start, end] = rangestring.split("-");
194
196
  return {
195
197
  start: start - 1,
196
- end: end - 1,
198
+ end: end - 1
197
199
  };
198
200
  }
199
201
 
@@ -6,5 +6,5 @@
6
6
  * @returns {string} New name.
7
7
  */
8
8
  export const reformatName = function (pName) {
9
- return pName.toString().replace(/ /g, '_');
9
+ return pName.toString().replace(/ /g, "_");
10
10
  };
@@ -1,93 +1,91 @@
1
1
  const ParserUtil = {};
2
- ParserUtil.postProcessGenbankFeature = function(feat) {
3
- let name = null;
4
- // let nameIndex = null;
5
-
6
- // let hasName = false;
7
- let usingLabel = false;
8
- let usingGene = false;
9
-
10
- for (let j = 0; j < feat.notes.length; j++) {
11
- const note = feat.notes[j];
12
- const key = note.name;
13
- const value = note.value;
14
-
15
- // SET THE LABEL FIELD. DO NOT STORE AS AN ATTRIBUTE
16
-
17
- if (this.isAGenbankFeatureLabel(key)) {
18
- // Priority for name attributes is: 'label' > 'gene' > 'organism'.
19
- // We check to see if the current name is from a lower-priority
20
- // attribute. If it is, we store it as an attribute and then
21
- // replace it with the current higher-priority attribute.
22
-
23
- if (key === "label") {
24
- // Label has top priority.
25
-
26
- name = value;
27
- // nameIndex = j;
28
-
29
- usingLabel = true;
30
- }
31
- else if (key === "gene") {
32
-
33
- // If we're not using the label for the name, use the
34
- // current 'gene' attribute. If we are using label for
35
- // the name, just save the current attribute as a normal
36
- // attribute.
37
- if (!usingLabel) {
38
-
39
- name = value;
40
- // nameIndex = j;
41
-
42
- usingGene = true;
43
- }
44
- }
45
- else if (!usingLabel && !usingGene) {
46
- // If we don't have a label from either a 'gene' or a
47
- // 'label' field, use the current field as the name.
48
-
49
- name = value;
50
- // nameIndex = j;
51
-
52
- }
53
-
54
- // hasName = true;
55
- }
56
- }
57
-
58
- feat.name = name || "";
59
- // if(nameIndex !== null) {
60
- // feat.notes.splice(nameIndex, 1);
61
- // }
62
- //
63
- // if(feat.locations.length > 0) {
64
- // var loc = feat.locations[0];
65
- // feat.start = loc.start;
66
- // feat.end = loc.end;
67
- // }
68
- // else {
69
- // feat.start = null;
70
- // feat.end = null;
71
- // }
72
-
73
- return feat;
2
+ ParserUtil.postProcessGenbankFeature = function (feat) {
3
+ let name = null;
4
+ // let nameIndex = null;
5
+
6
+ // let hasName = false;
7
+ let usingLabel = false;
8
+ let usingGene = false;
9
+
10
+ for (let j = 0; j < feat.notes.length; j++) {
11
+ const note = feat.notes[j];
12
+ const key = note.name;
13
+ const value = note.value;
14
+
15
+ // SET THE LABEL FIELD. DO NOT STORE AS AN ATTRIBUTE
16
+
17
+ if (this.isAGenbankFeatureLabel(key)) {
18
+ // Priority for name attributes is: 'label' > 'gene' > 'organism'.
19
+ // We check to see if the current name is from a lower-priority
20
+ // attribute. If it is, we store it as an attribute and then
21
+ // replace it with the current higher-priority attribute.
22
+
23
+ if (key === "label") {
24
+ // Label has top priority.
25
+
26
+ name = value;
27
+ // nameIndex = j;
28
+
29
+ usingLabel = true;
30
+ } else if (key === "gene") {
31
+ // If we're not using the label for the name, use the
32
+ // current 'gene' attribute. If we are using label for
33
+ // the name, just save the current attribute as a normal
34
+ // attribute.
35
+ if (!usingLabel) {
36
+ name = value;
37
+ // nameIndex = j;
38
+
39
+ usingGene = true;
40
+ }
41
+ } else if (!usingLabel && !usingGene) {
42
+ // If we don't have a label from either a 'gene' or a
43
+ // 'label' field, use the current field as the name.
44
+
45
+ name = value;
46
+ // nameIndex = j;
47
+ }
48
+
49
+ // hasName = true;
50
+ }
51
+ }
52
+
53
+ feat.name = name || "";
54
+ // if(nameIndex !== null) {
55
+ // feat.notes.splice(nameIndex, 1);
56
+ // }
57
+ //
58
+ // if(feat.locations.length > 0) {
59
+ // var loc = feat.locations[0];
60
+ // feat.start = loc.start;
61
+ // feat.end = loc.end;
62
+ // }
63
+ // else {
64
+ // feat.start = null;
65
+ // feat.end = null;
66
+ // }
67
+
68
+ return feat;
74
69
  };
75
70
 
76
-
77
-
78
71
  /**
79
72
  * isAFeatureLabel
80
73
  * @param {string} name Name of a attribute or qualifier
81
74
  * @return {boolean} isALabel
82
75
  */
83
- ParserUtil.isAGenbankFeatureLabel = function(name) {
84
- if (name === "label" || name === "name" || name === "ApEinfo_label" ||
85
- name === "note" || name === "gene" || name === "organism" || name === "locus_tag") {
86
-
87
- return true;
88
- }
89
- else {
90
- return false;
91
- }
76
+ ParserUtil.isAGenbankFeatureLabel = function (name) {
77
+ if (
78
+ name === "label" ||
79
+ name === "name" ||
80
+ name === "ApEinfo_label" ||
81
+ name === "note" ||
82
+ name === "gene" ||
83
+ name === "organism" ||
84
+ name === "locus_tag"
85
+ ) {
86
+ return true;
87
+ } else {
88
+ return false;
89
+ }
92
90
  };
93
91
  export default ParserUtil;
@@ -1,13 +1,12 @@
1
1
  import { cloneDeep, forEach } from "lodash";
2
2
 
3
3
  export default function cleanUpTeselagenJsonForExport(tgJson) {
4
- const seqData = cloneDeep(tgJson);
5
- if (!seqData) return seqData
6
- delete seqData.cutsites;
7
- delete seqData.orfs;
8
- forEach(seqData.translations,(t)=>{
9
- delete t.aminoAcids
10
- })
11
- return seqData
4
+ const seqData = cloneDeep(tgJson);
5
+ if (!seqData) return seqData;
6
+ delete seqData.cutsites;
7
+ delete seqData.orfs;
8
+ forEach(seqData.translations, t => {
9
+ delete t.aminoAcids;
10
+ });
11
+ return seqData;
12
12
  }
13
-
@@ -1,24 +1,24 @@
1
- export const untitledSequenceName = 'Untitled Sequence';
1
+ export const untitledSequenceName = "Untitled Sequence";
2
2
 
3
3
  export const gbDivisions = {
4
- // https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html#GenBankDivisionB
5
- PRI: true, //- primate sequences
6
- ROD: true, //- rodent sequences
7
- MAM: true, //- other mammalian sequences
8
- VRT: true, //- other vertebrate sequences
9
- INV: true, //- invertebrate sequences
10
- PLN: true, //- plant, fungal, and algal sequences
11
- BCT: true, //- bacterial sequences
12
- VRL: true, //- viral sequences
13
- PHG: true, //- bacteriophage sequences
14
- SYN: true, //- synthetic sequences
15
- UNA: true, //- unannotated sequences
16
- EST: true, //- EST sequences (expressed sequence tags)
17
- PAT: true, //- patent sequences
18
- STS: true, //- STS sequences (sequence tagged sites)
19
- GSS: true, //- GSS sequences (genome survey sequences)
20
- HTG: true, //- HTG sequences (high-throughput genomic sequences)
21
- HTC: true, //- unfinished high-throughput cDNA sequencing
22
- ENV: true, //- environmental sampling sequences
23
- CON: true, //- sequence assembly instructions on how to construct contigs from multiple GenBank records.
24
- }
4
+ // https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html#GenBankDivisionB
5
+ PRI: true, //- primate sequences
6
+ ROD: true, //- rodent sequences
7
+ MAM: true, //- other mammalian sequences
8
+ VRT: true, //- other vertebrate sequences
9
+ INV: true, //- invertebrate sequences
10
+ PLN: true, //- plant, fungal, and algal sequences
11
+ BCT: true, //- bacterial sequences
12
+ VRL: true, //- viral sequences
13
+ PHG: true, //- bacteriophage sequences
14
+ SYN: true, //- synthetic sequences
15
+ UNA: true, //- unannotated sequences
16
+ EST: true, //- EST sequences (expressed sequence tags)
17
+ PAT: true, //- patent sequences
18
+ STS: true, //- STS sequences (sequence tagged sites)
19
+ GSS: true, //- GSS sequences (genome survey sequences)
20
+ HTG: true, //- HTG sequences (high-throughput genomic sequences)
21
+ HTC: true, //- unfinished high-throughput cDNA sequencing
22
+ ENV: true, //- environmental sampling sequences
23
+ CON: true //- sequence assembly instructions on how to construct contigs from multiple GenBank records.
24
+ };
@@ -1,4 +1,4 @@
1
- import { isRangeWithinRange } from '@teselagen/range-utils';
1
+ import { isRangeWithinRange } from "@teselagen/range-utils";
2
2
 
3
3
  export default function convertOldSequenceDataToNewDataType(
4
4
  oldTeselagenJson,
@@ -7,7 +7,7 @@ export default function convertOldSequenceDataToNewDataType(
7
7
  if (opts && opts.splitLocations) {
8
8
  //after the file has been parsed, but before it's been saved, check for features with multiple locations and split them
9
9
  oldTeselagenJson &&
10
- oldTeselagenJson.features.forEach(function(feature) {
10
+ oldTeselagenJson.features.forEach(function (feature) {
11
11
  if (feature.locations && feature.locations[0]) {
12
12
  if (feature.locations.length > 1) {
13
13
  for (let i = 1; i < feature.locations.length; i++) {
@@ -31,11 +31,10 @@ export default function convertOldSequenceDataToNewDataType(
31
31
  }
32
32
  delete feature.locations;
33
33
  });
34
-
35
34
  } else {
36
35
  //mange locations
37
36
  oldTeselagenJson &&
38
- oldTeselagenJson.features.forEach(function(feature) {
37
+ oldTeselagenJson.features.forEach(function (feature) {
39
38
  if (feature.locations && feature.locations[0]) {
40
39
  //set the new starts and ends
41
40
  feature.start = feature.locations[0].start;
@@ -53,7 +52,7 @@ export default function convertOldSequenceDataToNewDataType(
53
52
  delete feature.locations;
54
53
  }
55
54
  } else {
56
- delete feature.locations
55
+ delete feature.locations;
57
56
  }
58
57
  }
59
58
  });
@@ -61,4 +60,4 @@ export default function convertOldSequenceDataToNewDataType(
61
60
  if (Array.isArray(oldTeselagenJson.sequence)) {
62
61
  oldTeselagenJson.sequence = oldTeselagenJson.sequence.join("");
63
62
  }
64
- };
63
+ }
@@ -1,14 +1,16 @@
1
1
  import { untitledSequenceName } from "./constants";
2
2
 
3
3
  export default function createInitialSequence(options) {
4
- options = options || {}
5
- return {
6
- messages: [],
7
- success: true,
8
- parsedSequence: {
9
- features: [],
10
- name: (options.fileName && options.fileName.replace(/\.[^/.]+$/, "")) || untitledSequenceName,
11
- sequence: ''
12
- }
13
- };
14
- };
4
+ options = options || {};
5
+ return {
6
+ messages: [],
7
+ success: true,
8
+ parsedSequence: {
9
+ features: [],
10
+ name:
11
+ (options.fileName && options.fileName.replace(/\.[^/.]+$/, "")) ||
12
+ untitledSequenceName,
13
+ sequence: ""
14
+ }
15
+ };
16
+ }
@@ -1,14 +1,12 @@
1
1
  export default function extractFileExtension(name) {
2
- if (typeof name === 'string') {
3
- let ext = "";
4
- const match = name.match(/\.(\w+)$/);
5
- if (match && match[1]) {
6
- ext = match[1];
7
- }
8
- return ext;
9
- }
10
- else {
11
- return "";
12
- }
13
- };
14
-
2
+ if (typeof name === "string") {
3
+ let ext = "";
4
+ const match = name.match(/\.(\w+)$/);
5
+ if (match && match[1]) {
6
+ ext = match[1];
7
+ }
8
+ return ext;
9
+ } else {
10
+ return "";
11
+ }
12
+ }
@@ -1,17 +1,17 @@
1
- import convertOldSequenceDataToNewDataType from './convertOldSequenceDataToNewDataType.js';
1
+ import convertOldSequenceDataToNewDataType from "./convertOldSequenceDataToNewDataType.js";
2
2
 
3
3
  export default function flattenSequenceArray(parsingResultArray, opts) {
4
- if (parsingResultArray) {
5
- if (!Array.isArray(parsingResultArray)) {
6
- //wrap the parsingResult into an array if it isn't one already
7
- parsingResultArray = [parsingResultArray];
8
- }
9
- //should convert the old data type to the new data type (flattened sequence)
10
- parsingResultArray.forEach(function(parsingResult) {
11
- if (parsingResult.success) {
12
- convertOldSequenceDataToNewDataType(parsingResult.parsedSequence, opts);
13
- }
14
- });
4
+ if (parsingResultArray) {
5
+ if (!Array.isArray(parsingResultArray)) {
6
+ //wrap the parsingResult into an array if it isn't one already
7
+ parsingResultArray = [parsingResultArray];
15
8
  }
16
- return parsingResultArray;
17
- };
9
+ //should convert the old data type to the new data type (flattened sequence)
10
+ parsingResultArray.forEach(function (parsingResult) {
11
+ if (parsingResult.success) {
12
+ convertOldSequenceDataToNewDataType(parsingResult.parsedSequence, opts);
13
+ }
14
+ });
15
+ }
16
+ return parsingResultArray;
17
+ }
@@ -1,5 +1,5 @@
1
- import { Buffer } from 'buffer';
2
- import isBrowser from './isBrowser';
1
+ import { Buffer } from "buffer";
2
+ import isBrowser from "./isBrowser";
3
3
 
4
4
  export default function getArrayBufferFromFile(file) {
5
5
  if (!isBrowser) {
@@ -9,11 +9,11 @@ export default function getArrayBufferFromFile(file) {
9
9
 
10
10
  const reader = new window.FileReader();
11
11
  return new Promise((resolve, reject) => {
12
- reader.onload = (e) => {
12
+ reader.onload = e => {
13
13
  resolve(e.target.result);
14
14
  };
15
- reader.onerror = (err) => {
16
- console.error('err:', err);
15
+ reader.onerror = err => {
16
+ console.error("err:", err);
17
17
  reject(err);
18
18
  };
19
19
  reader.readAsArrayBuffer(
@@ -1 +1,2 @@
1
- export default typeof window !== 'undefined' && typeof window.document !== 'undefined';
1
+ export default typeof window !== "undefined" &&
2
+ typeof window.document !== "undefined";
@@ -5,9 +5,9 @@ export default function parseUracilFeatures(sequenceBps, featureList = []) {
5
5
  name: "tg_uracil",
6
6
  strand: 1,
7
7
  start: index,
8
- end: index,
8
+ end: index
9
9
  });
10
10
  return u === "U" ? "T" : "t";
11
11
  });
12
- return cleanedBps
12
+ return cleanedBps;
13
13
  }
@@ -1,5 +1,6 @@
1
1
  export default [
2
- { //primers don't need a pragma because they already have a feature type of primer_bind
2
+ {
3
+ //primers don't need a pragma because they already have a feature type of primer_bind
3
4
  type: "primers"
4
5
  },
5
6
  {
@@ -18,4 +19,4 @@ export default [
18
19
  pragma: "j5_lineage_annotation",
19
20
  type: "lineageAnnotations"
20
21
  }
21
- ]
22
+ ];
@@ -16,7 +16,7 @@ class Match {
16
16
  logValue() {
17
17
  const val = this.value;
18
18
  // if value is an object then just toString it
19
- const isPrimitive = (x) => Object(x) !== x;
19
+ const isPrimitive = x => Object(x) !== x;
20
20
  return isPrimitive(val) || Array.isArray(val) ? val : {}.toString.call(val);
21
21
  }
22
22
 
@@ -39,7 +39,7 @@ export default function searchWholeObjByName(what, where) {
39
39
 
40
40
  const matches = [];
41
41
  matches.log = function () {
42
- this.forEach((m) => m.log());
42
+ this.forEach(m => m.log());
43
43
  };
44
44
 
45
45
  // a non-recursive solution to avoid call stack limits
@@ -77,7 +77,7 @@ export default function searchWholeObjByName(what, where) {
77
77
  path: `${path}.${prop}`,
78
78
  obj: where,
79
79
  prop,
80
- type,
80
+ type
81
81
  });
82
82
  matches.push(match);
83
83
  }
@@ -1,13 +1,14 @@
1
1
  export default function splitStringIntoLines(string) {
2
- let lines = [];
3
- if (string === "") {
4
- return lines;
5
- }
6
- else {
7
- lines = string.split(/\r?\n/);
8
- if (lines.length == 1) { //tnr: not sure why this check is being made... but keeping it in because it is probably doing something
9
- lines = string.split('\\n');
10
- }
11
- return lines;
12
- }
13
- };
2
+ let lines = [];
3
+ if (string === "") {
4
+ return lines;
5
+ } else {
6
+ lines = string.split(/\r?\n/);
7
+ // eslint-disable-next-line eqeqeq
8
+ if (lines.length == 1) {
9
+ //tnr: not sure why this check is being made... but keeping it in because it is probably doing something
10
+ lines = string.split("\\n");
11
+ }
12
+ return lines;
13
+ }
14
+ }