@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
106 lines (105 loc) • 6.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnmodeledTrackBuilder = void 0;
exports.addUnmodeledTrackBuilder = addUnmodeledTrackBuilder;
const tslib_1 = require("tslib");
const GqlTypes_1 = require("@rcsb/rcsb-api-tools/lib/RcsbGraphQL/Types/Borrego/GqlTypes");
const lodash_1 = require("lodash");
const RcsbRequestContextManager_1 = require("../../RcsbRequest/RcsbRequestContextManager");
const RcsbFvTooltip_1 = require("../../RcsbFvWeb/RcsbFvTooltip/RcsbFvTooltip");
function addUnmodeledTrackBuilder(unmodeledTrackBuilder, externalTrackBuilder) {
const trackBuilder = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b;
return [
...(_b = yield ((_a = externalTrackBuilder === null || externalTrackBuilder === void 0 ? void 0 : externalTrackBuilder.filterFeatures) === null || _a === void 0 ? void 0 : _a.call(externalTrackBuilder, data))) !== null && _b !== void 0 ? _b : [],
...yield unmodeledTrackBuilder.filterFeatures(data)
];
});
return Object.assign(Object.assign({}, externalTrackBuilder), { filterFeatures: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
(_a = externalTrackBuilder === null || externalTrackBuilder === void 0 ? void 0 : externalTrackBuilder.filterFeatures) === null || _a === void 0 ? void 0 : _a.call(externalTrackBuilder, data);
return trackBuilder({
annotations: (_c = yield ((_b = externalTrackBuilder === null || externalTrackBuilder === void 0 ? void 0 : externalTrackBuilder.filterFeatures) === null || _b === void 0 ? void 0 : _b.call(externalTrackBuilder, data))) !== null && _c !== void 0 ? _c : data.annotations,
rcsbContext: data.rcsbContext
});
}) });
}
class UnmodeledTrackBuilder {
constructor() {
this.unmodeledDescription = new Map();
}
filterFeatures(data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!data.rcsbContext)
return data.annotations;
return [
...yield this.buildUnobserved(data.annotations, data.rcsbContext),
...filterUnobserved(data.annotations)
];
});
}
getTooltip() {
return new UnobservedToolTip(this.unmodeledDescription);
}
buildUnobserved(annotations, rcsbContext) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a;
const nInstances = (yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntityProperties((_a = rcsbContext.entityId) !== null && _a !== void 0 ? _a : "none"))[0].instances.length;
const featurePositions = Array.from(annotations.filter(ann => {
var _a, _b, _c;
return (_c = (_b = (_a = ann.features) === null || _a === void 0 ? void 0 : _a.filter(f => (f === null || f === void 0 ? void 0 : f.type) == GqlTypes_1.FeaturesType.UnobservedResidueXyz)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0 > 0;
}).map(ann => {
var _a, _b;
return (_b = (_a = ann.features) === null || _a === void 0 ? void 0 : _a.filter((f) => (f === null || f === void 0 ? void 0 : f.type) == GqlTypes_1.FeaturesType.UnobservedResidueXyz)) !== null && _b !== void 0 ? _b : [];
}).flat().map(feature => {
var _a, _b;
return (_b = (_a = feature.feature_positions) === null || _a === void 0 ? void 0 : _a.filter((p) => typeof p != "undefined")) !== null && _b !== void 0 ? _b : [];
}).flat().map(p => p.beg_seq_id && p.end_seq_id ? (0, lodash_1.range)(p.beg_seq_id, p.end_seq_id + 1) : []).flat().reduce((map, idx) => { var _a; return map.set(idx, ((_a = map.get(idx)) !== null && _a !== void 0 ? _a : 0) + 1); }, new Map).entries()).map(([idx, unobserved]) => {
this.unmodeledDescription.set(`${rcsbContext.entityId}:${idx}`, [unobserved, nInstances]);
return {
beg_seq_id: idx,
values: [Math.round(unobserved / nInstances * 100) / 100]
};
});
return [{
source: GqlTypes_1.AnnotationReference.PdbEntity,
target_id: rcsbContext.entityId,
features: [{
type: UNMODELED,
feature_positions: featurePositions
}]
}];
});
}
}
exports.UnmodeledTrackBuilder = UnmodeledTrackBuilder;
class UnobservedToolTip {
constructor(trackDescription) {
this.regularTooltip = new RcsbFvTooltip_1.RcsbFvTooltip();
this.trackDescription = trackDescription;
}
showTooltip(d) {
return this.regularTooltip.showTooltip(d);
}
showTooltipDescription(d) {
if (d.title == UNMODELED)
return this.overloadTooltipDescription(d);
return this.regularTooltip.showTooltipDescription(d);
}
overloadTooltipDescription(d) {
var _a;
if (!this.trackDescription.has(`${d.sourceId}:${d.begin}`))
return undefined;
const tooltipDescriptionDiv = document.createElement("div");
const [unobserved, total] = (_a = this.trackDescription.get(`${d.sourceId}:${d.begin}`)) !== null && _a !== void 0 ? _a : [0, 0];
tooltipDescriptionDiv.append(`Unmodeled in ${unobserved} of ${total} chains`);
return tooltipDescriptionDiv;
}
}
function filterUnobserved(annotations) {
return annotations.map(ann => {
var _a;
return Object.assign(Object.assign({}, ann), { features: (_a = ann.features) === null || _a === void 0 ? void 0 : _a.filter(f => (f === null || f === void 0 ? void 0 : f.type) != GqlTypes_1.FeaturesType.UnobservedResidueXyz && (f === null || f === void 0 ? void 0 : f.type) != GqlTypes_1.FeaturesType.UnobservedAtomXyz) });
});
}
const UNMODELED = "UNMODELED";