molstar
Version:
A comprehensive macromolecular library.
114 lines • 5.12 kB
JavaScript
/**
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { __assign, __awaiter, __generator } from "tslib";
import { Bond, StructureElement, Unit } from '../../../mol-model/structure';
import { Color } from '../../../mol-util/color';
import { getPalette, getPaletteParams } from '../../../mol-util/color/palette';
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { BestDatabaseSequenceMapping } from '../best-database-mapping';
var DefaultColor = Color(0xFAFAFA);
var Description = 'Assigns a color based on best dababase sequence mapping.';
// same colors for same accessions
var globalAccessionMap = new Map();
export var BestDatabaseSequenceMappingColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: 'set-1' }));
export function getBestDatabaseSequenceMappingColorThemeParams(ctx) {
return BestDatabaseSequenceMappingColorThemeParams; // TODO return copy
}
export function BestDatabaseSequenceMappingColorTheme(ctx, props) {
var color;
if (ctx.structure) {
for (var _i = 0, _a = ctx.structure.models; _i < _a.length; _i++) {
var m = _a[_i];
var mapping = BestDatabaseSequenceMapping.Provider.get(m).value;
if (!mapping)
continue;
for (var _b = 0, _c = mapping.accession; _b < _c.length; _b++) {
var acc = _c[_b];
if (!acc || globalAccessionMap.has(acc))
continue;
globalAccessionMap.set(acc, globalAccessionMap.size);
}
}
var l_1 = StructureElement.Location.create(ctx.structure);
var palette_1 = getPalette(globalAccessionMap.size + 1, props, { valueLabel: function (i) { return "" + i; } });
var colorMap_1 = new Map();
var getColor_1 = function (location) {
var key = BestDatabaseSequenceMapping.getKey(location);
if (!key)
return DefaultColor;
if (colorMap_1.has(key))
return colorMap_1.get(key);
var color = palette_1.color(globalAccessionMap.get(key));
colorMap_1.set(key, color);
return color;
};
color = function (location) {
if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
return getColor_1(location);
}
else if (Bond.isLocation(location)) {
l_1.unit = location.aUnit;
l_1.element = location.aUnit.elements[location.aIndex];
return getColor_1(l_1);
}
return DefaultColor;
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: BestDatabaseSequenceMappingColorTheme,
granularity: 'group',
preferSmoothing: true,
color: color,
props: props,
description: Description,
};
}
export var BestDatabaseSequenceMappingColorThemeProvider = {
name: 'best-sequence-database-mapping',
label: 'Best Database Sequence Mapping',
category: "Residue Property" /* Residue */,
factory: BestDatabaseSequenceMappingColorTheme,
getParams: getBestDatabaseSequenceMappingColorThemeParams,
defaultValues: PD.getDefaultValues(BestDatabaseSequenceMappingColorThemeParams),
isApplicable: function (ctx) { var _a; return !!((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models.some(function (m) { return BestDatabaseSequenceMapping.Provider.isApplicable(m); })); },
ensureCustomProperties: {
attach: function (ctx, data) { return __awaiter(void 0, void 0, void 0, function () {
var _i, _a, m;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!data.structure)
return [2 /*return*/];
_i = 0, _a = data.structure.models;
_b.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
m = _a[_i];
return [4 /*yield*/, BestDatabaseSequenceMapping.Provider.attach(ctx, m, void 0, true)];
case 2:
_b.sent();
_b.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
}); },
detach: function (data) {
if (!data.structure)
return;
for (var _i = 0, _a = data.structure.models; _i < _a.length; _i++) {
var m = _a[_i];
BestDatabaseSequenceMapping.Provider.ref(m, false);
}
}
}
};
//# sourceMappingURL=best-database-mapping.js.map