@jbrowse/plugin-alignments 2.0.0 → 2.1.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.
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +61 -90
- package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js.map +1 -1
- package/dist/AlignmentsFeatureDetail/index.js +14 -16
- package/dist/AlignmentsFeatureDetail/index.js.map +1 -1
- package/dist/AlignmentsTrack/index.js +8 -8
- package/dist/AlignmentsTrack/index.js.map +1 -1
- package/dist/BamAdapter/BamAdapter.d.ts +6 -1
- package/dist/BamAdapter/BamAdapter.js +157 -336
- package/dist/BamAdapter/BamAdapter.js.map +1 -1
- package/dist/BamAdapter/BamSlightlyLazyFeature.js +68 -103
- package/dist/BamAdapter/BamSlightlyLazyFeature.js.map +1 -1
- package/dist/BamAdapter/MismatchParser.d.ts +1 -1
- package/dist/BamAdapter/MismatchParser.js +97 -162
- package/dist/BamAdapter/MismatchParser.js.map +1 -1
- package/dist/BamAdapter/configSchema.js +27 -29
- package/dist/BamAdapter/configSchema.js.map +1 -1
- package/dist/BamAdapter/index.js +9 -11
- package/dist/BamAdapter/index.js.map +1 -1
- package/dist/CramAdapter/CramAdapter.js +193 -351
- package/dist/CramAdapter/CramAdapter.js.map +1 -1
- package/dist/CramAdapter/CramSlightlyLazyFeature.js +119 -154
- package/dist/CramAdapter/CramSlightlyLazyFeature.js.map +1 -1
- package/dist/CramAdapter/CramTestAdapters.js +51 -148
- package/dist/CramAdapter/CramTestAdapters.js.map +1 -1
- package/dist/CramAdapter/configSchema.js +23 -25
- package/dist/CramAdapter/configSchema.js.map +1 -1
- package/dist/CramAdapter/index.js +9 -11
- package/dist/CramAdapter/index.js.map +1 -1
- package/dist/HtsgetBamAdapter/HtsgetBamAdapter.js +25 -87
- package/dist/HtsgetBamAdapter/HtsgetBamAdapter.js.map +1 -1
- package/dist/HtsgetBamAdapter/configSchema.js +16 -18
- package/dist/HtsgetBamAdapter/configSchema.js.map +1 -1
- package/dist/HtsgetBamAdapter/index.js +15 -19
- package/dist/HtsgetBamAdapter/index.js.map +1 -1
- package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js +14 -15
- package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js.map +1 -1
- package/dist/LinearAlignmentsDisplay/index.js +7 -7
- package/dist/LinearAlignmentsDisplay/index.js.map +1 -1
- package/dist/LinearAlignmentsDisplay/models/configSchema.js +5 -5
- package/dist/LinearAlignmentsDisplay/models/configSchema.js.map +1 -1
- package/dist/LinearAlignmentsDisplay/models/model.js +64 -140
- package/dist/LinearAlignmentsDisplay/models/model.js.map +1 -1
- package/dist/LinearPileupDisplay/components/ColorByModifications.js +24 -53
- package/dist/LinearPileupDisplay/components/ColorByModifications.js.map +1 -1
- package/dist/LinearPileupDisplay/components/ColorByTag.js +14 -30
- package/dist/LinearPileupDisplay/components/ColorByTag.js.map +1 -1
- package/dist/LinearPileupDisplay/components/FilterByTag.js +33 -49
- package/dist/LinearPileupDisplay/components/FilterByTag.js.map +1 -1
- package/dist/LinearPileupDisplay/components/LinearPileupDisplayBlurb.js +7 -7
- package/dist/LinearPileupDisplay/components/LinearPileupDisplayBlurb.js.map +1 -1
- package/dist/LinearPileupDisplay/components/SetFeatureHeight.js +17 -33
- package/dist/LinearPileupDisplay/components/SetFeatureHeight.js.map +1 -1
- package/dist/LinearPileupDisplay/components/SetMaxHeight.js +14 -30
- package/dist/LinearPileupDisplay/components/SetMaxHeight.js.map +1 -1
- package/dist/LinearPileupDisplay/components/SortByTag.js +14 -30
- package/dist/LinearPileupDisplay/components/SortByTag.js.map +1 -1
- package/dist/LinearPileupDisplay/configSchema.js +4 -4
- package/dist/LinearPileupDisplay/configSchema.js.map +1 -1
- package/dist/LinearPileupDisplay/index.js +7 -7
- package/dist/LinearPileupDisplay/index.js.map +1 -1
- package/dist/LinearPileupDisplay/model.js +534 -645
- package/dist/LinearPileupDisplay/model.js.map +1 -1
- package/dist/LinearSNPCoverageDisplay/components/Tooltip.d.ts +5 -2
- package/dist/LinearSNPCoverageDisplay/components/Tooltip.js +30 -79
- package/dist/LinearSNPCoverageDisplay/components/Tooltip.js.map +1 -1
- package/dist/LinearSNPCoverageDisplay/index.js +7 -7
- package/dist/LinearSNPCoverageDisplay/index.js.map +1 -1
- package/dist/LinearSNPCoverageDisplay/models/configSchema.js +4 -4
- package/dist/LinearSNPCoverageDisplay/models/configSchema.js.map +1 -1
- package/dist/LinearSNPCoverageDisplay/models/model.d.ts +27 -5
- package/dist/LinearSNPCoverageDisplay/models/model.js +171 -244
- package/dist/LinearSNPCoverageDisplay/models/model.js.map +1 -1
- package/dist/NestedFrequencyTable.js +27 -40
- package/dist/NestedFrequencyTable.js.map +1 -1
- package/dist/PileupRPC/rpcMethods.js +63 -191
- package/dist/PileupRPC/rpcMethods.js.map +1 -1
- package/dist/PileupRenderer/PileupLayoutSession.js +25 -47
- package/dist/PileupRenderer/PileupLayoutSession.js.map +1 -1
- package/dist/PileupRenderer/PileupRenderer.d.ts +0 -4
- package/dist/PileupRenderer/PileupRenderer.js +395 -529
- package/dist/PileupRenderer/PileupRenderer.js.map +1 -1
- package/dist/PileupRenderer/components/PileupRendering.js +41 -68
- package/dist/PileupRenderer/components/PileupRendering.js.map +1 -1
- package/dist/PileupRenderer/configSchema.js +2 -2
- package/dist/PileupRenderer/configSchema.js.map +1 -1
- package/dist/PileupRenderer/index.js +9 -11
- package/dist/PileupRenderer/index.js.map +1 -1
- package/dist/PileupRenderer/sortUtil.js +36 -40
- package/dist/PileupRenderer/sortUtil.js.map +1 -1
- package/dist/SNPCoverageAdapter/SNPCoverageAdapter.js +229 -414
- package/dist/SNPCoverageAdapter/SNPCoverageAdapter.js.map +1 -1
- package/dist/SNPCoverageAdapter/configSchema.js +5 -9
- package/dist/SNPCoverageAdapter/configSchema.js.map +1 -1
- package/dist/SNPCoverageAdapter/index.js +17 -21
- package/dist/SNPCoverageAdapter/index.js.map +1 -1
- package/dist/SNPCoverageRenderer/SNPCoverageRenderer.d.ts +1 -1
- package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js +175 -259
- package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
- package/dist/SNPCoverageRenderer/configSchema.js +1 -1
- package/dist/SNPCoverageRenderer/configSchema.js.map +1 -1
- package/dist/SNPCoverageRenderer/index.js +10 -12
- package/dist/SNPCoverageRenderer/index.js.map +1 -1
- package/dist/index.js +40 -58
- package/dist/index.js.map +1 -1
- package/dist/shared.js +23 -78
- package/dist/shared.js.map +1 -1
- package/dist/util.js +13 -66
- package/dist/util.js.map +1 -1
- package/esm/BamAdapter/BamAdapter.d.ts +6 -1
- package/esm/BamAdapter/BamAdapter.js.map +1 -1
- package/esm/BamAdapter/MismatchParser.d.ts +1 -1
- package/esm/BamAdapter/MismatchParser.js +2 -2
- package/esm/BamAdapter/MismatchParser.js.map +1 -1
- package/esm/LinearPileupDisplay/model.js +0 -1
- package/esm/LinearPileupDisplay/model.js.map +1 -1
- package/esm/LinearSNPCoverageDisplay/components/Tooltip.d.ts +4 -1
- package/esm/LinearSNPCoverageDisplay/components/Tooltip.js +0 -1
- package/esm/LinearSNPCoverageDisplay/components/Tooltip.js.map +1 -1
- package/esm/LinearSNPCoverageDisplay/models/model.d.ts +27 -5
- package/esm/LinearSNPCoverageDisplay/models/model.js +1 -0
- package/esm/LinearSNPCoverageDisplay/models/model.js.map +1 -1
- package/esm/PileupRenderer/PileupRenderer.d.ts +0 -4
- package/esm/PileupRenderer/PileupRenderer.js +1 -3
- package/esm/PileupRenderer/PileupRenderer.js.map +1 -1
- package/esm/SNPCoverageAdapter/SNPCoverageAdapter.js +4 -3
- package/esm/SNPCoverageAdapter/SNPCoverageAdapter.js.map +1 -1
- package/esm/SNPCoverageRenderer/SNPCoverageRenderer.d.ts +1 -1
- package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js +0 -1
- package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
- package/package.json +6 -7
- package/src/AlignmentsFeatureDetail/__snapshots__/index.test.js.snap +12 -12
- package/src/BamAdapter/BamAdapter.ts +1 -1
- package/src/BamAdapter/MismatchParser.ts +2 -2
- package/src/LinearPileupDisplay/model.ts +2 -2
- package/src/LinearSNPCoverageDisplay/components/Tooltip.tsx +3 -4
- package/src/LinearSNPCoverageDisplay/models/model.ts +3 -1
- package/src/PileupRenderer/PileupRenderer.tsx +13 -19
- package/src/SNPCoverageAdapter/SNPCoverageAdapter.ts +4 -3
- package/src/SNPCoverageRenderer/SNPCoverageRenderer.ts +1 -3
|
@@ -1,259 +1,139 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
4
|
};
|
|
67
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
_this.samHeader = {};
|
|
6
|
+
const cram_1 = require("@gmod/cram");
|
|
7
|
+
const BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
|
|
8
|
+
const util_1 = require("@jbrowse/core/util");
|
|
9
|
+
const io_1 = require("@jbrowse/core/util/io");
|
|
10
|
+
const rxjs_1 = require("@jbrowse/core/util/rxjs");
|
|
11
|
+
const operators_1 = require("rxjs/operators");
|
|
12
|
+
const CramSlightlyLazyFeature_1 = __importDefault(require("./CramSlightlyLazyFeature"));
|
|
13
|
+
class CramAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.samHeader = {};
|
|
80
17
|
// maps a seqId to original refname, passed specially to render args, to a seqid
|
|
81
|
-
|
|
82
|
-
return _this;
|
|
18
|
+
this.seqIdToOriginalRefName = [];
|
|
83
19
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}),
|
|
103
|
-
seqFetch: this.seqFetch.bind(this),
|
|
104
|
-
checkSequenceMD5: false,
|
|
105
|
-
fetchSizeLimit: 200000000, // just make this a large size to avoid hitting it
|
|
106
|
-
});
|
|
107
|
-
sequenceAdapterType = this.getConf(['sequenceAdapter', 'type']);
|
|
108
|
-
if (!this.getSubAdapter) {
|
|
109
|
-
throw new Error('Error getting subadapter');
|
|
110
|
-
}
|
|
111
|
-
seqConf = this.getConf('sequenceAdapter');
|
|
112
|
-
return [4 /*yield*/, this.getSubAdapter(seqConf)];
|
|
113
|
-
case 1:
|
|
114
|
-
sequenceAdapter = (_a.sent()).dataAdapter;
|
|
115
|
-
if (!(sequenceAdapter instanceof BaseAdapter_1.BaseFeatureDataAdapter)) {
|
|
116
|
-
throw new Error("CRAM feature adapters cannot use sequence adapters of type '".concat(sequenceAdapterType, "'"));
|
|
117
|
-
}
|
|
118
|
-
return [2 /*return*/, { cram: cram, sequenceAdapter: sequenceAdapter }];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
CramAdapter.prototype.getHeader = function (opts) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var cram;
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
switch (_a.label) {
|
|
128
|
-
case 0: return [4 /*yield*/, this.configure()];
|
|
129
|
-
case 1:
|
|
130
|
-
cram = (_a.sent()).cram;
|
|
131
|
-
return [2 /*return*/, cram.cram.getHeaderText(opts)];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
CramAdapter.prototype.seqFetch = function (seqId, start, end) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
-
var sequenceAdapter, refName, seqChunks, sequence;
|
|
139
|
-
return __generator(this, function (_a) {
|
|
140
|
-
switch (_a.label) {
|
|
141
|
-
case 0:
|
|
142
|
-
start -= 1; // convert from 1-based closed to interbase
|
|
143
|
-
return [4 /*yield*/, this.configure()];
|
|
144
|
-
case 1:
|
|
145
|
-
sequenceAdapter = (_a.sent()).sequenceAdapter;
|
|
146
|
-
refName = this.refIdToOriginalName(seqId) || this.refIdToName(seqId);
|
|
147
|
-
if (!refName) {
|
|
148
|
-
return [2 /*return*/, undefined];
|
|
149
|
-
}
|
|
150
|
-
return [4 /*yield*/, sequenceAdapter
|
|
151
|
-
.getFeatures({
|
|
152
|
-
refName: refName,
|
|
153
|
-
start: start,
|
|
154
|
-
end: end,
|
|
155
|
-
assemblyName: '',
|
|
156
|
-
})
|
|
157
|
-
.pipe((0, operators_1.toArray)())
|
|
158
|
-
.toPromise()];
|
|
159
|
-
case 2:
|
|
160
|
-
seqChunks = _a.sent();
|
|
161
|
-
sequence = seqChunks
|
|
162
|
-
.sort(function (a, b) { return a.get('start') - b.get('start'); })
|
|
163
|
-
.map(function (chunk) {
|
|
164
|
-
var chunkStart = chunk.get('start');
|
|
165
|
-
var chunkEnd = chunk.get('end');
|
|
166
|
-
var trimStart = Math.max(start - chunkStart, 0);
|
|
167
|
-
var trimEnd = Math.min(end - chunkStart, chunkEnd - chunkStart);
|
|
168
|
-
var trimLength = trimEnd - trimStart;
|
|
169
|
-
var chunkSeq = chunk.get('seq') || chunk.get('residues');
|
|
170
|
-
return chunkSeq.substr(trimStart, trimLength);
|
|
171
|
-
})
|
|
172
|
-
.join('');
|
|
173
|
-
if (sequence.length !== end - start) {
|
|
174
|
-
throw new Error("sequence fetch failed: fetching ".concat(refName, ":").concat((start - 1).toLocaleString(), "-").concat(end.toLocaleString(), " returned ").concat(sequence.length.toLocaleString(), " bases, but should have returned ").concat((end - start).toLocaleString()));
|
|
175
|
-
}
|
|
176
|
-
return [2 /*return*/, sequence];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
CramAdapter.prototype.setupPre = function (opts) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var _a, statusCallback, configured, cram, samHeader, idToName, nameToId, readGroups, data;
|
|
184
|
-
return __generator(this, function (_b) {
|
|
185
|
-
switch (_b.label) {
|
|
186
|
-
case 0:
|
|
187
|
-
_a = (opts || {}).statusCallback, statusCallback = _a === void 0 ? function () { } : _a;
|
|
188
|
-
return [4 /*yield*/, this.configure()];
|
|
189
|
-
case 1:
|
|
190
|
-
configured = _b.sent();
|
|
191
|
-
statusCallback('Downloading index');
|
|
192
|
-
cram = configured.cram;
|
|
193
|
-
return [4 /*yield*/, cram.cram.getSamHeader(opts === null || opts === void 0 ? void 0 : opts.signal)
|
|
194
|
-
// use the @SQ lines in the header to figure out the
|
|
195
|
-
// mapping between ref ID numbers and names
|
|
196
|
-
];
|
|
197
|
-
case 2:
|
|
198
|
-
samHeader = _b.sent();
|
|
199
|
-
idToName = [];
|
|
200
|
-
nameToId = {};
|
|
201
|
-
samHeader
|
|
202
|
-
.filter(function (l) { return l.tag === 'SQ'; })
|
|
203
|
-
.forEach(function (sqLine, refId) {
|
|
204
|
-
sqLine.data.forEach(function (item) {
|
|
205
|
-
if (item.tag === 'SN') {
|
|
206
|
-
// this is the ref name
|
|
207
|
-
var refName = item.value;
|
|
208
|
-
nameToId[refName] = refId;
|
|
209
|
-
idToName[refId] = refName;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
readGroups = samHeader
|
|
214
|
-
.filter(function (l) { return l.tag === 'RG'; })
|
|
215
|
-
.map(function (rgLine) { var _a; return (_a = rgLine.data.find(function (item) { return item.tag === 'ID'; })) === null || _a === void 0 ? void 0 : _a.value; });
|
|
216
|
-
data = { idToName: idToName, nameToId: nameToId, readGroups: readGroups };
|
|
217
|
-
statusCallback('');
|
|
218
|
-
this.samHeader = data;
|
|
219
|
-
return [2 /*return*/, __assign({ samHeader: data }, configured)];
|
|
220
|
-
}
|
|
221
|
-
});
|
|
20
|
+
async configure() {
|
|
21
|
+
const cramLocation = this.getConf('cramLocation');
|
|
22
|
+
const craiLocation = this.getConf('craiLocation');
|
|
23
|
+
if (!cramLocation) {
|
|
24
|
+
throw new Error('missing cramLocation argument');
|
|
25
|
+
}
|
|
26
|
+
if (!craiLocation) {
|
|
27
|
+
throw new Error('missing craiLocation argument');
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const cram = new cram_1.IndexedCramFile({
|
|
31
|
+
cramFilehandle: (0, io_1.openLocation)(cramLocation, this.pluginManager),
|
|
32
|
+
index: new cram_1.CraiIndex({
|
|
33
|
+
filehandle: (0, io_1.openLocation)(craiLocation, this.pluginManager),
|
|
34
|
+
}),
|
|
35
|
+
seqFetch: this.seqFetch.bind(this),
|
|
36
|
+
checkSequenceMD5: false,
|
|
37
|
+
fetchSizeLimit: 200000000, // just make this a large size to avoid hitting it
|
|
222
38
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
39
|
+
// instantiate the sequence adapter
|
|
40
|
+
const sequenceAdapterType = this.getConf(['sequenceAdapter', 'type']);
|
|
41
|
+
if (!this.getSubAdapter) {
|
|
42
|
+
throw new Error('Error getting subadapter');
|
|
43
|
+
}
|
|
44
|
+
const seqConf = this.getConf('sequenceAdapter');
|
|
45
|
+
const { dataAdapter: sequenceAdapter } = await this.getSubAdapter(seqConf);
|
|
46
|
+
if (!(sequenceAdapter instanceof BaseAdapter_1.BaseFeatureDataAdapter)) {
|
|
47
|
+
throw new Error(`CRAM feature adapters cannot use sequence adapters of type '${sequenceAdapterType}'`);
|
|
48
|
+
}
|
|
49
|
+
return { cram, sequenceAdapter };
|
|
50
|
+
}
|
|
51
|
+
async getHeader(opts) {
|
|
52
|
+
const { cram } = await this.configure();
|
|
53
|
+
return cram.cram.getHeaderText(opts);
|
|
54
|
+
}
|
|
55
|
+
async seqFetch(seqId, start, end) {
|
|
56
|
+
start -= 1; // convert from 1-based closed to interbase
|
|
57
|
+
const { sequenceAdapter } = await this.configure();
|
|
58
|
+
const refName = this.refIdToOriginalName(seqId) || this.refIdToName(seqId);
|
|
59
|
+
if (!refName) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const seqChunks = await sequenceAdapter
|
|
63
|
+
.getFeatures({
|
|
64
|
+
refName,
|
|
65
|
+
start,
|
|
66
|
+
end,
|
|
67
|
+
assemblyName: '',
|
|
68
|
+
})
|
|
69
|
+
.pipe((0, operators_1.toArray)())
|
|
70
|
+
.toPromise();
|
|
71
|
+
const sequence = seqChunks
|
|
72
|
+
.sort((a, b) => a.get('start') - b.get('start'))
|
|
73
|
+
.map(chunk => {
|
|
74
|
+
const chunkStart = chunk.get('start');
|
|
75
|
+
const chunkEnd = chunk.get('end');
|
|
76
|
+
const trimStart = Math.max(start - chunkStart, 0);
|
|
77
|
+
const trimEnd = Math.min(end - chunkStart, chunkEnd - chunkStart);
|
|
78
|
+
const trimLength = trimEnd - trimStart;
|
|
79
|
+
const chunkSeq = chunk.get('seq') || chunk.get('residues');
|
|
80
|
+
return chunkSeq.substr(trimStart, trimLength);
|
|
81
|
+
})
|
|
82
|
+
.join('');
|
|
83
|
+
if (sequence.length !== end - start) {
|
|
84
|
+
throw new Error(`sequence fetch failed: fetching ${refName}:${(start - 1).toLocaleString()}-${end.toLocaleString()} returned ${sequence.length.toLocaleString()} bases, but should have returned ${(end - start).toLocaleString()}`);
|
|
85
|
+
}
|
|
86
|
+
return sequence;
|
|
87
|
+
}
|
|
88
|
+
async setupPre(opts) {
|
|
89
|
+
const { statusCallback = () => { } } = opts || {};
|
|
90
|
+
const configured = await this.configure();
|
|
91
|
+
statusCallback('Downloading index');
|
|
92
|
+
const { cram } = configured;
|
|
93
|
+
const samHeader = await cram.cram.getSamHeader(opts === null || opts === void 0 ? void 0 : opts.signal);
|
|
94
|
+
// use the @SQ lines in the header to figure out the
|
|
95
|
+
// mapping between ref ID numbers and names
|
|
96
|
+
const idToName = [];
|
|
97
|
+
const nameToId = {};
|
|
98
|
+
samHeader
|
|
99
|
+
.filter(l => l.tag === 'SQ')
|
|
100
|
+
.forEach((sqLine, refId) => {
|
|
101
|
+
sqLine.data.forEach(item => {
|
|
102
|
+
if (item.tag === 'SN') {
|
|
103
|
+
// this is the ref name
|
|
104
|
+
const refName = item.value;
|
|
105
|
+
nameToId[refName] = refId;
|
|
106
|
+
idToName[refId] = refName;
|
|
233
107
|
}
|
|
234
|
-
return [2 /*return*/, this.setupP];
|
|
235
108
|
});
|
|
236
109
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
110
|
+
const readGroups = samHeader
|
|
111
|
+
.filter(l => l.tag === 'RG')
|
|
112
|
+
.map(rgLine => { var _a; return (_a = rgLine.data.find(item => item.tag === 'ID')) === null || _a === void 0 ? void 0 : _a.value; });
|
|
113
|
+
const data = { idToName, nameToId, readGroups };
|
|
114
|
+
statusCallback('');
|
|
115
|
+
this.samHeader = data;
|
|
116
|
+
return { samHeader: data, ...configured };
|
|
117
|
+
}
|
|
118
|
+
async setup(opts) {
|
|
119
|
+
if (!this.setupP) {
|
|
120
|
+
this.setupP = this.setupPre(opts).catch(e => {
|
|
121
|
+
this.setupP = undefined;
|
|
122
|
+
throw e;
|
|
251
123
|
});
|
|
252
|
-
}
|
|
253
|
-
|
|
124
|
+
}
|
|
125
|
+
return this.setupP;
|
|
126
|
+
}
|
|
127
|
+
async getRefNames(opts) {
|
|
128
|
+
const { samHeader } = await this.setup(opts);
|
|
129
|
+
if (!samHeader.idToName) {
|
|
130
|
+
throw new Error('CRAM file has no header lines');
|
|
131
|
+
}
|
|
132
|
+
return samHeader.idToName;
|
|
133
|
+
}
|
|
254
134
|
// use info from the SAM header if possible, but fall back to using
|
|
255
135
|
// the ref seq order from when the browser's refseqs were loaded
|
|
256
|
-
|
|
136
|
+
refNameToId(refName) {
|
|
257
137
|
if (this.samHeader.nameToId) {
|
|
258
138
|
return this.samHeader.nameToId[refName];
|
|
259
139
|
}
|
|
@@ -261,10 +141,10 @@ var CramAdapter = /** @class */ (function (_super) {
|
|
|
261
141
|
return this.seqIdToRefName.indexOf(refName);
|
|
262
142
|
}
|
|
263
143
|
return undefined;
|
|
264
|
-
}
|
|
144
|
+
}
|
|
265
145
|
// use info from the SAM header if possible, but fall back to using
|
|
266
146
|
// the ref seq order from when the browser's refseqs were loaded
|
|
267
|
-
|
|
147
|
+
refIdToName(refId) {
|
|
268
148
|
if (this.samHeader.idToName) {
|
|
269
149
|
return this.samHeader.idToName[refId];
|
|
270
150
|
}
|
|
@@ -272,121 +152,83 @@ var CramAdapter = /** @class */ (function (_super) {
|
|
|
272
152
|
return this.seqIdToRefName[refId];
|
|
273
153
|
}
|
|
274
154
|
return undefined;
|
|
275
|
-
}
|
|
276
|
-
|
|
155
|
+
}
|
|
156
|
+
refIdToOriginalName(refId) {
|
|
277
157
|
return this.seqIdToOriginalRefName[refId];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (!!this.seqIdToRefName) return [3 /*break*/, 3];
|
|
293
|
-
_b = this;
|
|
294
|
-
return [4 /*yield*/, sequenceAdapter.getRefNames(opts)];
|
|
295
|
-
case 2:
|
|
296
|
-
_b.seqIdToRefName = _f.sent();
|
|
297
|
-
_f.label = 3;
|
|
298
|
-
case 3:
|
|
299
|
-
refId = this.refNameToId(refName);
|
|
300
|
-
if (!(refId !== undefined)) return [3 /*break*/, 5];
|
|
301
|
-
if (originalRefName) {
|
|
302
|
-
this.seqIdToOriginalRefName[refId] = originalRefName;
|
|
303
|
-
}
|
|
304
|
-
return [4 /*yield*/, cram.getRecordsForRange(refId, start, end, opts)];
|
|
305
|
-
case 4:
|
|
306
|
-
records = _f.sent();
|
|
307
|
-
(0, util_1.checkAbortSignal)(signal);
|
|
308
|
-
_c = filterBy || {}, _d = _c.flagInclude, flagInclude_1 = _d === void 0 ? 0 : _d, _e = _c.flagExclude, flagExclude_1 = _e === void 0 ? 0 : _e, tagFilter_1 = _c.tagFilter, readName_1 = _c.readName;
|
|
309
|
-
filtered = records.filter(function (record) {
|
|
310
|
-
var flags = record.flags;
|
|
311
|
-
return (flags & flagInclude_1) === flagInclude_1 && !(flags & flagExclude_1);
|
|
312
|
-
});
|
|
313
|
-
if (tagFilter_1) {
|
|
314
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
315
|
-
filtered = filtered.filter(function (record) {
|
|
316
|
-
var val = record[tagFilter_1.tag];
|
|
317
|
-
return val === '*' ? val !== undefined : val === tagFilter_1.value;
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
if (readName_1) {
|
|
321
|
-
filtered = filtered.filter(
|
|
322
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
|
-
function (record) { return record.readName === readName_1; });
|
|
324
|
-
}
|
|
325
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
-
filtered.forEach(function (record) {
|
|
327
|
-
observer.next(_this.cramRecordToFeature(record));
|
|
328
|
-
});
|
|
329
|
-
return [3 /*break*/, 6];
|
|
330
|
-
case 5:
|
|
331
|
-
console.warn('Unknown refName', refName);
|
|
332
|
-
_f.label = 6;
|
|
333
|
-
case 6:
|
|
334
|
-
statusCallback('');
|
|
335
|
-
observer.complete();
|
|
336
|
-
return [2 /*return*/];
|
|
158
|
+
}
|
|
159
|
+
getFeatures(region, opts) {
|
|
160
|
+
const { signal, filterBy, statusCallback = () => { } } = opts || {};
|
|
161
|
+
const { refName, start, end, originalRefName } = region;
|
|
162
|
+
return (0, rxjs_1.ObservableCreate)(async (observer) => {
|
|
163
|
+
const { cram, sequenceAdapter } = await this.setup(opts);
|
|
164
|
+
statusCallback('Downloading alignments');
|
|
165
|
+
if (!this.seqIdToRefName) {
|
|
166
|
+
this.seqIdToRefName = await sequenceAdapter.getRefNames(opts);
|
|
167
|
+
}
|
|
168
|
+
const refId = this.refNameToId(refName);
|
|
169
|
+
if (refId !== undefined) {
|
|
170
|
+
if (originalRefName) {
|
|
171
|
+
this.seqIdToOriginalRefName[refId] = originalRefName;
|
|
337
172
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
173
|
+
const records = await cram.getRecordsForRange(refId, start, end, opts);
|
|
174
|
+
(0, util_1.checkAbortSignal)(signal);
|
|
175
|
+
const { flagInclude = 0, flagExclude = 0, tagFilter, readName, } = filterBy || {};
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
let filtered = records.filter((record) => {
|
|
178
|
+
const flags = record.flags;
|
|
179
|
+
return (flags & flagInclude) === flagInclude && !(flags & flagExclude);
|
|
180
|
+
});
|
|
181
|
+
if (tagFilter) {
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
|
+
filtered = filtered.filter((record) => {
|
|
184
|
+
const val = record[tagFilter.tag];
|
|
185
|
+
return val === '*' ? val !== undefined : val === tagFilter.value;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (readName) {
|
|
189
|
+
filtered = filtered.filter(
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
191
|
+
(record) => record.readName === readName);
|
|
192
|
+
}
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
194
|
+
filtered.forEach((record) => {
|
|
195
|
+
observer.next(this.cramRecordToFeature(record));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.warn('Unknown refName', refName);
|
|
200
|
+
}
|
|
201
|
+
statusCallback('');
|
|
202
|
+
observer.complete();
|
|
203
|
+
}, signal);
|
|
204
|
+
}
|
|
205
|
+
freeResources( /* { region } */) { }
|
|
206
|
+
cramRecordToFeature(record) {
|
|
343
207
|
return new CramSlightlyLazyFeature_1.default(record, this);
|
|
344
|
-
}
|
|
208
|
+
}
|
|
345
209
|
// we return the configured fetchSizeLimit, and the bytes for the region
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
fetchSizeLimit = this.getConf('fetchSizeLimit');
|
|
355
|
-
return [2 /*return*/, {
|
|
356
|
-
bytes: bytes,
|
|
357
|
-
fetchSizeLimit: fetchSizeLimit,
|
|
358
|
-
}];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
};
|
|
210
|
+
async estimateRegionsStats(regions, opts) {
|
|
211
|
+
const bytes = await this.bytesForRegions(regions, opts);
|
|
212
|
+
const fetchSizeLimit = this.getConf('fetchSizeLimit');
|
|
213
|
+
return {
|
|
214
|
+
bytes,
|
|
215
|
+
fetchSizeLimit,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
363
218
|
/**
|
|
364
219
|
* get the approximate number of bytes queried from the file for the given
|
|
365
220
|
* query regions
|
|
366
221
|
* @param regions - list of query regions
|
|
367
222
|
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
var refName = region.refName, start = region.start, end = region.end;
|
|
379
|
-
var chrId = _this.refNameToId(refName);
|
|
380
|
-
return cram.index.getEntriesForRange(chrId, start, end);
|
|
381
|
-
}))];
|
|
382
|
-
case 2:
|
|
383
|
-
blockResults = _a.sent();
|
|
384
|
-
return [2 /*return*/, blockResults.flat().reduce(function (a, b) { return a + b.sliceBytes; }, 0)];
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
return CramAdapter;
|
|
390
|
-
}(BaseAdapter_1.BaseFeatureDataAdapter));
|
|
223
|
+
async bytesForRegions(regions, _opts) {
|
|
224
|
+
const { cram } = await this.configure();
|
|
225
|
+
const blockResults = await Promise.all(regions.map(region => {
|
|
226
|
+
const { refName, start, end } = region;
|
|
227
|
+
const chrId = this.refNameToId(refName);
|
|
228
|
+
return cram.index.getEntriesForRange(chrId, start, end);
|
|
229
|
+
}));
|
|
230
|
+
return blockResults.flat().reduce((a, b) => a + b.sliceBytes, 0);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
391
233
|
exports.default = CramAdapter;
|
|
392
234
|
//# sourceMappingURL=CramAdapter.js.map
|