UNPKG

@rcsb/rcsb-saguaro-app

Version:
112 lines 7.26 kB
import { __awaiter } from "tslib"; import { RcsbFvAbstractModule } from "./RcsbFvAbstractModule"; import { FieldName, GroupReference, OperationType, AnnotationReference, FeaturesType } from "@rcsb/rcsb-api-tools/lib/RcsbGraphQL/Types/Borrego/GqlTypes"; import { MsaAlignmentTrackFactory } from "../RcsbFvFactories/RcsbFvTrackFactory/TrackFactoryImpl/MsaAlignmentTrackFactory"; import { Assertions } from "../../RcsbUtils/Helpers/Assertions"; var assertDefined = Assertions.assertDefined; import { Operator } from "../../RcsbUtils/Helpers/Operator"; import { rcsbRequestCtxManager } from "../../RcsbRequest/RcsbRequestContextManager"; import { rcsbClient } from "../../RcsbGraphQL/RcsbClient"; import { TagDelimiter } from "@rcsb/rcsb-api-tools/lib/RcsbUtils/TagDelimiter"; export class RcsbFvGroupAlignment extends RcsbFvAbstractModule { protectedBuild() { return __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(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) == 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) == 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 __awaiter(this, void 0, void 0, function* () { return Object.assign(Object.assign({}, this.boardConfigData), { length: yield this.alignmentCollector.getAlignmentLength(), includeAxis: true }); }); } } function collectNextPage(alignmentRequestContext, alignmentCollector, annotationCollector) { return __awaiter(this, void 0, void 0, function* () { const alignmentResponse = yield 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.requestRcsbPdbGroupAnnotations(buildGroupAnnotationQuery({ groupId: alignmentRequestContext.groupId, targetList })); const featureTargetList = Operator.uniqueValues(alignmentFeatures.map(af => { var _a; return TagDelimiter.parseInstance((_a = af.target_id) !== null && _a !== void 0 ? _a : "").entryId; })); Operator.arrayChunk(featureTargetList, 100).forEach(ids => rcsbRequestCtxManager.getEntryProperties(ids)); } }); } function uniqueTargetList(alignmentResponse) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const entityIds = 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 rcsbRequestCtxManager.getEntityProperties(entityIds)).map(e => e.rcsbId); return Operator.uniqueValues(instanceIds !== null && instanceIds !== void 0 ? instanceIds : []); }); } function collectFeatures(annotationsContext, annotationCollector) { return __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: GroupReference.SequenceIdentity, groupId: annotationsContext.groupId, sources: [AnnotationReference.PdbInstance], filters: [{ source: AnnotationReference.PdbInstance, operation: OperationType.Equals, field: FieldName.Type, values: [FeaturesType.UnobservedResidueXyz, FeaturesType.MaQaMetricLocalTypePlddt] }, { source: AnnotationReference.PdbInstance, operation: OperationType.Equals, field: FieldName.TargetId, values: annotationsContext.targetList }] }; } //# sourceMappingURL=RcsbFvGroupAlignment.js.map