@jbrowse/plugin-bed 3.6.3 → 3.6.5

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.
@@ -8,6 +8,7 @@ const bed_1 = __importDefault(require("@gmod/bed"));
8
8
  const BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
9
9
  const util_1 = require("@jbrowse/core/util");
10
10
  const io_1 = require("@jbrowse/core/util/io");
11
+ const parseLineByLine_1 = require("@jbrowse/core/util/parseLineByLine");
11
12
  const rxjs_1 = require("@jbrowse/core/util/rxjs");
12
13
  const util_2 = require("../util");
13
14
  class BedAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
@@ -16,39 +17,24 @@ class BedAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
16
17
  this.intervalTrees = {};
17
18
  }
18
19
  async loadDataP(opts) {
19
- const { statusCallback = () => { } } = opts || {};
20
20
  const bedLoc = this.getConf('bedLocation');
21
21
  const buffer = await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(bedLoc, this.pluginManager), opts);
22
22
  const headerLines = [];
23
23
  const features = {};
24
- let blockStart = 0;
25
- let i = 0;
26
- const decoder = new TextDecoder('utf8');
27
- while (blockStart < buffer.length) {
28
- const n = buffer.indexOf(10, blockStart);
29
- const b = n === -1 ? buffer.subarray(blockStart) : buffer.subarray(blockStart, n);
30
- const line = decoder.decode(b).trim();
31
- if (line) {
32
- if (line.startsWith('#')) {
33
- headerLines.push(line);
34
- }
35
- else if (line.startsWith('>')) {
36
- break;
37
- }
38
- else {
39
- const tab = line.indexOf('\t');
40
- const refName = line.slice(0, tab);
41
- if (!features[refName]) {
42
- features[refName] = [];
43
- }
44
- features[refName].push(line);
45
- }
24
+ (0, parseLineByLine_1.parseLineByLine)(buffer, line => {
25
+ if (line.startsWith('#')) {
26
+ headerLines.push(line);
46
27
  }
47
- if (i++ % 10000 === 0) {
48
- statusCallback(`Loading ${(0, util_1.getProgressDisplayStr)(blockStart, buffer.length)}`);
28
+ else {
29
+ const tab = line.indexOf('\t');
30
+ const refName = line.slice(0, tab);
31
+ if (!features[refName]) {
32
+ features[refName] = [];
33
+ }
34
+ features[refName].push(line);
49
35
  }
50
- blockStart = n + 1;
51
- }
36
+ return true;
37
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
52
38
  const header = headerLines.join('\n');
53
39
  const autoSql = this.getConf('autoSql');
54
40
  const parser = new bed_1.default({ autoSql });
@@ -7,6 +7,7 @@ const interval_tree_1 = __importDefault(require("@flatten-js/interval-tree"));
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
  class BedGraphAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
12
13
  constructor() {
@@ -69,30 +70,25 @@ class BedGraphAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
69
70
  const pm = this.pluginManager;
70
71
  const bedLoc = this.getConf('bedGraphLocation');
71
72
  const buffer = await (0, util_1.fetchAndMaybeUnzip)((0, io_1.openLocation)(bedLoc, pm), opts);
72
- if (buffer.length > 536870888) {
73
- throw new Error('Data exceeds maximum string length (512MB)');
74
- }
75
- const data = new TextDecoder('utf8', { fatal: true }).decode(buffer);
76
- const lines = data.split(/\n|\r\n|\r/).filter(f => !!f);
77
- const headerLines = [];
78
- let i = 0;
79
- for (; i < lines.length && lines[i].startsWith('#'); i++) {
80
- headerLines.push(lines[i]);
81
- }
82
- const header = headerLines.join('\n');
83
73
  const features = {};
84
- for (; i < lines.length; i++) {
85
- const line = lines[i];
86
- const tab = line.indexOf('\t');
87
- const refName = line.slice(0, tab);
88
- if (!features[refName]) {
89
- features[refName] = [];
74
+ const headerLines = [];
75
+ (0, parseLineByLine_1.parseLineByLine)(buffer, line => {
76
+ if (line.startsWith('#')) {
77
+ headerLines.push(line);
90
78
  }
91
- features[refName].push(line);
92
- }
79
+ else {
80
+ const tab = line.indexOf('\t');
81
+ const refName = line.slice(0, tab);
82
+ if (!features[refName]) {
83
+ features[refName] = [];
84
+ }
85
+ features[refName].push(line);
86
+ }
87
+ return true;
88
+ }, opts.statusCallback);
93
89
  const columnNames = this.getConf('columnNames');
94
90
  return {
95
- header,
91
+ header: headerLines.join('\n'),
96
92
  features,
97
93
  columnNames,
98
94
  };
@@ -172,10 +172,7 @@ class BigBedAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
172
172
  const e = (0, util_1.max)(subfeatures.map(f => f.end));
173
173
  if ((0, util_1.doesIntersect2)(s, e, originalQuery.start, originalQuery.end)) {
174
174
  const subs = subfeatures.sort((a, b) => a.uniqueId.localeCompare(b.uniqueId));
175
- if (subs.every(s => {
176
- var _a;
177
- return s.strand === (((_a = subs[0]) === null || _a === void 0 ? void 0 : _a.strand) || 1);
178
- })) {
175
+ if (subs.some((a, i) => subs.some((b, j) => i !== j && (0, util_1.doesIntersect2)(a.start, a.end, b.start, b.end)))) {
179
176
  observer.next(new util_1.SimpleFeature({
180
177
  id: `${this.id}-${(_a = subs[0]) === null || _a === void 0 ? void 0 : _a.uniqueId}-parent`,
181
178
  data: {
@@ -1,8 +1,9 @@
1
1
  import IntervalTree from '@flatten-js/interval-tree';
2
2
  import BED from '@gmod/bed';
3
3
  import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
4
- import { SimpleFeature, fetchAndMaybeUnzip, getProgressDisplayStr, } from '@jbrowse/core/util';
4
+ import { SimpleFeature, fetchAndMaybeUnzip } from '@jbrowse/core/util';
5
5
  import { openLocation } from '@jbrowse/core/util/io';
6
+ import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
6
7
  import { ObservableCreate } from '@jbrowse/core/util/rxjs';
7
8
  import { featureData } from '../util';
8
9
  class BedAdapter extends BaseFeatureDataAdapter {
@@ -11,39 +12,24 @@ class BedAdapter extends BaseFeatureDataAdapter {
11
12
  this.intervalTrees = {};
12
13
  }
13
14
  async loadDataP(opts) {
14
- const { statusCallback = () => { } } = opts || {};
15
15
  const bedLoc = this.getConf('bedLocation');
16
16
  const buffer = await fetchAndMaybeUnzip(openLocation(bedLoc, this.pluginManager), opts);
17
17
  const headerLines = [];
18
18
  const features = {};
19
- let blockStart = 0;
20
- let i = 0;
21
- const decoder = new TextDecoder('utf8');
22
- while (blockStart < buffer.length) {
23
- const n = buffer.indexOf(10, blockStart);
24
- const b = n === -1 ? buffer.subarray(blockStart) : buffer.subarray(blockStart, n);
25
- const line = decoder.decode(b).trim();
26
- if (line) {
27
- if (line.startsWith('#')) {
28
- headerLines.push(line);
29
- }
30
- else if (line.startsWith('>')) {
31
- break;
32
- }
33
- else {
34
- const tab = line.indexOf('\t');
35
- const refName = line.slice(0, tab);
36
- if (!features[refName]) {
37
- features[refName] = [];
38
- }
39
- features[refName].push(line);
40
- }
19
+ parseLineByLine(buffer, line => {
20
+ if (line.startsWith('#')) {
21
+ headerLines.push(line);
41
22
  }
42
- if (i++ % 10000 === 0) {
43
- statusCallback(`Loading ${getProgressDisplayStr(blockStart, buffer.length)}`);
23
+ else {
24
+ const tab = line.indexOf('\t');
25
+ const refName = line.slice(0, tab);
26
+ if (!features[refName]) {
27
+ features[refName] = [];
28
+ }
29
+ features[refName].push(line);
44
30
  }
45
- blockStart = n + 1;
46
- }
31
+ return true;
32
+ }, opts === null || opts === void 0 ? void 0 : opts.statusCallback);
47
33
  const header = headerLines.join('\n');
48
34
  const autoSql = this.getConf('autoSql');
49
35
  const parser = new BED({ autoSql });
@@ -2,6 +2,7 @@ import IntervalTree from '@flatten-js/interval-tree';
2
2
  import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3
3
  import { SimpleFeature, 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
  export default class BedGraphAdapter extends BaseFeatureDataAdapter {
7
8
  constructor() {
@@ -64,30 +65,25 @@ export default class BedGraphAdapter extends BaseFeatureDataAdapter {
64
65
  const pm = this.pluginManager;
65
66
  const bedLoc = this.getConf('bedGraphLocation');
66
67
  const buffer = await fetchAndMaybeUnzip(openLocation(bedLoc, pm), opts);
67
- if (buffer.length > 536870888) {
68
- throw new Error('Data exceeds maximum string length (512MB)');
69
- }
70
- const data = new TextDecoder('utf8', { fatal: true }).decode(buffer);
71
- const lines = data.split(/\n|\r\n|\r/).filter(f => !!f);
72
- const headerLines = [];
73
- let i = 0;
74
- for (; i < lines.length && lines[i].startsWith('#'); i++) {
75
- headerLines.push(lines[i]);
76
- }
77
- const header = headerLines.join('\n');
78
68
  const features = {};
79
- for (; i < lines.length; i++) {
80
- const line = lines[i];
81
- const tab = line.indexOf('\t');
82
- const refName = line.slice(0, tab);
83
- if (!features[refName]) {
84
- features[refName] = [];
69
+ const headerLines = [];
70
+ parseLineByLine(buffer, line => {
71
+ if (line.startsWith('#')) {
72
+ headerLines.push(line);
85
73
  }
86
- features[refName].push(line);
87
- }
74
+ else {
75
+ const tab = line.indexOf('\t');
76
+ const refName = line.slice(0, tab);
77
+ if (!features[refName]) {
78
+ features[refName] = [];
79
+ }
80
+ features[refName].push(line);
81
+ }
82
+ return true;
83
+ }, opts.statusCallback);
88
84
  const columnNames = this.getConf('columnNames');
89
85
  return {
90
- header,
86
+ header: headerLines.join('\n'),
91
87
  features,
92
88
  columnNames,
93
89
  };
@@ -167,10 +167,7 @@ export default class BigBedAdapter extends BaseFeatureDataAdapter {
167
167
  const e = max(subfeatures.map(f => f.end));
168
168
  if (doesIntersect2(s, e, originalQuery.start, originalQuery.end)) {
169
169
  const subs = subfeatures.sort((a, b) => a.uniqueId.localeCompare(b.uniqueId));
170
- if (subs.every(s => {
171
- var _a;
172
- return s.strand === (((_a = subs[0]) === null || _a === void 0 ? void 0 : _a.strand) || 1);
173
- })) {
170
+ if (subs.some((a, i) => subs.some((b, j) => i !== j && doesIntersect2(a.start, a.end, b.start, b.end)))) {
174
171
  observer.next(new SimpleFeature({
175
172
  id: `${this.id}-${(_a = subs[0]) === null || _a === void 0 ? void 0 : _a.uniqueId}-parent`,
176
173
  data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-bed",
3
- "version": "3.6.3",
3
+ "version": "3.6.5",
4
4
  "description": "JBrowse 2 bed adapters, tracks, etc.",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -41,7 +41,7 @@
41
41
  "@gmod/bed": "^2.1.2",
42
42
  "@gmod/bgzf-filehandle": "^4.0.0",
43
43
  "@gmod/tabix": "^3.0.1",
44
- "@jbrowse/core": "^3.6.3",
44
+ "@jbrowse/core": "^3.6.5",
45
45
  "mobx": "^6.0.0",
46
46
  "mobx-react": "^9.0.0",
47
47
  "mobx-state-tree": "^5.0.0",
@@ -53,5 +53,5 @@
53
53
  "distModule": "esm/index.js",
54
54
  "srcModule": "src/index.ts",
55
55
  "module": "esm/index.js",
56
- "gitHead": "cf3dd1c895b4f3f7367093d57a0b607f54b8d7db"
56
+ "gitHead": "354d0a87b757b4d84f824b47507662f6f3a1693f"
57
57
  }