UNPKG

molstar

Version:

A comprehensive macromolecular library.

85 lines (84 loc) 4.03 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __awaiter, __generator } from "tslib"; import { CustomElementProperty } from '../../mol-model-props/common/custom-element-property'; import { Color } from '../../mol-util/color'; import { Asset } from '../../mol-util/assets'; var EvolutionaryConservationPalette = [ [255, 255, 129], [160, 37, 96], [240, 125, 171], [250, 201, 222], [252, 237, 244], [255, 255, 255], [234, 255, 255], [215, 255, 255], [140, 255, 255], [16, 200, 209] // 1 ].reverse().map(function (_a) { var r = _a[0], g = _a[1], b = _a[2]; return Color.fromRgb(r, g, b); }); var EvolutionaryConservationDefaultColor = Color(0x999999); export var EvolutionaryConservation = CustomElementProperty.create({ name: 'proteopedia-wrapper-evolutionary-conservation', label: 'Evolutionary Conservation', type: 'static', getData: function (model, ctx) { var _a; return __awaiter(this, void 0, void 0, function () { var id, url, json, annotations, conservationMap, _i, annotations_1, e, _b, _c, r, map, residueCount, residueOffsets, chainIndex, rI, cI, key, ann, aI; return __generator(this, function (_d) { switch (_d.label) { case 0: id = model.entryId.toLowerCase(); url = Asset.getUrlAsset(ctx.assetManager, "https://proteopedia.org/cgi-bin/cnsrf?".concat(id)); return [4 /*yield*/, ctx.assetManager.resolve(url, 'json').runInContext(ctx.runtime)]; case 1: json = _d.sent(); annotations = ((_a = json.data) === null || _a === void 0 ? void 0 : _a.residueAnnotations) || []; conservationMap = new Map(); for (_i = 0, annotations_1 = annotations; _i < annotations_1.length; _i++) { e = annotations_1[_i]; for (_b = 0, _c = e.ids; _b < _c.length; _b++) { r = _c[_b]; conservationMap.set(r, e.annotation); } } map = new Map(); residueCount = model.atomicHierarchy.residues._rowCount; residueOffsets = model.atomicHierarchy.residueAtomSegments.offsets; chainIndex = model.atomicHierarchy.chainAtomSegments.index; for (rI = 0; rI < residueCount; rI++) { cI = chainIndex[residueOffsets[rI]]; key = "".concat(model.atomicHierarchy.chains.auth_asym_id.value(cI), " ").concat(model.atomicHierarchy.residues.auth_seq_id.value(rI)); if (!conservationMap.has(key)) continue; ann = conservationMap.get(key); for (aI = residueOffsets[rI]; aI < residueOffsets[rI + 1]; aI++) { map.set(aI, ann); } } return [2 /*return*/, { value: map, assets: [json] }]; } }); }); }, coloring: { getColor: function (e) { if (e < 1 || e > 10) return EvolutionaryConservationDefaultColor; return EvolutionaryConservationPalette[e - 1]; }, defaultColor: EvolutionaryConservationDefaultColor }, getLabel: function (e) { if (e === 10) return "Evolutionary Conservation: Insufficient Data"; return e ? "Evolutionary Conservation: ".concat(e) : void 0; } });