UNPKG

@rcsb/rcsb-saguaro-app

Version:
99 lines 5.52 kB
import { __awaiter } from "tslib"; import { Assertions } from "../../../../RcsbUtils/Helpers/Assertions"; var assertDefined = Assertions.assertDefined; export class AnnotationBlockManager { constructor(trackManagerFactory, rcsbAnnotationConfig, polymerEntityInstanceTranslator) { this.annotationTracks = new Map(); this.trackManagerFactory = trackManagerFactory; this.rcsbAnnotationConfig = rcsbAnnotationConfig; this.polymerEntityInstanceTranslator = polymerEntityInstanceTranslator; } setData(requestConfig, data) { return __awaiter(this, void 0, void 0, function* () { yield this.processAnnotations(requestConfig, data); this.mergeTracks(); }); } getTracks() { var _a; return (_a = this.orderedTypes() .filter(type => { var _a, _b; return this.has(type) && ((_b = (_a = this.annotationTracks.get(type)) === null || _a === void 0 ? void 0 : _a.size()) !== null && _b !== void 0 ? _b : 0) > 0; }) .map(type => this.annotationTracks.get(type)) .filter((track) => track != null)) !== null && _a !== void 0 ? _a : []; } has(type) { return this.annotationTracks.has(type); } orderedTypes() { return [ this.rcsbAnnotationConfig.instanceOrder(), this.rcsbAnnotationConfig.entityOrder(), this.rcsbAnnotationConfig.uniprotOrder(), Array.from(this.annotationTracks.keys()).filter(type => !this.rcsbAnnotationConfig.allTypes().has(type)) ].flat(); } processAnnotations(requestConfig, data) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; yield Promise.all(data.map(ann => { var _a, _b; return (_b = (_a = ann.features) === null || _a === void 0 ? void 0 : _a.map((feature) => __awaiter(this, void 0, void 0, function* () { if (feature) return yield this.addFeature(requestConfig, ann, feature); }))) !== null && _b !== void 0 ? _b : []; }).flat()); (_b = (_a = requestConfig.annotationProcessing) === null || _a === void 0 ? void 0 : _a.computeAnnotationValue) === null || _b === void 0 ? void 0 : _b.call(_a, this.annotationTracks); }); } addFeature(requestConfig, ann, feature) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; if (feature.type && ((_a = this.rcsbAnnotationConfig.getConfig(feature.type)) === null || _a === void 0 ? void 0 : _a.ignore)) return; const type = yield this.rcsbAnnotationConfig.getAnnotationType(requestConfig, ann, feature); if (!this.annotationTracks.has(type)) { const o = (_b = this.rcsbAnnotationConfig.getConfig(type)) !== null && _b !== void 0 ? _b : { type: type, display: "block" /* RcsbFvDisplayTypes.BLOCK */, title: type, provenanceList: new Set() }; assertDefined(o, `Unknown type: ${type}`); this.annotationTracks.set(type, this.trackManagerFactory.getTrackManager(type, o, this.polymerEntityInstanceTranslator)); } const queryId = (_c = requestConfig.queryId) !== null && _c !== void 0 ? _c : requestConfig.groupId; assertDefined(queryId, "undefined queryId or groupId"); assertDefined(ann.source, "undefined source"); assertDefined(ann.target_id, "undefined target_id"); (_d = this.annotationTracks.get(type)) === null || _d === void 0 ? void 0 : _d.addFeature({ reference: (_e = requestConfig.reference) !== null && _e !== void 0 ? _e : undefined, queryId: queryId, source: ann.source, targetId: ann.target_id, feature: feature }, requestConfig.annotationProcessing); }); } mergeTracks() { const typeList = Array.from(this.annotationTracks.keys()); typeList.forEach((type) => { var _a, _b, _c, _d, _e; if (this.rcsbAnnotationConfig.isMergedType(type)) { const newType = (_a = this.rcsbAnnotationConfig.getMergeConfig(type)) === null || _a === void 0 ? void 0 : _a.type; assertDefined(newType); const color = (_b = this.rcsbAnnotationConfig.getConfig(type)) === null || _b === void 0 ? void 0 : _b.color; if (!this.annotationTracks.has(newType)) { const o = this.rcsbAnnotationConfig.getConfig(newType); assertDefined(o); this.annotationTracks.set(newType, this.trackManagerFactory.getTrackManager(newType, o, this.polymerEntityInstanceTranslator)); } const o = this.annotationTracks.get(type); if (o && typeof color === "string") (_c = this.annotationTracks.get(newType)) === null || _c === void 0 ? void 0 : _c.addAll(o, color); this.rcsbAnnotationConfig.addMultipleProvenance(newType, Array.from((_e = (_d = this.annotationTracks.get(newType)) === null || _d === void 0 ? void 0 : _d.getTrackProvenance()) !== null && _e !== void 0 ? _e : [])); this.annotationTracks.delete(type); } }); } } //# sourceMappingURL=AnnotationBlockManager.js.map