UNPKG

molstar

Version:

A comprehensive macromolecular library.

111 lines 4.64 kB
"use strict"; /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SequenceIdColorThemeProvider = exports.SequenceIdColorTheme = exports.getSequenceIdColorThemeParams = exports.SequenceIdColorThemeParams = void 0; var structure_1 = require("../../mol-model/structure"); var color_1 = require("../../mol-util/color"); var param_definition_1 = require("../../mol-util/param-definition"); var DefaultColor = (0, color_1.Color)(0xCCCCCC); var Description = 'Gives every polymer residue a color based on its `seq_id` value.'; exports.SequenceIdColorThemeParams = { list: param_definition_1.ParamDefinition.ColorList('turbo', { presetKind: 'scale' }), }; function getSequenceIdColorThemeParams(ctx) { return exports.SequenceIdColorThemeParams; // TODO return copy } exports.getSequenceIdColorThemeParams = getSequenceIdColorThemeParams; function getSeqId(unit, element) { var model = unit.model; switch (unit.kind) { case 0 /* Atomic */: var residueIndex = model.atomicHierarchy.residueAtomSegments.index[element]; return model.atomicHierarchy.residues.label_seq_id.value(residueIndex); case 1 /* Spheres */: return Math.round((model.coarseHierarchy.spheres.seq_id_begin.value(element) + model.coarseHierarchy.spheres.seq_id_end.value(element)) / 2); case 2 /* Gaussians */: return Math.round((model.coarseHierarchy.gaussians.seq_id_begin.value(element) + model.coarseHierarchy.gaussians.seq_id_end.value(element)) / 2); } } function getSequenceLength(unit, element) { var model = unit.model; var entityId = ''; switch (unit.kind) { case 0 /* Atomic */: var chainIndex = model.atomicHierarchy.chainAtomSegments.index[element]; entityId = model.atomicHierarchy.chains.label_entity_id.value(chainIndex); break; case 1 /* Spheres */: entityId = model.coarseHierarchy.spheres.entity_id.value(element); break; case 2 /* Gaussians */: entityId = model.coarseHierarchy.gaussians.entity_id.value(element); break; } if (entityId === '') return 0; var entityIndex = model.entities.getEntityIndex(entityId); if (entityIndex === -1) return 0; var entity = model.sequence.byEntityKey[entityIndex]; if (entity === undefined) return 0; return entity.sequence.length; } function SequenceIdColorTheme(ctx, props) { var scale = color_1.ColorScale.create({ listOrName: props.list.colors, minLabel: 'Start', maxLabel: 'End', }); var color = function (location) { if (structure_1.StructureElement.Location.is(location)) { var unit = location.unit, element = location.element; var seq_id = getSeqId(unit, element); if (seq_id > 0) { var seqLen = getSequenceLength(unit, element); if (seqLen) { scale.setDomain(0, seqLen - 1); return scale.color(seq_id); } } } else if (structure_1.Bond.isLocation(location)) { var aUnit = location.aUnit, aIndex = location.aIndex; var seq_id = getSeqId(aUnit, aUnit.elements[aIndex]); if (seq_id > 0) { var seqLen = getSequenceLength(aUnit, aUnit.elements[aIndex]); if (seqLen) { scale.setDomain(0, seqLen - 1); return scale.color(seq_id); } } } return DefaultColor; }; return { factory: SequenceIdColorTheme, granularity: 'group', preferSmoothing: true, color: color, props: props, description: Description, legend: scale ? scale.legend : undefined }; } exports.SequenceIdColorTheme = SequenceIdColorTheme; exports.SequenceIdColorThemeProvider = { name: 'sequence-id', label: 'Sequence Id', category: "Residue Property" /* Residue */, factory: SequenceIdColorTheme, getParams: getSequenceIdColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.SequenceIdColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } }; //# sourceMappingURL=sequence-id.js.map