@microbiome-informatics/genome-properties-viewer 0.0.0-stage → 1.0.0-beta.2

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.
@@ -0,0 +1,261 @@
1
+ import * as d3 from "./d3";
2
+ /**
3
+ * Appends a `defs` element in the main group of the viewer.
4
+ * It contains the definitions of the gradients used in th masks around the heatmap
5
+ * @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
6
+ */
7
+ export const createGradient = (viewer) => {
8
+ const uid = `gpv-${Math.random().toString(36).slice(2, 8)}`;
9
+ viewer.heatmapClipId = `${uid}-heatmap`;
10
+ viewer.treeClipId = `${uid}-tree`;
11
+ const defs = viewer.mainGroup.append("defs");
12
+ const gradient_left = defs
13
+ .append("linearGradient")
14
+ .attr("id", "gradientleft")
15
+ .attr("x1", "0%")
16
+ .attr("y1", "0%")
17
+ .attr("x2", "100%")
18
+ .attr("y2", "0%");
19
+ gradient_left
20
+ .append("stop")
21
+ .attr("offset", "85%")
22
+ .attr("stop-color", "#fff")
23
+ .attr("stop-opacity", 1);
24
+ gradient_left
25
+ .append("stop")
26
+ .attr("offset", "100%")
27
+ .attr("stop-color", "#fff")
28
+ .attr("stop-opacity", 0.5);
29
+ const gradient_top = defs
30
+ .append("linearGradient")
31
+ .attr("id", "gradienttop")
32
+ .attr("x1", "0%")
33
+ .attr("y1", "0%")
34
+ .attr("x2", "0%")
35
+ .attr("y2", "100%");
36
+ gradient_top
37
+ .append("stop")
38
+ .attr("offset", "85%")
39
+ .attr("stop-color", "#fff")
40
+ .attr("stop-opacity", 1);
41
+ gradient_top
42
+ .append("stop")
43
+ .attr("offset", "100%")
44
+ .attr("stop-color", "#fff")
45
+ .attr("stop-opacity", 0.5);
46
+ const gradient_right = defs
47
+ .append("linearGradient")
48
+ .attr("id", "gradientright")
49
+ .attr("x1", "0%")
50
+ .attr("y1", "0%")
51
+ .attr("x2", "100%")
52
+ .attr("y2", "0%");
53
+ gradient_right
54
+ .append("stop")
55
+ .attr("offset", "0%")
56
+ .attr("stop-color", "#fff")
57
+ .attr("stop-opacity", 0);
58
+ gradient_right
59
+ .append("stop")
60
+ .attr("offset", "15%")
61
+ .attr("stop-color", "#fff")
62
+ .attr("stop-opacity", 0.5);
63
+ gradient_right
64
+ .append("stop")
65
+ .attr("offset", "35%")
66
+ .attr("stop-color", "#fff")
67
+ .attr("stop-opacity", 1);
68
+ const gradient_bottom = defs
69
+ .append("linearGradient")
70
+ .attr("id", "gradientbottom")
71
+ .attr("x1", "0%")
72
+ .attr("y1", "0%")
73
+ .attr("x2", "0%")
74
+ .attr("y2", "100%");
75
+ gradient_bottom
76
+ .append("stop")
77
+ .attr("offset", "0%")
78
+ .attr("stop-color", "#fff")
79
+ .attr("stop-opacity", 0);
80
+ gradient_bottom
81
+ .append("stop")
82
+ .attr("offset", "15%")
83
+ .attr("stop-color", "#fff")
84
+ .attr("stop-opacity", 0.5);
85
+ gradient_bottom
86
+ .append("stop")
87
+ .attr("offset", "35%")
88
+ .attr("stop-color", "#fff")
89
+ .attr("stop-opacity", 1);
90
+
91
+ viewer.heatmapClipPath = defs
92
+ .append("clipPath")
93
+ .attr("id", viewer.heatmapClipId);
94
+ viewer.heatmapClipPath
95
+ .append("rect")
96
+ .attr("x", viewer.heatmapLeft)
97
+ .attr("y", viewer.treeHeight)
98
+ .attr("width", Math.max(1, viewer.heatmapWidth()))
99
+ .attr("height", Math.max(1, viewer.heatmapHeight()));
100
+ viewer.treeClipPath = defs.append("clipPath").attr("id", viewer.treeClipId);
101
+ viewer.treeClipPath
102
+ .append("rect")
103
+ .attr("x", 0)
104
+ .attr("y", 0)
105
+ .attr("width", Math.max(1, viewer.options.width))
106
+ .attr("height", Math.max(1, viewer.treeHeight));
107
+ };
108
+
109
+ /**
110
+ * Appends a new group element into the mainGroup of the viewer.
111
+ * The group contains masks as rectangles to give the effect of fading around the heatmap
112
+ * @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
113
+ */
114
+ export const drawMasks = (viewer) => {
115
+ viewer.masks = viewer.mainGroup.append("g").attr("class", "masks");
116
+ viewer.masks
117
+ .append("rect")
118
+ .attr("class", "tree-background background")
119
+ .style("fill", "url(#gradienttop)")
120
+ .attr("x", 0)
121
+ .attr("y", 0)
122
+ .attr("width", viewer.options.width)
123
+ .attr("height", viewer.treeHeight);
124
+ viewer.masks
125
+ .append("rect")
126
+ .attr("class", "label-background background")
127
+ .style("fill", "url(#gradientleft)")
128
+ .attr("x", 0)
129
+ .attr("y", 0)
130
+ .attr("width", viewer.labelWidth)
131
+ .attr("height", viewer.options.height);
132
+ viewer.masks
133
+ .append("rect")
134
+ .attr("class", "total-background background")
135
+ .style("fill", "url(#gradientright)")
136
+ .attr(
137
+ "x",
138
+ viewer.options.width - viewer.options.dimensions.total.short_side * 1.2
139
+ )
140
+ .attr("y", 0)
141
+ .attr("width", viewer.options.dimensions.total.short_side * 1.2)
142
+ .attr("height", viewer.options.height);
143
+ viewer.masks
144
+ .append("rect")
145
+ .attr("class", "bottom-background background")
146
+ .style("fill", "url(#gradientbottom)")
147
+ .attr("x", 0)
148
+ .attr(
149
+ "y",
150
+ viewer.options.height - viewer.options.dimensions.total.short_side * 1.2
151
+ )
152
+ .attr("width", viewer.options.width)
153
+ .attr("height", viewer.options.dimensions.total.short_side * 1.2);
154
+ };
155
+
156
+ /**
157
+ * Update the size and position of the masks
158
+ * @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
159
+ */
160
+ export const updateMasks = (viewer) => {
161
+ viewer.masks
162
+ .select(".tree-background")
163
+ .attr("width", viewer.options.width)
164
+ .attr("height", viewer.treeHeight);
165
+ viewer.masks
166
+ .select(".label-background")
167
+ .attr("width", viewer.heatmapAnchor)
168
+ .attr("height", viewer.options.height);
169
+ viewer.masks
170
+ .select(".total-background")
171
+ .attr(
172
+ "x",
173
+ viewer.options.width - viewer.options.dimensions.total.short_side * 1.2
174
+ )
175
+ .attr("width", viewer.options.dimensions.total.short_side * 1.2)
176
+ .attr("height", viewer.options.height);
177
+ viewer.masks
178
+ .select(".bottom-background")
179
+ .attr(
180
+ "y",
181
+ viewer.options.height - viewer.options.dimensions.total.short_side * 1.2
182
+ )
183
+ .attr("width", viewer.options.width)
184
+ .attr("height", viewer.options.dimensions.total.short_side * 1.2);
185
+ if (viewer.heatmapClipPath) {
186
+ viewer.heatmapClipPath
187
+ .select("rect")
188
+ .attr("x", viewer.heatmapLeft)
189
+ .attr("y", viewer.heatmapTop)
190
+ .attr("width", viewer.heatmapWidth())
191
+ .attr("height", viewer.heatmapHeight());
192
+ }
193
+ if (viewer.treeClipPath) {
194
+ viewer.treeClipPath
195
+ .select("rect")
196
+ .attr("x", 0)
197
+ .attr("y", 0)
198
+ .attr("width", viewer.options.width)
199
+ .attr("height", viewer.treeHeight);
200
+ }
201
+ viewer.mainGroup
202
+ .select(".height-dragger")
203
+ .attr("transform", `translate(0, ${viewer.treeHeight})`);
204
+ viewer.mainGroup.select(".height-sizer").attr("x2", viewer.options.width);
205
+ };
206
+
207
+ /**
208
+ * Draws a draggable area to redefine the height assigned to the taxonomy tree.
209
+ * @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
210
+ */
211
+ export const drawDragArea = (viewer) => {
212
+ const yLimit = 80;
213
+ let dy = 0;
214
+ const g = viewer.mainGroup
215
+ .append("g")
216
+ .attr("class", "height-dragger")
217
+ .attr("transform", `translate(0, ${viewer.treeHeight})`)
218
+ .call(
219
+ d3
220
+ .drag()
221
+ .on("drag", (event) => {
222
+ const treeSpace = viewer.options.dimensions.tree.width;
223
+ dy = Math.min(
224
+ Math.max(-treeSpace + event.y, yLimit - treeSpace),
225
+ viewer.options.height - treeSpace - 80
226
+ );
227
+ g.attr("transform", `translate(0, ${dy + treeSpace})`);
228
+ })
229
+ .on("end", () => {
230
+ const treeSpace = viewer.options.dimensions.tree.width;
231
+ const new_height = treeSpace + dy;
232
+ if (Number.isNaN(new_height)) return;
233
+ viewer.gp_taxonomy.dipatcher.call(
234
+ "changeWidth",
235
+ viewer.gp_taxonomy,
236
+ new_height
237
+ );
238
+ g.attr("transform", `translate(0, ${new_height})`);
239
+ viewer.gp_taxonomy.height = new_height;
240
+ viewer.gp_taxonomy.update_tree();
241
+ })
242
+ );
243
+ const side = viewer.options.cell_side / 2;
244
+ g.append("rect")
245
+ .attr("x", 0)
246
+ .attr("y", -side / 2)
247
+ .attr("width", side * 2)
248
+ .attr("height", side)
249
+ .style("fill", "transparent");
250
+ for (let index = -1; index < 2; index++) {
251
+ g.append("line")
252
+ .attr("x1", 0)
253
+ .attr("x2", side * 2)
254
+ .attr("y1", (index * side) / 2)
255
+ .attr("y2", (index * side) / 2)
256
+ .style("stroke", "#333");
257
+ }
258
+ g.append("line")
259
+ .attr("class", "height-sizer")
260
+ .attr("x2", viewer.options.width);
261
+ };
@@ -0,0 +1,402 @@
1
+ import { tsvParseRows, select } from "./d3";
2
+
3
+ const isLineOK = (line) => line.length === 3;
4
+
5
+ const mergeObjectToData = (data, obj) => {
6
+ for (const gp of Object.keys(data)) {
7
+ for (const newOrg of Object.keys((obj[gp] && obj[gp].values) || {})) {
8
+ if (newOrg !== "TOTAL") data[gp].values[newOrg] = obj[gp].values[newOrg];
9
+ }
10
+ const stepsObj = ((obj[gp] && obj[gp].steps) || []).reduce((agg, v) => {
11
+ agg[v.step] = v;
12
+ return agg;
13
+ }, {});
14
+ for (const step of data[gp].steps) {
15
+ for (const newOrg of Object.keys(stepsObj[step.step].values)) {
16
+ step.values[newOrg] = stepsObj[step.step].values[newOrg];
17
+ }
18
+ }
19
+ }
20
+ };
21
+
22
+ export const enableSpeciesFromPreLoaded = (
23
+ viewer,
24
+ taxId,
25
+ isFromFile = false,
26
+ shouldUpdate = true
27
+ ) => {
28
+ let tax_id = Number(taxId);
29
+ if (Number.isNaN(tax_id)) tax_id = taxId;
30
+ viewer.gp_taxonomy.set_organisms_loaded(tax_id, isFromFile);
31
+ viewer.organisms.push(tax_id);
32
+ viewer.organism_totals[tax_id] = { YES: 0, NO: 0, PARTIAL: 0 };
33
+ if (shouldUpdate) viewer.update_viewer(500);
34
+ };
35
+
36
+ export const loadGenomePropertiesText = (
37
+ viewer,
38
+ label,
39
+ text,
40
+ isFromFile = false
41
+ ) => {
42
+ try {
43
+ const obj = JSON.parse(text);
44
+ mergeObjectToData(viewer.data, obj);
45
+ const objOrgs = Object.keys(Object.values(obj)[0].values).filter(
46
+ (x) => x !== "TOTAL"
47
+ );
48
+ for (const org of objOrgs) {
49
+ enableSpeciesFromPreLoaded(viewer, org, isFromFile);
50
+ }
51
+ } catch (e) {
52
+ // eslint-disable-next-line no-console
53
+ console.warn("File is not JSON. Trying to parse it as TSV now.");
54
+ const wl = viewer.whitelist;
55
+ let tax_id = Number(label);
56
+ if (isFromFile) tax_id = label;
57
+ viewer.organisms.push(tax_id);
58
+ viewer.organism_totals[tax_id] = { YES: 0, NO: 0, PARTIAL: 0 };
59
+ let allLinesAreOK = true;
60
+ const errorLines = [];
61
+ tsvParseRows(text, (d, i) => {
62
+ if (!isLineOK(d)) {
63
+ allLinesAreOK = false;
64
+ errorLines.push([i, d]);
65
+ }
66
+ if (wl && wl.indexOf(d[0]) === -1) return;
67
+ if (!(d[0] in viewer.data))
68
+ viewer.data[d[0]] = {
69
+ property: d[0],
70
+ name: d[1],
71
+ values: { TOTAL: { YES: 0, NO: 0, PARTIAL: 0 } },
72
+ parent_top_properties: viewer.gp_hierarchy.get_top_level_gp_by_id(
73
+ d[0]
74
+ ),
75
+ // TODO: Replace for actual steps information
76
+ steps: d[0]
77
+ .slice(7)
78
+ .split("")
79
+ .filter((x) => x !== "0")
80
+ .reduce((agg) => {
81
+ agg.push({
82
+ step: agg.length + 1,
83
+ values: {},
84
+ });
85
+ return agg;
86
+ }, []),
87
+ isShowingSteps: false,
88
+ };
89
+ if (tax_id in viewer.data[d[0]].values) return;
90
+ viewer.data[d[0]].values[tax_id] = d[2];
91
+ viewer.data[d[0]].values.TOTAL[d[2]]++;
92
+ viewer.organism_totals[tax_id][d[2]]++;
93
+ // TODO: Replace for actual steps information
94
+ viewer.data[d[0]].steps.forEach(
95
+ (step) => (step.values[tax_id] = Math.random() > 0.5)
96
+ );
97
+ });
98
+ if (allLinesAreOK) {
99
+ viewer.gp_taxonomy.set_organisms_loaded(tax_id, isFromFile);
100
+ if (!viewer.propsOrder)
101
+ viewer.propsOrder = Object.keys(viewer.data).sort();
102
+ viewer.update_viewer(500);
103
+ } else {
104
+ delete viewer.organisms[tax_id];
105
+ delete viewer.organism_totals[tax_id];
106
+ throw new Error(
107
+ `File didn't load. The following lines have errors:${errorLines
108
+ .map((l) => l.join(": "))
109
+ .join("\n")}`
110
+ );
111
+ }
112
+ }
113
+ };
114
+
115
+ export const preloadSpecies = (viewer, data) => {
116
+ viewer.data = data;
117
+ Object.values(viewer.data).forEach((gp) => {
118
+ gp.parent_top_properties = viewer.gp_hierarchy.get_top_level_gp_by_id(
119
+ gp.property
120
+ );
121
+ gp.isShowingSteps = false;
122
+ });
123
+ };
124
+
125
+ export const removeGenomePropertiesFile = (viewer, id) => {
126
+ let tax_id = Number(id);
127
+ const isFromFile = Number.isNaN(tax_id);
128
+ if (isFromFile) tax_id = id;
129
+ delete viewer.organism_totals[tax_id];
130
+ const i = viewer.organisms.indexOf(tax_id);
131
+ viewer.organisms.splice(i, 1);
132
+ viewer.gp_taxonomy.remove_organism_loaded(tax_id, isFromFile);
133
+ viewer.update_viewer(500);
134
+ };
135
+
136
+ function concat(arrays) {
137
+ let i = 0;
138
+ let n = 0;
139
+ for (const a of arrays) n += a.length;
140
+ const newArray = new Uint8Array(n);
141
+ for (const a of arrays) {
142
+ newArray.set(a, i);
143
+ i += a.length;
144
+ }
145
+ return newArray.buffer;
146
+ }
147
+ export class FileGetter {
148
+ constructor({ element = "body", viewer }) {
149
+ this.base = select(element);
150
+ this.files = {};
151
+ this.isActive = false;
152
+ this.viewer = viewer;
153
+ this.activeGauge = 0;
154
+ this.activeGauges = [];
155
+ this.progressTimer = setInterval(() => {
156
+ const n = this.activeGauges.length;
157
+ if (n) this.activeGauge = (this.activeGauge + 1) % n;
158
+ }, 3000);
159
+ }
160
+
161
+ destroy() {
162
+ this.isActive = false;
163
+ if (this.progressTimer) {
164
+ clearInterval(this.progressTimer);
165
+ this.progressTimer = null;
166
+ }
167
+ }
168
+
169
+ getJSON(path) {
170
+ return this.getText(path, true);
171
+ }
172
+
173
+ async getText(path, shouldParseAsJSON = false) {
174
+ if (this.files[path]) return this.files[path].request;
175
+ this.files[path] = {
176
+ loading: true,
177
+ path,
178
+ };
179
+ const { modal } = this.viewer;
180
+ if (!this.isActive) this.createProgressContent(modal);
181
+ // this.activeGauge = path;
182
+ const response = await fetch(path);
183
+ if (this.viewer.destroyed) return null;
184
+ this.files[path].request = response;
185
+ const total = response.headers.get("content-length");
186
+ const reader = response.body && response.body.getReader();
187
+ const values = [];
188
+ let loaded = 0;
189
+ let responseAsArrayBuffer = null;
190
+ if (!reader) {
191
+ responseAsArrayBuffer = await response.arrayBuffer();
192
+ loaded = responseAsArrayBuffer.byteLength;
193
+ this.files[path].progress = 1;
194
+ } else {
195
+ // eslint-disable-next-line no-constant-condition
196
+ while (true) {
197
+ // eslint-disable-next-line no-await-in-loop
198
+ const { done, value } = await reader.read();
199
+ if (done) break;
200
+ if (this.viewer.destroyed) return null;
201
+ loaded += value.length;
202
+ this.files[path].progress = total ? loaded / total : null;
203
+ this.files[path].event = {
204
+ total,
205
+ loaded,
206
+ };
207
+ this.updateProgress();
208
+ values.push(value);
209
+ }
210
+ responseAsArrayBuffer = concat(values);
211
+ }
212
+ const codeUnits = new Uint8Array(responseAsArrayBuffer);
213
+ let text = "";
214
+ for (let i = 0; i < codeUnits.length; i++) {
215
+ text += String.fromCharCode(codeUnits[i]);
216
+ }
217
+ this.files[path].loading = false;
218
+ this.files[path].data = shouldParseAsJSON ? JSON.parse(text) : text;
219
+
220
+ if (Object.values(this.files).every((file) => !file.loading)) {
221
+ modal.setVisibility(false);
222
+ this.isActive = false;
223
+ }
224
+
225
+ return this.files[path].data;
226
+ }
227
+
228
+ createProgressContent(modal) {
229
+ modal.showContent("", true);
230
+ this.progressContent = modal.getContentElement();
231
+ this.progressContent.append("h1").text("Loading Assets");
232
+ const pp = this.progressContent
233
+ .append("div")
234
+ .attr("class", "progress-panel");
235
+ this.gaugeDiv = pp.append("div").attr("class", "gauges-panel");
236
+ this.gaugeSVG = this.gaugeDiv
237
+ .append("svg")
238
+ .attr("width", "10vw")
239
+ .attr("height", "10vw")
240
+ .attr("class", "gauges");
241
+ this.gaugeLabel = this.gaugeDiv
242
+ .append("div")
243
+ .attr("class", "gauge-label")
244
+ .text("...");
245
+ this.requestsList = pp.append("div").attr("class", "requests-list");
246
+ this.isActive = true;
247
+ }
248
+
249
+ updateProgress() {
250
+ if (!this.isActive) return;
251
+
252
+ const files = Object.values(this.files);
253
+ const total = {
254
+ path: "TOTAL",
255
+ progress:
256
+ files.reduce((agg, v) => agg + (v.progress || 0), 0) / files.length,
257
+ };
258
+ this.activeGauges = files
259
+ .concat(total)
260
+ .filter((f) => f.progress === null || f.progress < 1);
261
+ this.gaugeLabel.text(
262
+ this.activeGauges[this.activeGauge]
263
+ ? this.activeGauges[this.activeGauge].path
264
+ : ""
265
+ );
266
+
267
+ const requestDiv = this.requestsList
268
+ .selectAll("div.request")
269
+ .data(files, (d) => d.path);
270
+ requestDiv
271
+ .enter()
272
+ .append("div")
273
+ .attr("class", "request")
274
+ .merge(requestDiv)
275
+ .text(
276
+ (d) => `${d.path}:
277
+ ${d.progress ? (d.progress * 100).toFixed(1) : " ? "}%
278
+ - ${d.event ? d.event.loaded : "_"}/${(d.event && d.event.total) || "?"}
279
+ `
280
+ );
281
+
282
+ const gaugeNode = this.gaugeSVG && this.gaugeSVG.node();
283
+ if (!gaugeNode) return;
284
+ const w = gaugeNode.getBoundingClientRect().width || 0;
285
+ if (w <= 0) return;
286
+
287
+ const gauges = this.gaugeSVG.selectAll("g.gauge").data(this.activeGauges);
288
+ const current = Number.isFinite(this.activeGauge) ? this.activeGauge : 0;
289
+
290
+ const gauge = gauges
291
+ .enter()
292
+ .append("g")
293
+ .attr("class", "gauge")
294
+ .attr("transform", (d, i) => `translate(0,${w * (i - current)})`);
295
+
296
+ const r = Math.max(0, w / 2 - 10);
297
+
298
+ const circunferencia = 2 * Math.PI * r;
299
+ gauge
300
+ .append("circle")
301
+ .attr("class", "gauge-bg")
302
+ .attr("r", r)
303
+ .attr("cx", w / 2)
304
+ .attr("cy", w / 2);
305
+ gauge
306
+ .append("circle")
307
+ .attr("class", "gauge-val")
308
+ .attr("stroke-linecap", "round")
309
+ .attr("stroke-dasharray", circunferencia)
310
+ .attr("stroke-dashoffset", circunferencia)
311
+ .attr("r", r)
312
+ .attr("transform", `rotate(90,${w / 2},${w / 2})`)
313
+ .attr("cx", w / 2)
314
+ .attr("cy", w / 2);
315
+
316
+ gauge
317
+ .append("text")
318
+ .attr("class", "percentage")
319
+ .attr("x", w / 2)
320
+ .attr("y", w / 2);
321
+
322
+ gauges
323
+ .transition()
324
+ .attr("transform", (d, i) => `translate(0,${w * (i - current)})`);
325
+ gauges
326
+ .select(".percentage")
327
+ .text((d) => (d.progress ? `${(d.progress * 100).toFixed(1)}%` : "?"));
328
+ gauges
329
+ .select(".gauge-val")
330
+ .classed("uncertain", (d) => d.progress === null)
331
+ .attr("stroke-dashoffset", (d) =>
332
+ d.progress === null
333
+ ? circunferencia / 2
334
+ : circunferencia * (1 - d.progress)
335
+ );
336
+ }
337
+ }
338
+ export const loadGenomePropertiesFile = (viewer, tax_id) => {
339
+ if (viewer.organisms.indexOf(Number(tax_id)) !== -1) return;
340
+ fetch(viewer.options.server.replace("{}", tax_id))
341
+ .then((response) => {
342
+ if (!response.ok)
343
+ throw new Error(`${response.status} ${response.statusText}`);
344
+ return response.text();
345
+ })
346
+ .then((text) => {
347
+ loadGenomePropertiesText(viewer, tax_id, text);
348
+ viewer.update_viewer(500);
349
+ });
350
+ };
351
+
352
+ function isIpproLine(line) {
353
+ const parts = line.split("\t");
354
+ return !(parts.length < 11 || parts[1].length !== 32);
355
+ }
356
+
357
+ export const uploadLocalGPFile = (viewer, fileToRead) => {
358
+ const reader = new FileReader();
359
+ reader.fileToRead = fileToRead;
360
+ reader.onload = (evt) => {
361
+ try {
362
+ const firstline = evt.target.result.split("\n")[0];
363
+ if (isIpproLine(firstline)) {
364
+ viewer.modal.showContent(
365
+ "<h3><div class='loading'>◉</div>Calculation Genome Properties from InterProScan Data</h3>",
366
+ true
367
+ );
368
+
369
+ fetch(viewer.options.gp_server, {
370
+ method: "POST",
371
+ body: `ipproname=${reader.fileToRead.name}&ipprotsv=${evt.target.result}`,
372
+ headers: new Headers({
373
+ "Content-Type": "application/x-www-form-urlencoded",
374
+ "Access-Control-Request-Method": "POST",
375
+ "Access-Control-Request-Headers": "X-PINGOTHER, Content-Type",
376
+ }),
377
+ })
378
+ .then((response) => response.text())
379
+ .then((x) => {
380
+ viewer.loadGenomePropertiesText(reader.fileToRead.name, x);
381
+ viewer.modal.setVisibility(false);
382
+ })
383
+ .catch(() => {
384
+ viewer.modal.showContent(
385
+ "<h3><div class='error'>Server Error processing the file</div></h3>",
386
+ false
387
+ );
388
+ });
389
+ } else {
390
+ viewer.loadGenomePropertiesText(
391
+ reader.fileToRead.name,
392
+ evt.target.result
393
+ );
394
+ }
395
+ } catch (e) {
396
+ // eslint-disable-next-line no-console
397
+ console.error(e);
398
+ }
399
+ document.getElementById("newfile").value = null;
400
+ };
401
+ reader.readAsText(fileToRead);
402
+ };