UNPKG

molstar

Version:

A comprehensive macromolecular library.

88 lines (87 loc) 4.21 kB
"use strict"; /** * 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> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EvolutionaryConservation = void 0; var tslib_1 = require("tslib"); var custom_element_property_1 = require("../../mol-model-props/common/custom-element-property"); var color_1 = require("../../mol-util/color"); var assets_1 = require("../../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_1.Color.fromRgb(r, g, b); }); var EvolutionaryConservationDefaultColor = (0, color_1.Color)(0x999999); exports.EvolutionaryConservation = custom_element_property_1.CustomElementProperty.create({ name: 'proteopedia-wrapper-evolutionary-conservation', label: 'Evolutionary Conservation', type: 'static', getData: function (model, ctx) { var _a; return tslib_1.__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 tslib_1.__generator(this, function (_d) { switch (_d.label) { case 0: id = model.entryId.toLowerCase(); url = assets_1.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; } });