pdbe-molstar
Version:
Molstar implementation for PDBe
81 lines (80 loc) • 4.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomainAnnotationsColorThemeProvider = void 0;
exports.DomainAnnotationsColorTheme = DomainAnnotationsColorTheme;
const structure_1 = require("molstar/lib/mol-model/structure");
const color_1 = require("molstar/lib/mol-theme/color");
const color_2 = require("molstar/lib/mol-util/color");
const param_definition_1 = require("molstar/lib/mol-util/param-definition");
const prop_1 = require("./prop");
const DomainColors = {
/** Applied to a part of structure which is not included in the domain */
outside: color_2.Color.fromRgb(170, 170, 170),
/** Applied to a part of structure which is included in the domain */
inside: color_2.Color.fromRgb(255, 112, 3),
};
function makeDomainAnnotationsColorThemeParams(domainSources, domainNames) {
const map = {};
let defaultSource = undefined; // will be assigned to the first source with non-empty list of domains
const nSources = domainSources.length;
for (let i = 0; i < nSources; i++) {
const source = domainSources[i];
const domains = domainNames[i];
if (domains.length > 0) {
defaultSource !== null && defaultSource !== void 0 ? defaultSource : (defaultSource = source);
map[source] = param_definition_1.ParamDefinition.Group({
domain: param_definition_1.ParamDefinition.Select(domains[0], domains.map(dom => [dom, dom])),
}, { isFlat: true });
}
}
map['None'] = param_definition_1.ParamDefinition.Group({
domain: param_definition_1.ParamDefinition.Select('None', [['None', 'None']], { isHidden: true }), // this is to keep the same shape of props but `domain` param will not be displayed in UI
}, { isFlat: true });
return {
source: param_definition_1.ParamDefinition.MappedStatic(defaultSource !== null && defaultSource !== void 0 ? defaultSource : 'None', map, { options: Object.keys(map).map(source => [source, source]) }), // `options` is to keep case-sensitive database names in UI
};
}
/** DomainAnnotationsColorThemeParams for when the data are not available (yet or at all) */
const DummyDomainAnnotationsColorThemeParams = makeDomainAnnotationsColorThemeParams([], []);
function DomainAnnotationsColorTheme(ctx, props) {
let color;
const domainSource = props.source.name;
const domainName = props.source.params.domain;
if (ctx.structure && !ctx.structure.isEmpty && ctx.structure.models[0].customProperties.has(prop_1.DomainAnnotationsProvider.descriptor) && domainSource !== 'None') {
color = (location) => {
if (structure_1.StructureElement.Location.is(location) && prop_1.DomainAnnotations.isInDomain(location, domainSource, domainName)) {
return DomainColors.inside;
}
return DomainColors.outside;
};
}
else {
color = () => DomainColors.outside;
}
return {
factory: DomainAnnotationsColorTheme,
granularity: 'group',
color: color,
props: props,
description: 'Highlights Sequence and Structure Domain Annotations. Data obtained via PDBe.',
};
}
exports.DomainAnnotationsColorThemeProvider = {
name: 'pdbe-domain-annotations',
label: 'Domain annotations',
category: color_1.ColorTheme.Category.Misc,
factory: DomainAnnotationsColorTheme,
getParams: ctx => {
const domainTypes = prop_1.DomainAnnotations.getDomainTypes(ctx.structure);
const domainNames = prop_1.DomainAnnotations.getDomainNames(ctx.structure);
return makeDomainAnnotationsColorThemeParams(domainTypes, domainNames);
},
defaultValues: param_definition_1.ParamDefinition.getDefaultValues(DummyDomainAnnotationsColorThemeParams),
isApplicable: (ctx) => { var _a; return prop_1.DomainAnnotations.isApplicable((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models[0]); },
ensureCustomProperties: {
attach: (ctx, data) => {
return data.structure ? prop_1.DomainAnnotationsProvider.attach(ctx, data.structure.models[0], undefined, true) : Promise.resolve();
},
detach: (data) => data.structure && prop_1.DomainAnnotationsProvider.ref(data.structure.models[0], false),
},
};