@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
101 lines • 5.76 kB
JavaScript
import { __awaiter } from "tslib";
import { AnnotationReference, FeaturesType } from "@rcsb/rcsb-api-tools/lib/RcsbGraphQL/Types/Borrego/GqlTypes";
import { range } from "lodash";
import { rcsbRequestCtxManager } from "../../RcsbRequest/RcsbRequestContextManager";
import { RcsbFvTooltip } from "../../RcsbFvWeb/RcsbFvTooltip/RcsbFvTooltip";
export function addUnmodeledTrackBuilder(unmodeledTrackBuilder, externalTrackBuilder) {
const trackBuilder = (data) => __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) => __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
});
}) });
}
export class UnmodeledTrackBuilder {
constructor() {
this.unmodeledDescription = new Map();
}
filterFeatures(data) {
return __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 __awaiter(this, void 0, void 0, function* () {
var _a;
const nInstances = (yield 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) == 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) == 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 ? 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: AnnotationReference.PdbEntity,
target_id: rcsbContext.entityId,
features: [{
type: UNMODELED,
feature_positions: featurePositions
}]
}];
});
}
}
class UnobservedToolTip {
constructor(trackDescription) {
this.regularTooltip = new 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) != FeaturesType.UnobservedResidueXyz && (f === null || f === void 0 ? void 0 : f.type) != FeaturesType.UnobservedAtomXyz) });
});
}
const UNMODELED = "UNMODELED";
//# sourceMappingURL=UnmodeledTrackBuilder.js.map