UNPKG

molstar

Version:

A comprehensive macromolecular library.

102 lines (101 loc) 4.16 kB
"use strict"; /** * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SIFTSMappingColorThemeProvider = exports.SIFTSMappingColorThemeParams = void 0; exports.getSIFTSMappingColorThemeParams = getSIFTSMappingColorThemeParams; exports.SIFTSMappingColorTheme = SIFTSMappingColorTheme; const structure_1 = require("../../../mol-model/structure"); const categories_1 = require("../../../mol-theme/color/categories"); const color_1 = require("../../../mol-util/color"); const palette_1 = require("../../../mol-util/color/palette"); const param_definition_1 = require("../../../mol-util/param-definition"); const sifts_mapping_1 = require("../sifts-mapping"); const DefaultColor = (0, color_1.Color)(0xFAFAFA); const Description = 'Assigns a color based on SIFTS mapping.'; // same colors for same accessions const globalAccessionMap = new Map(); exports.SIFTSMappingColorThemeParams = { ...(0, palette_1.getPaletteParams)({ type: 'colors', colorList: 'set-1' }), }; function getSIFTSMappingColorThemeParams(ctx) { return exports.SIFTSMappingColorThemeParams; // TODO return copy } function SIFTSMappingColorTheme(ctx, props) { let color; if (ctx.structure) { for (const m of ctx.structure.models) { const mapping = sifts_mapping_1.SIFTSMapping.Provider.get(m).value; if (!mapping) continue; for (const acc of mapping.accession) { if (!acc || globalAccessionMap.has(acc)) continue; globalAccessionMap.set(acc, globalAccessionMap.size); } } const l = structure_1.StructureElement.Location.create(ctx.structure); const palette = (0, palette_1.getPalette)(globalAccessionMap.size + 1, props, { valueLabel: i => `${i}` }); const colorMap = new Map(); const getColor = (location) => { const key = sifts_mapping_1.SIFTSMapping.getKey(location); if (!key) return DefaultColor; if (colorMap.has(key)) return colorMap.get(key); const color = palette.color(globalAccessionMap.get(key)); colorMap.set(key, color); return color; }; color = (location) => { if (structure_1.StructureElement.Location.is(location) && structure_1.Unit.isAtomic(location.unit)) { return getColor(location); } else if (structure_1.Bond.isLocation(location)) { l.unit = location.aUnit; l.element = location.aUnit.elements[location.aIndex]; return getColor(l); } return DefaultColor; }; } else { color = () => DefaultColor; } return { factory: SIFTSMappingColorTheme, granularity: 'group', preferSmoothing: true, color, props, description: Description, }; } exports.SIFTSMappingColorThemeProvider = { name: 'sifts-mapping', label: 'SIFTS Mapping', category: categories_1.ColorThemeCategory.Residue, factory: SIFTSMappingColorTheme, getParams: getSIFTSMappingColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.SIFTSMappingColorThemeParams), isApplicable: (ctx) => { var _a; return !!((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models.some(m => sifts_mapping_1.SIFTSMapping.Provider.isApplicable(m))); }, ensureCustomProperties: { attach: async (ctx, data) => { if (!data.structure) return; for (const m of data.structure.models) { await sifts_mapping_1.SIFTSMapping.Provider.attach(ctx, m, void 0, true); } }, detach: (data) => { if (!data.structure) return; for (const m of data.structure.models) { sifts_mapping_1.SIFTSMapping.Provider.ref(m, false); } } } };