UNPKG

pdbe-molstar

Version:
60 lines (59 loc) 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SequenceColor = void 0; const model_1 = require("molstar/lib/mol-plugin-state/transforms/model"); const context_1 = require("molstar/lib/mol-plugin-ui/context"); const behavior_1 = require("molstar/lib/mol-plugin/behavior"); const param_definition_1 = require("molstar/lib/mol-util/param-definition"); const rxjs_1 = require("rxjs"); const color_1 = require("./color"); const sequence_color_annotations_prop_1 = require("./sequence-color-annotations-prop"); const sequence_color_theme_prop_1 = require("./sequence-color-theme-prop"); /** Allows coloring residues in sequence panel */ exports.SequenceColor = behavior_1.PluginBehavior.create({ name: 'sequence-color', category: 'misc', display: { name: 'Sequence Color', description: 'Sequence Color extension, allows assigning custom residue colors to be shown in the sequence panel, based on a custom structure property', }, ctor: class extends behavior_1.PluginBehavior.Handler { register() { var _a; var _b; const colorThemeRegistry = this.ctx.representation.structure.themes.colorThemeRegistry; this.ctx.customStructureProperties.register(sequence_color_theme_prop_1.SequenceColorThemeProperty.makeProvider(colorThemeRegistry), this.params.autoAttach); this.ctx.customStructureProperties.register(sequence_color_annotations_prop_1.SequenceColorAnnotationsProperty.Provider, this.params.autoAttach); const customColorThemeProvider = color_1.CustomSequenceColorTheme.makeProvider(colorThemeRegistry); if (this.ctx instanceof context_1.PluginUIContext) { const theme = (_a = (_b = this.ctx.customUIState).experimentalSequenceColorTheme) !== null && _a !== void 0 ? _a : (_b.experimentalSequenceColorTheme = new rxjs_1.BehaviorSubject(undefined)); this.sub = this.ctx.state.events.cell.stateUpdated.subscribe(s => { if (s.cell.transform.transformer === model_1.CustomStructureProperties) { theme.next({ provider: customColorThemeProvider }); } }); } } update(p) { const updated = this.params.autoAttach !== p.autoAttach; this.params.autoAttach = p.autoAttach; this.ctx.customStructureProperties.setDefaultAutoAttach(sequence_color_theme_prop_1.SequenceColorThemeProperty.Name, this.params.autoAttach); this.ctx.customStructureProperties.setDefaultAutoAttach(sequence_color_annotations_prop_1.SequenceColorAnnotationsProperty.Name, this.params.autoAttach); return updated; } unregister() { var _a; this.ctx.customStructureProperties.unregister(sequence_color_theme_prop_1.SequenceColorThemeProperty.Name); this.ctx.customStructureProperties.unregister(sequence_color_annotations_prop_1.SequenceColorAnnotationsProperty.Name); (_a = this.sub) === null || _a === void 0 ? void 0 : _a.unsubscribe(); this.sub = undefined; if (this.ctx instanceof context_1.PluginUIContext) { const theme = this.ctx.customUIState.experimentalSequenceColorTheme; theme === null || theme === void 0 ? void 0 : theme.next(undefined); } } }, params: () => ({ autoAttach: param_definition_1.ParamDefinition.Boolean(true), }), });