@jbrowse/plugin-comparative-adapters 3.6.2 → 3.6.4

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.
@@ -7,9 +7,9 @@ const configuration_1 = require("@jbrowse/core/configuration");
7
7
  const BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
8
8
  const util_1 = require("@jbrowse/core/util");
9
9
  const io_1 = require("@jbrowse/core/util/io");
10
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
10
11
  const rxjs_1 = require("@jbrowse/core/util/rxjs");
11
12
  const SyntenyFeature_1 = __importDefault(require("../SyntenyFeature"));
12
- const util_2 = require("../util");
13
13
  function createBlastLineParser(columns) {
14
14
  const columnNames = columns.trim().split(' ');
15
15
  const qseqidIndex = columnNames.indexOf('qseqid');
@@ -85,7 +85,16 @@ class BlastTabularAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
85
85
  }
86
86
  async setup(opts) {
87
87
  const columns = (0, configuration_1.readConfObject)(this.config, 'columns');
88
- return (0, util_2.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)((0, configuration_1.readConfObject)(this.config, 'blastTableLocation'), this.pluginManager), opts), createBlastLineParser(columns), opts);
88
+ const lines = [];
89
+ const cb = createBlastLineParser(columns);
90
+ (0, parseLineByLine_1.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)((0, configuration_1.readConfObject)(this.config, 'blastTableLocation'), this.pluginManager), opts), line => {
91
+ const res = cb(line);
92
+ if (res) {
93
+ lines.push(res);
94
+ }
95
+ return true;
96
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
97
+ return lines;
89
98
  }
