UNPKG

@rcsb/rcsb-saguaro-app

Version:
116 lines (115 loc) 7.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RcsbFvGroupAlignment = void 0; const tslib_1 = require("tslib"); const RcsbFvAbstractModule_1 = require("./RcsbFvAbstractModule"); const GqlTypes_1 = require("@rcsb/rcsb-api-tools/lib/RcsbGraphQL/Types/Borrego/GqlTypes"); const MsaAlignmentTrackFactory_1 = require("../RcsbFvFactories/RcsbFvTrackFactory/TrackFactoryImpl/MsaAlignmentTrackFactory"); const Assertions_1 = require("../../RcsbUtils/Helpers/Assertions"); var assertDefined = Assertions_1.Assertions.assertDefined; const Operator_1 = require("../../RcsbUtils/Helpers/Operator"); const RcsbRequestContextManager_1 = require("../../RcsbRequest/RcsbRequestContextManager"); const RcsbClient_1 = require("../../RcsbGraphQL/RcsbClient"); const TagDelimiter_1 = require("@rcsb/rcsb-api-tools/lib/RcsbUtils/TagDelimiter"); class RcsbFvGroupAlignment extends RcsbFvAbstractModule_1.RcsbFvAbstractModule { protectedBuild() { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j; const buildConfig = this.buildConfig; assertDefined(buildConfig.groupId), assertDefined(buildConfig.group), assertDefined((_a = buildConfig.additionalConfig) === null || _a === void 0 ? void 0 : _a.page); const alignmentRequestContext = { group: buildConfig.group, groupId: buildConfig.groupId, filter: (_b = buildConfig.additionalConfig) === null || _b === void 0 ? void 0 : _b.alignmentFilter, page: (_c = buildConfig.additionalConfig) === null || _c === void 0 ? void 0 : _c.page, excludeLogo: (_d = buildConfig.additionalConfig) === null || _d === void 0 ? void 0 : _d.excludeLogo, from: buildConfig.from, to: buildConfig.to, dynamicDisplay: false, fitTitleWidth: true, excludeFirstRowLink: true, sequencePrefix: (_f = (_e = buildConfig.additionalConfig) === null || _e === void 0 ? void 0 : _e.sequencePrefix) !== null && _f !== void 0 ? _f : "", externalTrackBuilder: (_g = buildConfig.additionalConfig) === null || _g === void 0 ? void 0 : _g.externalTrackBuilder }; const alignmentResponse = yield this.alignmentCollector.collect(alignmentRequestContext, (_h = buildConfig.additionalConfig) === null || _h === void 0 ? void 0 : _h.alignmentFilter); const trackFactory = new MsaAlignmentTrackFactory_1.MsaAlignmentTrackFactory(this.getPolymerEntityInstanceTranslator()); const targetList = yield uniqueTargetList(alignmentResponse); const alignmentFeatures = yield collectFeatures({ groupId: buildConfig.groupId, externalTrackBuilder: (_j = buildConfig.additionalConfig) === null || _j === void 0 ? void 0 : _j.externalTrackBuilder, targetList }, this.annotationCollector); yield trackFactory.prepareFeatures(alignmentFeatures.map(af => { var _a; return (Object.assign(Object.assign({}, af), { feature: (_a = af.features) === null || _a === void 0 ? void 0 : _a.filter(f => (f === null || f === void 0 ? void 0 : f.type) == GqlTypes_1.FeaturesType.UnobservedResidueXyz) })); }), alignmentFeatures.map(af => { var _a; return (Object.assign(Object.assign({}, af), { feature: (_a = af.features) === null || _a === void 0 ? void 0 : _a.filter(f => (f === null || f === void 0 ? void 0 : f.type) == GqlTypes_1.FeaturesType.MaQaMetricLocalTypePlddt) })); })); yield this.buildAlignmentTracks(alignmentRequestContext, alignmentResponse, { alignmentTrackFactory: trackFactory }); collectNextPage(alignmentRequestContext, this.alignmentCollector, this.annotationCollector).then(() => console.log("Next page ready")); return void 0; }); } concatAlignmentAndAnnotationTracks() { this.rowConfigData = this.referenceTrack ? [this.referenceTrack].concat(this.alignmentTracks) : this.alignmentTracks; } getBoardConfig() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return Object.assign(Object.assign({}, this.boardConfigData), { length: yield this.alignmentCollector.getAlignmentLength(), includeAxis: true }); }); } } exports.RcsbFvGroupAlignment = RcsbFvGroupAlignment; function collectNextPage(alignmentRequestContext, alignmentCollector, annotationCollector) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const alignmentResponse = yield RcsbClient_1.rcsbClient.requestGroupAlignment({ group: alignmentRequestContext.group, groupId: alignmentRequestContext.groupId, page: { first: alignmentRequestContext.page.first, after: alignmentRequestContext.page.after + alignmentRequestContext.page.first }, excludeLogo: true }); const targetList = yield uniqueTargetList(alignmentResponse); if (alignmentRequestContext.groupId) { const alignmentFeatures = yield RcsbClient_1.rcsbClient.requestRcsbPdbGroupAnnotations(buildGroupAnnotationQuery({ groupId: alignmentRequestContext.groupId, targetList })); const featureTargetList = Operator_1.Operator.uniqueValues(alignmentFeatures.map(af => { var _a; return TagDelimiter_1.TagDelimiter.parseInstance((_a = af.target_id) !== null && _a !== void 0 ? _a : "").entryId; })); Operator_1.Operator.arrayChunk(featureTargetList, 100).forEach(ids => RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntryProperties(ids)); } }); } function uniqueTargetList(alignmentResponse) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b; const entityIds = Operator_1.Operator.uniqueValues((_b = (_a = alignmentResponse.target_alignments) === null || _a === void 0 ? void 0 : _a.map(ta => { assertDefined(ta === null || ta === void 0 ? void 0 : ta.target_id); return ta.target_id; })) !== null && _b !== void 0 ? _b : []); const instanceIds = (yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntityProperties(entityIds)).map(e => e.rcsbId); return Operator_1.Operator.uniqueValues(instanceIds !== null && instanceIds !== void 0 ? instanceIds : []); }); } function collectFeatures(annotationsContext, annotationCollector) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield annotationCollector.collect(Object.assign(Object.assign({}, buildGroupAnnotationQuery(annotationsContext)), { isSummary: false, externalTrackBuilder: annotationsContext.externalTrackBuilder })); }); } function buildGroupAnnotationQuery(annotationsContext) { return { group: GqlTypes_1.GroupReference.SequenceIdentity, groupId: annotationsContext.groupId, sources: [GqlTypes_1.AnnotationReference.PdbInstance], filters: [{ source: GqlTypes_1.AnnotationReference.PdbInstance, operation: GqlTypes_1.OperationType.Equals, field: GqlTypes_1.FieldName.Type, values: [GqlTypes_1.FeaturesType.UnobservedResidueXyz, GqlTypes_1.FeaturesType.MaQaMetricLocalTypePlddt] }, { source: GqlTypes_1.AnnotationReference.PdbInstance, operation: GqlTypes_1.OperationType.Equals, field: GqlTypes_1.FieldName.TargetId, values: annotationsContext.targetList }] }; }