90
99
  async hasDataForRefName() {
91
100
  return true;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.paf_chain2paf = paf_chain2paf;
4
- const util_1 = require("@jbrowse/core/util");
4
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
5
5
  function generate_record(qname, qstart, qend, qstrand, tname, tstart, tend, cigar, numMatches) {
6
6
  return {
7
7
  qname,
@@ -32,24 +32,9 @@ function paf_chain2paf(buffer, opts) {
32
32
  let num_matches = 0;
33
33
  let cigar = '';
34
34
  const records = [];
35
- let blockStart = 0;
36
- const decoder = new TextDecoder('utf8');
37
- let s = performance.now();
38
- let i = 0;
39
- while (blockStart < buffer.length) {
40
- if (i++ % 10000 === 0 && performance.now() - s > 50) {
41
- statusCallback(`Loading ${(0, util_1.getProgressDisplayStr)(blockStart, buffer.length)}`);
42
- s = performance.now();
43
- }
44
- const n = buffer.indexOf(10, blockStart);
45
- if (n === -1) {
46
- break;
47
- }
48
- const b = buffer.subarray(blockStart, n);
49
- const line = decoder.decode(b).trim();
50
- blockStart = n + 1;
35
+ (0, parseLineByLine_1.parseLineByLine)(buffer, line => {
51
36
  if (!line || line.startsWith('#')) {
52
- continue;
37
+ return true;
53
38
  }
54
39
  const l_vec = line.split(/[ \t]+/);
55
40
  if (l_vec[0] === 'chain') {
@@ -87,7 +72,8 @@ function paf_chain2paf(buffer, opts) {
87
72
  cigar += `${diff_in_target}D`;
88
73
  }
89
74
  }
90
- }
75
+ return true;
76
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
91
77
  if (cigar) {
92
78
  generate_record(q_name, q_start, q_end, q_strand, t_name, t_start, t_end, cigar, num_matches);
93
79
  }
@@ -9,12 +9,6 @@ export default class DeltaAdapter extends PAFAdapter {
9
9
  tstart: number;
10
10
  tend: number;
11
11
  strand: number;
12
- extra: {
13
- numMatches: number;
14
- blockLen: number;
15
- mappingQual: number;
16
- NM: number;
17
- cg: string;
18
- };
12
+ extra: Record<string, unknown>;
19
13
  }[]>;
20
14
  }
@@ -7,11 +7,5 @@ export declare function paf_delta2paf(buffer: Uint8Array, opts?: BaseOptions): {
7
7
  tstart: number;
8
8
  tend: number;
9
9
  strand: number;
10
- extra: {
11
- numMatches: number;
12
- blockLen: number;
13
- mappingQual: number;
14
- NM: number;
15
- cg: string;
16
- };
10
+ extra: Record<string, unknown>;
17
11
  }[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.paf_delta2paf = paf_delta2paf;
4
- const util_1 = require("@jbrowse/core/util");
4
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
5
5
  function paf_delta2paf(buffer, opts) {
6
6
  const { statusCallback = () => { } } = opts || {};
7
7
  let rname = '';
@@ -18,113 +18,94 @@ function paf_delta2paf(buffer, opts) {
18
18
  let seen_gt = false;
19
19
  const records = [];
20
20
  const regex = new RegExp(/^>(\S+)\s+(\S+)\s+(\d+)\s+(\d+)/);
21
- let blockStart = 0;
22
- let i = 0;
23
- let j = 0;
24
- const decoder = new TextDecoder('utf8');
25
- let s = performance.now();
26
- while (blockStart < buffer.length) {
27
- if (j++ % 10000 === 0 && performance.now() - s > 50) {
28
- statusCallback(`Loading ${(0, util_1.getProgressDisplayStr)(blockStart, buffer.length)}`);
29
- s = performance.now();
21
+ (0, parseLineByLine_1.parseLineByLine)(buffer, line => {
22
+ const m = regex.exec(line);
23
+ if (m !== null) {
24
+ rname = m[1];
25
+ qname = m[2];
26
+ seen_gt = true;
27
+ return true;
30
28
  }
31
- const n = buffer.indexOf(10, blockStart);
32
- if (n === -1) {
33
- break;
29
+ if (!seen_gt) {
30
+ return true;
34
31
  }
35
- const b = buffer.subarray(blockStart, n);
36
- const line = decoder.decode(b).trim();
37
- blockStart = n + 1;
38
- i++;
39
- if (line) {
40
- const m = regex.exec(line);
41
- if (m !== null) {
42
- rname = m[1];
43
- qname = m[2];
44
- seen_gt = true;
45
- continue;
46
- }
47
- if (!seen_gt) {
48
- continue;
32
+ const t = line.split(' ');
33
+ if (t.length === 7) {
34
+ const t0 = +t[0];
35
+ const t1 = +t[1];
36
+ const t2 = +t[2];
37
+ const t3 = +t[3];
38
+ const t4 = +t[4];
39
+ strand = (t0 < t1 && t2 < t3) || (t0 > t1 && t2 > t3) ? 1 : -1;
40
+ rs = +Math.min(t0, t1) - 1;
41
+ re = +Math.max(t1, t0);
42
+ qs = +Math.min(t2, t3) - 1;
43
+ qe = +Math.max(t3, t2);
44
+ x = y = 0;
45
+ NM = t4;
46
+ cigar = [];
47
+ }
48
+ else if (t.length === 1) {
49
+ const d = +t[0];
50
+ if (d === 0) {
51
+ let blen = 0;
52
+ const cigar_str = [];
53
+ if (re - rs - x !== qe - qs - y) {
54
+ throw new Error(`inconsistent alignment on line ${line}`);
55
+ }
56
+ cigar.push((re - rs - x) << 4);
57
+ for (const entry of cigar) {
58
+ const rlen = entry >> 4;
59
+ blen += rlen;
60
+ cigar_str.push(rlen + 'MID'.charAt(entry & 0xf));
61
+ }
62
+ records.push({
63
+ qname,
64
+ qstart: qs,
65
+ qend: qe,
66
+ tname: rname,
67
+ tstart: rs,
68
+ tend: re,
69
+ strand,
70
+ extra: {
71
+ numMatches: blen - NM,
72
+ blockLen: blen,
73
+ mappingQual: 0,
74
+ NM,
75
+ cg: cigar_str.join(''),
76
+ },
77
+ });
49
78
  }
50
- const t = line.split(' ');
51
- if (t.length === 7) {
52
- const t0 = +t[0];
53
- const t1 = +t[1];
54
- const t2 = +t[2];
55
- const t3 = +t[3];
56
- const t4 = +t[4];
57
- strand = (t0 < t1 && t2 < t3) || (t0 > t1 && t2 > t3) ? 1 : -1;
58
- rs = +Math.min(t0, t1) - 1;
59
- re = +Math.max(t1, t0);
60
- qs = +Math.min(t2, t3) - 1;
61
- qe = +Math.max(t3, t2);
62
- x = y = 0;
63
- NM = t4;
64
- cigar = [];
79
+ else if (d > 0) {
80
+ const l = d - 1;
81
+ x += l + 1;
82
+ y += l;
83
+ if (l > 0) {
84
+ cigar.push(l << 4);
85
+ }
86
+ if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 2) {
87
+ cigar[cigar.length - 1] += 1 << 4;
88
+ }
89
+ else {
90
+ cigar.push((1 << 4) | 2);
91
+ }
65
92
  }
66
- else if (t.length === 1) {
67
- const d = +t[0];
68
- if (d === 0) {
69
- let blen = 0;
70
- const cigar_str = [];
71
- if (re - rs - x !== qe - qs - y) {
72
- throw new Error(`inconsistent alignment on line ${i}`);
73
- }
74
- cigar.push((re - rs - x) << 4);
75
- for (const entry of cigar) {
76
- const rlen = entry >> 4;
77
- blen += rlen;
78
- cigar_str.push(rlen + 'MID'.charAt(cigar[i] & 0xf));
79
- }
80
- records.push({
81
- qname,
82
- qstart: qs,
83
- qend: qe,
84
- tname: rname,
85
- tstart: rs,
86
- tend: re,
87
- strand,
88
- extra: {
89
- numMatches: blen - NM,
90
- blockLen: blen,
91
- mappingQual: 0,
92
- NM,
93
- cg: cigar_str.join(''),
94
- },
95
- });
93
+ else {
94
+ const l = -d - 1;
95
+ x += l;
96
+ y += l + 1;
97
+ if (l > 0) {
98
+ cigar.push(l << 4);
96
99
  }
97
- else if (d > 0) {
98
- const l = d - 1;
99
- x += l + 1;
100
- y += l;
101
- if (l > 0) {
102
- cigar.push(l << 4);
103
- }
104
- if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 2) {
105
- cigar[cigar.length - 1] += 1 << 4;
106
- }
107
- else {
108
- cigar.push((1 << 4) | 2);
109
- }
100
+ if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 1) {
101
+ cigar[cigar.length - 1] += 1 << 4;
110
102
  }
111
103
  else {
112
- const l = -d - 1;
113
- x += l;
114
- y += l + 1;
115
- if (l > 0) {
116
- cigar.push(l << 4);
117
- }
118
- if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 1) {
119
- cigar[cigar.length - 1] += 1 << 4;
120
- }
121
- else {
122
- cigar.push((1 << 4) | 1);
123
- }
104
+ cigar.push((1 << 4) | 1);
124
105
  }
125
106
  }
126
107
  }
127
- }
128
- statusCallback('');
108
+ return true;
109
+ }, statusCallback);
129
110
  return records;
130
111
  }
@@ -5,11 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const util_1 = require("@jbrowse/core/util");
7
7
  const io_1 = require("@jbrowse/core/util/io");
8
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
8
9
  const PAFAdapter_1 = __importDefault(require("../PAFAdapter/PAFAdapter"));
9
- const util_2 = require("../util");
10
10
  class MashMapAdapter extends PAFAdapter_1.default {
11
11
  async setupPre(opts) {
12
- return (0, util_2.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(this.getConf('outLocation'), this.pluginManager), opts), parseMashMapLine, opts);
12
+ const lines = [];
13
+ (0, parseLineByLine_1.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(this.getConf('outLocation'), this.pluginManager), opts), line => {
14
+ lines.push(parseMashMapLine(line));
15
+ return true;
16
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
17
+ return lines;
13
18
  }
14
19
  }
15
20
  exports.default = MashMapAdapter;
@@ -7,6 +7,7 @@ const configuration_1 = require("@jbrowse/core/configuration");
7
7
  const BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
8
8
  const util_1 = require("@jbrowse/core/util");
9
9
  const io_1 = require("@jbrowse/core/util/io");
10
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
10
11
  const range_1 = require("@jbrowse/core/util/range");
11
12
  const rxjs_1 = require("@jbrowse/core/util/rxjs");
12
13
  const plugin_alignments_1 = require("@jbrowse/plugin-alignments");
@@ -25,7 +26,12 @@ class PAFAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
25
26
  return this.setupP;
26
27
  }
27
28
  async setupPre(opts) {
28
- return (0, util_2.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(this.getConf('pafLocation'), this.pluginManager), opts), util_2.parsePAFLine, opts);
29
+ const lines = [];
30
+ (0, parseLineByLine_1.parseLineByLine)(await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(this.getConf('pafLocation'), this.pluginManager), opts), line => {
31
+ lines.push((0, util_2.parsePAFLine)(line));
32
+ return true;
33
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
34
+ return lines;
29
35
  }
30
36
  async hasDataForRefName() {
31
37
  return true;
package/dist/util.d.ts CHANGED
@@ -11,7 +11,6 @@ export declare function parseBed(text: string): Map<string | undefined, {
11
11
  }>;
12
12
  export declare function readFile(file: GenericFilehandle, opts?: BaseOptions): Promise<string>;
13
13
  export declare function zip(a: number[], b: number[]): [number, number][];
14
- export declare function parseLineByLine<T>(buffer: Uint8Array, cb: (line: string) => T | undefined, opts?: BaseOptions): T[];
15
14
  export declare function parsePAFLine(line: string): PAFRecord;
16
15
  export declare function flipCigar(cigar: string[]): (string | undefined)[];
17
16
  export declare function swapIndelCigar(cigar: string): string;
package/dist/util.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBed = parseBed;
4
4
  exports.readFile = readFile;
5
5
  exports.zip = zip;
6
- exports.parseLineByLine = parseLineByLine;
7
6
  exports.parsePAFLine = parsePAFLine;
8
7
  exports.flipCigar = flipCigar;
9
8
  exports.swapIndelCigar = swapIndelCigar;
@@ -33,35 +32,6 @@ async function readFile(file, opts) {
33
32
  function zip(a, b) {
34
33
  return a.map((e, i) => [e, b[i]]);
35
34
  }
36
- function parseLineByLine(buffer, cb, opts) {
37
- const { statusCallback = () => { } } = opts || {};
38
- let blockStart = 0;
39
- const entries = [];
40
- const decoder = new TextDecoder('utf8');
41
- let i = 0;
42
- let s = performance.now();
43
- while (blockStart < buffer.length) {
44
- const n = buffer.indexOf(10, blockStart);
45
- if (n === -1) {
46
- break;
47
- }
48
- const b = buffer.subarray(blockStart, n);
49
- const line = decoder.decode(b).trim();
50
- if (line) {
51
- const entry = cb(line);
52
- if (entry) {
53
- entries.push(entry);
54
- }
55
- }
56
- if (i++ % 10000 === 0 && performance.now() - s > 50) {
57
- statusCallback(`Loading ${(0, util_1.getProgressDisplayStr)(blockStart, buffer.length)}`);
58
- s = performance.now();
59
- }
60
- blockStart = n + 1;
61
- }
62
- statusCallback('');
63
- return entries;
64
- }
65
35
  function parsePAFLine(line) {
66
36
  const parts = line.split('\t');
67
37
  const extraFields = parts.slice(12);
@@ -2,9 +2,9 @@ import { readConfObject } from '@jbrowse/core/configuration';
2
2
  import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3
3
  import { doesIntersect2, fetchAndMaybeUnzip } from '@jbrowse/core/util';
4
4
  import { openLocation } from '@jbrowse/core/util/io';
5
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
5
6
  import { ObservableCreate } from '@jbrowse/core/util/rxjs';
6
7
  import SyntenyFeature from '../SyntenyFeature';
7
- import { parseLineByLine } from '../util';
8
8
  function createBlastLineParser(columns) {
9
9
  const columnNames = columns.trim().split(' ');
10
10
  const qseqidIndex = columnNames.indexOf('qseqid');
@@ -80,7 +80,16 @@ class BlastTabularAdapter extends BaseFeatureDataAdapter {
80
80
  }
81
81
  async setup(opts) {
82
82
  const columns = readConfObject(this.config, 'columns');
83
- return parseLineByLine(await fetchAndMaybeUnzip(openLocation(readConfObject(this.config, 'blastTableLocation'), this.pluginManager), opts), createBlastLineParser(columns), opts);
83
+ const lines = [];
84
+ const cb = createBlastLineParser(columns);
85
+ parseLineByLine(await fetchAndMaybeUnzip(openLocation(readConfObject(this.config, 'blastTableLocation'), this.pluginManager), opts), line => {
86
+ const res = cb(line);
87
+ if (res) {
88
+ lines.push(res);
89
+ }
90
+ return true;
91
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
92
+ return lines;
84
93
  }
85
94
  async hasDataForRefName() {
86
95
  return true;
@@ -1,4 +1,4 @@
1
- import { getProgressDisplayStr } from '@jbrowse/core/util';
1
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
2
2
  function generate_record(qname, qstart, qend, qstrand, tname, tstart, tend, cigar, numMatches) {
3
3
  return {
4
4
  qname,
@@ -29,24 +29,9 @@ export function paf_chain2paf(buffer, opts) {
29
29
  let num_matches = 0;
30
30
  let cigar = '';
31
31
  const records = [];
32
- let blockStart = 0;
33
- const decoder = new TextDecoder('utf8');
34
- let s = performance.now();
35
- let i = 0;
36
- while (blockStart < buffer.length) {
37
- if (i++ % 10000 === 0 && performance.now() - s > 50) {
38
- statusCallback(`Loading ${getProgressDisplayStr(blockStart, buffer.length)}`);
39
- s = performance.now();
40
- }
41
- const n = buffer.indexOf(10, blockStart);
42
- if (n === -1) {
43
- break;
44
- }
45
- const b = buffer.subarray(blockStart, n);
46
- const line = decoder.decode(b).trim();
47
- blockStart = n + 1;
32
+ parseLineByLine(buffer, line => {
48
33
  if (!line || line.startsWith('#')) {
49
- continue;
34
+ return true;
50
35
  }
51
36
  const l_vec = line.split(/[ \t]+/);
52
37
  if (l_vec[0] === 'chain') {
@@ -84,7 +69,8 @@ export function paf_chain2paf(buffer, opts) {
84
69
  cigar += `${diff_in_target}D`;
85
70
  }
86
71
  }
87
- }
72
+ return true;
73
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
88
74
  if (cigar) {
89
75
  generate_record(q_name, q_start, q_end, q_strand, t_name, t_start, t_end, cigar, num_matches);
90
76
  }
@@ -9,12 +9,6 @@ export default class DeltaAdapter extends PAFAdapter {
9
9
  tstart: number;
10
10
  tend: number;
11
11
  strand: number;
12
- extra: {
13
- numMatches: number;
14
- blockLen: number;
15
- mappingQual: number;
16
- NM: number;
17
- cg: string;
18
- };
12
+ extra: Record<string, unknown>;
19
13
  }[]>;
20
14
  }
@@ -7,11 +7,5 @@ export declare function paf_delta2paf(buffer: Uint8Array, opts?: BaseOptions): {
7
7
  tstart: number;
8
8
  tend: number;
9
9
  strand: number;
10
- extra: {
11
- numMatches: number;
12
- blockLen: number;
13
- mappingQual: number;
14
- NM: number;
15
- cg: string;
16
- };
10
+ extra: Record<string, unknown>;
17
11
  }[];
@@ -1,4 +1,4 @@
1
- import { getProgressDisplayStr } from '@jbrowse/core/util';
1
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
2
2
  export function paf_delta2paf(buffer, opts) {
3
3
  const { statusCallback = () => { } } = opts || {};
4
4
  let rname = '';
@@ -15,113 +15,94 @@ export function paf_delta2paf(buffer, opts) {
15
15
  let seen_gt = false;
16
16
  const records = [];
17
17
  const regex = new RegExp(/^>(\S+)\s+(\S+)\s+(\d+)\s+(\d+)/);
18
- let blockStart = 0;
19
- let i = 0;
20
- let j = 0;
21
- const decoder = new TextDecoder('utf8');
22
- let s = performance.now();
23
- while (blockStart < buffer.length) {
24
- if (j++ % 10000 === 0 && performance.now() - s > 50) {
25
- statusCallback(`Loading ${getProgressDisplayStr(blockStart, buffer.length)}`);
26
- s = performance.now();
18
+ parseLineByLine(buffer, line => {
19
+ const m = regex.exec(line);
20
+ if (m !== null) {
21
+ rname = m[1];
22
+ qname = m[2];
23
+ seen_gt = true;
24
+ return true;
27
25
  }
28
- const n = buffer.indexOf(10, blockStart);
29
- if (n === -1) {
30
- break;
26
+ if (!seen_gt) {
27
+ return true;
31
28
  }
32
- const b = buffer.subarray(blockStart, n);
33
- const line = decoder.decode(b).trim();
34
- blockStart = n + 1;
35
- i++;
36
- if (line) {
37
- const m = regex.exec(line);
38
- if (m !== null) {
39
- rname = m[1];
40
- qname = m[2];
41
- seen_gt = true;
42
- continue;
43
- }
44
- if (!seen_gt) {
45
- continue;
29
+ const t = line.split(' ');
30
+ if (t.length === 7) {
31
+ const t0 = +t[0];
32
+ const t1 = +t[1];
33
+ const t2 = +t[2];
34
+ const t3 = +t[3];
35
+ const t4 = +t[4];
36
+ strand = (t0 < t1 && t2 < t3) || (t0 > t1 && t2 > t3) ? 1 : -1;
37
+ rs = +Math.min(t0, t1) - 1;
38
+ re = +Math.max(t1, t0);
39
+ qs = +Math.min(t2, t3) - 1;
40
+ qe = +Math.max(t3, t2);
41
+ x = y = 0;
42
+ NM = t4;
43
+ cigar = [];
44
+ }
45
+ else if (t.length === 1) {
46
+ const d = +t[0];
47
+ if (d === 0) {
48
+ let blen = 0;
49
+ const cigar_str = [];
50
+ if (re - rs - x !== qe - qs - y) {
51
+ throw new Error(`inconsistent alignment on line ${line}`);
52
+ }
53
+ cigar.push((re - rs - x) << 4);
54
+ for (const entry of cigar) {
55
+ const rlen = entry >> 4;
56
+ blen += rlen;
57
+ cigar_str.push(rlen + 'MID'.charAt(entry & 0xf));
58
+ }
59
+ records.push({
60
+ qname,
61
+ qstart: qs,
62
+ qend: qe,
63
+ tname: rname,
64
+ tstart: rs,
65
+ tend: re,
66
+ strand,
67
+ extra: {
68
+ numMatches: blen - NM,
69
+ blockLen: blen,
70
+ mappingQual: 0,
71
+ NM,
72
+ cg: cigar_str.join(''),
73
+ },
74
+ });
46
75
  }
47
- const t = line.split(' ');
48
- if (t.length === 7) {
49
- const t0 = +t[0];
50
- const t1 = +t[1];
51
- const t2 = +t[2];
52
- const t3 = +t[3];
53
- const t4 = +t[4];
54
- strand = (t0 < t1 && t2 < t3) || (t0 > t1 && t2 > t3) ? 1 : -1;
55
- rs = +Math.min(t0, t1) - 1;
56
- re = +Math.max(t1, t0);
57
- qs = +Math.min(t2, t3) - 1;
58
- qe = +Math.max(t3, t2);
59
- x = y = 0;
60
- NM = t4;
61
- cigar = [];
76
+ else if (d > 0) {
77
+ const l = d - 1;
78
+ x += l + 1;
79
+ y += l;
80
+ if (l > 0) {
81
+ cigar.push(l << 4);
82
+ }
83
+ if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 2) {
84
+ cigar[cigar.length - 1] += 1 << 4;
85
+ }
86
+ else {
87
+ cigar.push((1 << 4) | 2);
88
+ }
62
89
  }
63
- else if (t.length === 1) {
64
- const d = +t[0];
65
- if (d === 0) {
66
- let blen = 0;
67
- const cigar_str = [];
68
- if (re - rs - x !== qe - qs - y) {
69
- throw new Error(`inconsistent alignment on line ${i}`);
70
- }
71
- cigar.push((re - rs - x) << 4);
72
- for (const entry of cigar) {
73
- const rlen = entry >> 4;
74
- blen += rlen;
75
- cigar_str.push(rlen + 'MID'.charAt(cigar[i] & 0xf));
76
- }
77
- records.push({
78
- qname,
79
- qstart: qs,
80
- qend: qe,
81
- tname: rname,
82
- tstart: rs,
83
- tend: re,
84
- strand,
85
- extra: {
86
- numMatches: blen - NM,
87
- blockLen: blen,
88
- mappingQual: 0,
89
- NM,
90
- cg: cigar_str.join(''),
91
- },
92
- });
90
+ else {
91
+ const l = -d - 1;
92
+ x += l;
93
+ y += l + 1;
94
+ if (l > 0) {
95
+ cigar.push(l << 4);
93
96
  }
94
- else if (d > 0) {
95
- const l = d - 1;
96
- x += l + 1;
97
- y += l;
98
- if (l > 0) {
99
- cigar.push(l << 4);
100
- }
101
- if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 2) {
102
- cigar[cigar.length - 1] += 1 << 4;
103
- }
104
- else {
105
- cigar.push((1 << 4) | 2);
106
- }
97
+ if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 1) {
98
+ cigar[cigar.length - 1] += 1 << 4;
107
99
  }
108
100
  else {
109
- const l = -d - 1;
110
- x += l;
111
- y += l + 1;
112
- if (l > 0) {
113
- cigar.push(l << 4);
114
- }
115
- if (cigar.length > 0 && (cigar[cigar.length - 1] & 0xf) === 1) {
116
- cigar[cigar.length - 1] += 1 << 4;
117
- }
118
- else {
119
- cigar.push((1 << 4) | 1);
120
- }
101
+ cigar.push((1 << 4) | 1);
121
102
  }
122
103
  }
123
104
  }
124
- }
125
- statusCallback('');
105
+ return true;
106
+ }, statusCallback);
126
107
  return records;
127
108
  }
@@ -1,10 +1,15 @@
1
1
  import { fetchAndMaybeUnzip } from '@jbrowse/core/util';
2
2
  import { openLocation } from '@jbrowse/core/util/io';
3
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
3
4
  import PAFAdapter from '../PAFAdapter/PAFAdapter';
4
- import { parseLineByLine } from '../util';
5
5
  export default class MashMapAdapter extends PAFAdapter {
6
6
  async setupPre(opts) {
7
- return parseLineByLine(await fetchAndMaybeUnzip(openLocation(this.getConf('outLocation'), this.pluginManager), opts), parseMashMapLine, opts);
7
+ const lines = [];
8
+ parseLineByLine(await fetchAndMaybeUnzip(openLocation(this.getConf('outLocation'), this.pluginManager), opts), line => {
9
+ lines.push(parseMashMapLine(line));
10
+ return true;
11
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
12
+ return lines;
8
13
  }
9
14
  }
10
15
  function parseMashMapLine(line) {
@@ -2,11 +2,12 @@ import { readConfObject } from '@jbrowse/core/configuration';
2
2
  import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3
3
  import { fetchAndMaybeUnzip } from '@jbrowse/core/util';
4
4
  import { openLocation } from '@jbrowse/core/util/io';
5
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
5
6
  import { doesIntersect2 } from '@jbrowse/core/util/range';
6
7
  import { ObservableCreate } from '@jbrowse/core/util/rxjs';
7
8
  import { MismatchParser } from '@jbrowse/plugin-alignments';
8
9
  import SyntenyFeature from '../SyntenyFeature';
9
- import { flipCigar, parseLineByLine, parsePAFLine, swapIndelCigar, } from '../util';
10
+ import { flipCigar, parsePAFLine, swapIndelCigar } from '../util';
10
11
  import { getWeightedMeans } from './util';
11
12
  const { parseCigar } = MismatchParser;
12
13
  class PAFAdapter extends BaseFeatureDataAdapter {
@@ -20,7 +21,12 @@ class PAFAdapter extends BaseFeatureDataAdapter {
20
21
  return this.setupP;
21
22
  }
22
23
  async setupPre(opts) {
23
- return parseLineByLine(await fetchAndMaybeUnzip(openLocation(this.getConf('pafLocation'), this.pluginManager), opts), parsePAFLine, opts);
24
+ const lines = [];
25
+ parseLineByLine(await fetchAndMaybeUnzip(openLocation(this.getConf('pafLocation'), this.pluginManager), opts), line => {
26
+ lines.push(parsePAFLine(line));
27
+ return true;
28
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
29
+ return lines;
24
30
  }
25
31
  async hasDataForRefName() {
26
32
  return true;
package/esm/util.d.ts CHANGED
@@ -11,7 +11,6 @@ export declare function parseBed(text: string): Map<string | undefined, {
11
11
  }>;
12
12
  export declare function readFile(file: GenericFilehandle, opts?: BaseOptions): Promise<string>;
13
13
  export declare function zip(a: number[], b: number[]): [number, number][];
14
- export declare function parseLineByLine<T>(buffer: Uint8Array, cb: (line: string) => T | undefined, opts?: BaseOptions): T[];
15
14
  export declare function parsePAFLine(line: string): PAFRecord;
16
15
  export declare function flipCigar(cigar: string[]): (string | undefined)[];
17
16
  export declare function swapIndelCigar(cigar: string): string;
package/esm/util.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fetchAndMaybeUnzipText, getProgressDisplayStr, } from '@jbrowse/core/util';
1
+ import { fetchAndMaybeUnzipText } from '@jbrowse/core/util';
2
2
  export function parseBed(text) {
3
3
  return new Map(text
4
4
  .split(/\n|\r\n|\r/)
@@ -24,35 +24,6 @@ export async function readFile(file, opts) {
24
24
  export function zip(a, b) {
25
25
  return a.map((e, i) => [e, b[i]]);
26
26
  }
27
- export function parseLineByLine(buffer, cb, opts) {
28
- const { statusCallback = () => { } } = opts || {};
29
- let blockStart = 0;
30
- const entries = [];
31
- const decoder = new TextDecoder('utf8');
32
- let i = 0;
33
- let s = performance.now();
34
- while (blockStart < buffer.length) {
35
- const n = buffer.indexOf(10, blockStart);
36
- if (n === -1) {
37
- break;
38
- }
39
- const b = buffer.subarray(blockStart, n);
40
- const line = decoder.decode(b).trim();
41
- if (line) {
42
- const entry = cb(line);
43
- if (entry) {
44
- entries.push(entry);
45
- }
46
- }
47
- if (i++ % 10000 === 0 && performance.now() - s > 50) {
48
- statusCallback(`Loading ${getProgressDisplayStr(blockStart, buffer.length)}`);
49
- s = performance.now();
50
- }
51
- blockStart = n + 1;
52
- }
53
- statusCallback('');
54
- return entries;
55
- }
56
27
  export function parsePAFLine(line) {
57
28
  const parts = line.split('\t');
58
29
  const extraFields = parts.slice(12);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-comparative-adapters",
3
- "version": "3.6.2",
3
+ "version": "3.6.4",
4
4
  "description": "JBrowse 2 comparative adapters",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -38,9 +38,9 @@
38
38
  "dependencies": {
39
39
  "@gmod/bgzf-filehandle": "^4.0.0",
40
40
  "@gmod/tabix": "^3.0.1",
41
- "@jbrowse/core": "^3.6.2",
42
- "@jbrowse/plugin-alignments": "^3.6.2",
43
- "@jbrowse/plugin-linear-genome-view": "^3.6.2",
41
+ "@jbrowse/core": "^3.6.4",
42
+ "@jbrowse/plugin-alignments": "^3.6.4",
43
+ "@jbrowse/plugin-linear-genome-view": "^3.6.4",
44
44
  "@mui/material": "^7.0.0",
45
45
  "generic-filehandle2": "^2.0.1",
46
46
  "mobx": "^6.0.0",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "2a2c52face5f1b8fe899f48d5903e5c5f06dba63"
61
+ "gitHead": "3db8e50ce2bd9c081efbf6c2e7ae5f342380a25a"
62
62
  }