@3dbionotes/pdbe-molstar
Version:
Molstar implementation for PDBe
739 lines • 38.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SequenceView = exports.getStructure = exports.getStructureOptions = exports.getOperatorOptions = exports.getChainNumberedIdFromStructAsymId = exports.getEntityIdFromStructAsymId = exports.getStructAsymIdFromChainId = exports.getChainIdFromNumberedId = exports.getChainNumberedIdFromChainId = exports.getEntityIdFromChainId = exports.getEntityChainPairs = exports.getChainOptions = exports.getModelEntityOptions = exports.getLigand = exports.getSequenceWrapper = exports.splitModelEntityId = exports.opKey = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
/* File from molstar, modified in order to synchronize with viewer */
/* Extracted from: Commit df3a7e5 (change access modifiers) MKampfrath, Dec 12 2022 */
/* Import with no modifications: Commit fcc0c6c (Add SequenceView component) p3rcypj, Dec 4 2024 */
/**
* Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
*/
var lodash_1 = tslib_1.__importDefault(require("lodash"));
var React = tslib_1.__importStar(require("react"));
var base_1 = require("Molstar/mol-plugin-ui/base");
var objects_1 = require("Molstar/mol-plugin-state/objects");
var sequence_1 = require("Molstar/mol-plugin-ui/sequence/sequence");
var structure_1 = require("Molstar/mol-model/structure");
var polymer_1 = require("Molstar/mol-plugin-ui/sequence/polymer");
var marker_action_1 = require("Molstar/mol-util/marker-action");
var parameters_1 = require("Molstar/mol-plugin-ui/controls/parameters");
var param_definition_1 = require("Molstar/mol-util/param-definition");
var hetero_1 = require("Molstar/mol-plugin-ui/sequence/hetero");
var mol_state_1 = require("Molstar/mol-state");
var chain_1 = require("Molstar/mol-plugin-ui/sequence/chain");
var element_1 = require("Molstar/mol-plugin-ui/sequence/element");
var label_1 = require("Molstar/mol-theme/label");
var icons_1 = require("Molstar/mol-plugin-ui/controls/icons");
var array_1 = require("Molstar/mol-util/array");
var MaxDisplaySequenceLength = 5000;
// TODO: add virtualized Select controls (at best with a search box)?
var MaxSelectOptionsCount = 1000;
var MaxSequenceWrappersCount = 30;
function opKey(l) {
var ids = structure_1.StructureProperties.unit.pdbx_struct_oper_list_ids(l);
var ncs = structure_1.StructureProperties.unit.struct_ncs_oper_id(l);
var hkl = structure_1.StructureProperties.unit.hkl(l);
var spgrOp = structure_1.StructureProperties.unit.spgrOp(l);
return "".concat(ids.sort().join(','), "|").concat(ncs, "|").concat(hkl, "|").concat(spgrOp);
}
exports.opKey = opKey;
function splitModelEntityId(modelEntityId) {
var _a = modelEntityId.split('|'), modelIdx = _a[0], entityId = _a[1];
return [parseInt(modelIdx), entityId];
}
exports.splitModelEntityId = splitModelEntityId;
function getSequenceWrapper(state, structureSelection) {
var structure = state.structure, modelEntityId = state.modelEntityId, chainGroupId = state.chainGroupId, operatorKey = state.operatorKey;
var l = structure_1.StructureElement.Location.create(structure);
var _a = splitModelEntityId(modelEntityId), modelIdx = _a[0], entityId = _a[1];
var units = [];
for (var _i = 0, _b = structure.units; _i < _b.length; _i++) {
var unit = _b[_i];
structure_1.StructureElement.Location.set(l, structure, unit, unit.elements[0]);
if (structure.getModelIndex(unit.model) !== modelIdx)
continue;
if (structure_1.StructureProperties.entity.id(l) !== entityId)
continue;
if (unit.chainGroupId !== chainGroupId)
continue;
if (opKey(l) !== operatorKey)
continue;
units.push(unit);
}
if (units.length > 0) {
var data = { structure: structure, units: units };
var unit = units[0];
var sw = void 0;
if (unit.polymerElements.length) {
var l_1 = structure_1.StructureElement.Location.create(structure, unit, unit.elements[0]);
var entitySeq = unit.model.sequence.byEntityKey[structure_1.StructureProperties.entity.key(l_1)];
// check if entity sequence is available
if (entitySeq && entitySeq.sequence.length <= MaxDisplaySequenceLength) {
sw = new polymer_1.PolymerSequenceWrapper(data);
}
else {
var polymerElementCount = units.reduce(function (a, v) { return a + v.polymerElements.length; }, 0);
if (structure_1.Unit.isAtomic(unit) || polymerElementCount > MaxDisplaySequenceLength) {
sw = new chain_1.ChainSequenceWrapper(data);
}
else {
sw = new element_1.ElementSequenceWrapper(data);
}
}
}
else if (structure_1.Unit.isAtomic(unit)) {
var residueCount = units.reduce(function (a, v) { return a + v.residueCount; }, 0);
if (residueCount > MaxDisplaySequenceLength) {
sw = new chain_1.ChainSequenceWrapper(data);
}
else {
sw = new hetero_1.HeteroSequenceWrapper(data);
}
}
else {
console.warn('should not happen, expecting coarse units to be polymeric');
sw = new chain_1.ChainSequenceWrapper(data);
}
sw.markResidue(structureSelection.getLoci(structure), marker_action_1.MarkerAction.Select);
return sw;
}
else {
return 'No sequence available';
}
}
exports.getSequenceWrapper = getSequenceWrapper;
function getLigand(options, structure) {
var ligands = structure.units.flatMap(function (unit) {
return Array.from(unit.elements).flatMap(function (element) {
var location = {
kind: "element-location",
structure: structure,
unit: unit,
element: element,
};
var compIds = structure_1.StructureProperties.residue.microheterogeneityCompIds(location);
var type = structure_1.StructureProperties.residue.group_PDB(location);
var authSeqId = structure_1.StructureProperties.residue.auth_seq_id(location);
var chainId = structure_1.StructureProperties.chain.auth_asym_id(location);
var structAsymId = structure_1.StructureProperties.chain.label_asym_id(location);
// Debug ligands without previous filtering
// const ligand = [compIds[0], authSeqId].join("-");
return { type: type, compIds: compIds, authSeqId: authSeqId, chainId: chainId, structAsymId: structAsymId, id: [compIds[0], authSeqId].join("-") };
});
});
var groupedLigandsById = lodash_1.default.groupBy(ligands, 'id');
return groupedLigandsById[options.ligandId].filter(function (ligand) { return ligand.chainId === options.chainId; })[0];
}
exports.getLigand = getLigand;
function getModelEntityOptions(structure, options) {
var entityOptions = [];
var l = structure_1.StructureElement.Location.create(structure);
var seen = new Set();
for (var _i = 0, _a = structure.units; _i < _a.length; _i++) {
var unit = _a[_i];
structure_1.StructureElement.Location.set(l, structure, unit, unit.elements[0]);
var id = structure_1.StructureProperties.entity.id(l);
var modelIdx = structure.getModelIndex(unit.model);
var key = "".concat(modelIdx, "|").concat(id);
if (seen.has(key))
continue;
if (options.onlyPolymers && structure_1.StructureProperties.entity.type(l) !== 'polymer')
continue;
var description = structure_1.StructureProperties.entity.pdbx_description(l).join(', ');
if (structure.models.length) {
if (structure.representativeModel) { // indicates model trajectory
description += " (Model ".concat(structure.models[modelIdx].modelNum, ")");
}
else if (description.startsWith('Polymer ')) { // indicates generic entity name
description += " (".concat(structure.models[modelIdx].entry, ")");
}
}
var label = "".concat(id, ": ").concat(description);
entityOptions.push([key, label]);
seen.add(key);
if (entityOptions.length > MaxSelectOptionsCount) {
return [['', 'Too many entities']];
}
}
if (entityOptions.length === 0)
entityOptions.push(['', 'No entities']);
return entityOptions;
}
exports.getModelEntityOptions = getModelEntityOptions;
function getChainOptions(structure, modelEntityId) {
var options = [];
var l = structure_1.StructureElement.Location.create(structure);
var seen = new Set();
var _a = splitModelEntityId(modelEntityId), modelIdx = _a[0], entityId = _a[1];
for (var _i = 0, _b = structure.units; _i < _b.length; _i++) {
var unit = _b[_i];
structure_1.StructureElement.Location.set(l, structure, unit, unit.elements[0]);
if (structure.getModelIndex(unit.model) !== modelIdx)
continue;
if (structure_1.StructureProperties.entity.id(l) !== entityId)
continue;
var id = unit.chainGroupId;
if (seen.has(id))
continue;
// TODO handle special case
// - more than one chain in a unit
var label = (0, label_1.elementLabel)(l, { granularity: 'chain', hidePrefix: true, htmlStyling: false });
options.push([id, label]);
seen.add(id);
if (options.length > MaxSelectOptionsCount) {
return [[-1, 'Too many chains']];
}
}
if (options.length === 0)
options.push([-1, 'No chains']);
return options;
}
exports.getChainOptions = getChainOptions;
function getEntityChainPairs(state, options) {
var structureOptions = getStructureOptions(state);
var structureRef = structureOptions.options[0][0];
var structure = getStructure(state, structureRef);
var entityOptions = getModelEntityOptions(structure, options);
var chainOptions = entityOptions.map(function (_a) {
var modelEntityId = _a[0], _eLabel = _a[1];
return ({
entityId: modelEntityId,
chains: getChainOptions(structure, modelEntityId),
});
});
var chainIdOptions = chainOptions.flatMap(function (c) {
return c.chains.map(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$1$2");
});
});
var duplicates = chainIdOptions.filter(function (item, index) { return chainIdOptions.indexOf(item) !== index; });
if (duplicates.length > 0) {
var unique = Array.from(new Set(duplicates));
var duplicationsPerEntityPerDuplicatedChain = unique.map(function (duplicatedChainId) {
var coincidencesPerEntity = chainOptions.flatMap(function (c) {
var coincidencesChain = c.chains
.filter(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$1$2") ===
duplicatedChainId;
})
.map(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$1 [auth $2]");
});
if (coincidencesChain.length > 0)
return {
entityId: c.entityId,
chainsDuplicated: coincidencesChain.join(", "),
};
else
return [];
});
return { duplicatedChainId: duplicatedChainId, coincidencesPerEntity: coincidencesPerEntity };
});
// Maintenance Note: Should make tests for all PDBs for this
throw new Error(duplicationsPerEntityPerDuplicatedChain
.map(function (i) {
var coincidencesStr = i.coincidencesPerEntity
.map(function (opt) {
return "EntityId: ".concat(opt.entityId, ", Chains: ").concat(opt.chainsDuplicated);
})
.join("; ");
return "Duplicated chains for: ".concat(i.duplicatedChainId, " -> ").concat(coincidencesStr);
})
.join("\n"));
}
return { entityOptions: entityOptions, chainOptions: chainOptions };
}
exports.getEntityChainPairs = getEntityChainPairs;
// const chainIdRegex = /(?:(\w+) ){0,1}(?:\[auth (\w+)\]){0,1}/; if both ids are present this
// regex will match (which is not intended for later substitutions).
// With next regex, if some id is not present will not match, but intended for later substitutions;
// because if there is no id is because they are the same or there is no struct asym id for formats
// like "pdb" or "ent"
var chainIdRegex = /^(?:(\w+)\s{0,1}){0,1}(?:\[auth (\w+)\])$/; // $1 structAsymId, $2 chainId (auth)
function getEntityIdFromChainId(chainOptions, chainId) {
var _a;
var entityId = (_a = chainOptions.find(function (c) {
return c.chains.find(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$2") === chainId;
});
})) === null || _a === void 0 ? void 0 : _a.entityId;
if (!entityId)
throw new Error("Entity not found for chain ".concat(chainId));
return entityId;
}
exports.getEntityIdFromChainId = getEntityIdFromChainId;
function getChainNumberedIdFromChainId(chainOptions, chainId) {
var chainNumberedId = chainOptions.reduce(function (numberedId, opt) {
var _a;
if (typeof numberedId === "number")
return numberedId;
var chain = opt.chains.find(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$2") === chainId;
});
return chain && ((_a = chain[0]) !== null && _a !== void 0 ? _a : undefined);
}, undefined);
if (chainNumberedId === undefined)
throw new Error("Chain not found for chain ".concat(chainId));
return chainNumberedId;
}
exports.getChainNumberedIdFromChainId = getChainNumberedIdFromChainId;
function getChainIdFromNumberedId(chainOptions, chainNumberedId) {
var chainId = chainOptions.reduce(function (chainId, opt) {
var _a, _b;
if (chainId)
return chainId;
var chain = opt.chains.find(function (_a) {
var id = _a[0];
return String(id) === chainNumberedId;
});
return chain && ((_b = (_a = chain[1]) === null || _a === void 0 ? void 0 : _a.replace(chainIdRegex, "$2")) !== null && _b !== void 0 ? _b : undefined);
}, undefined);
if (chainId === undefined)
throw new Error("Chain not found for chain ".concat(chainNumberedId));
return chainId;
}
exports.getChainIdFromNumberedId = getChainIdFromNumberedId;
function getStructAsymIdFromChainId(chainOptions, chainId) {
var structAsymId = chainOptions.reduce(function (structAsymId, opt) {
var _a, _b;
if (structAsymId)
return structAsymId;
var chain = opt.chains.find(function (_a) {
var id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$2") === chainId;
});
return (chain && ((_b = (_a = chain[1]) === null || _a === void 0 ? void 0 : _a.replace(chainIdRegex, "$1")) !== null && _b !== void 0 ? _b : undefined));
}, undefined);
if (structAsymId === undefined)
throw new Error("Chain not found for chain ".concat(chainId));
return structAsymId;
}
exports.getStructAsymIdFromChainId = getStructAsymIdFromChainId;
function getEntityIdFromStructAsymId(chainOptions, structAsymId) {
var _a;
var entityId = (_a = chainOptions.find(function (c) {
return c.chains.find(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$1") === structAsymId;
});
})) === null || _a === void 0 ? void 0 : _a.entityId;
if (!entityId)
throw new Error("Entity not found for chain STRUCT_ASYM_ID ".concat(structAsymId));
return entityId;
}
exports.getEntityIdFromStructAsymId = getEntityIdFromStructAsymId;
function getChainNumberedIdFromStructAsymId(chainOptions, structAsymId) {
var chainNumberedId = chainOptions.reduce(function (numberedId, opt) {
var _a;
if (typeof numberedId === "number")
return numberedId;
var chain = opt.chains.find(function (_a) {
var _id = _a[0], label = _a[1];
return label.replace(chainIdRegex, "$1") === structAsymId;
});
return chain && ((_a = chain[0]) !== null && _a !== void 0 ? _a : undefined);
}, undefined);
if (chainNumberedId === undefined)
throw new Error("Chain not found for chain STRUCT_ASYM_ID ".concat(structAsymId));
return chainNumberedId;
}
exports.getChainNumberedIdFromStructAsymId = getChainNumberedIdFromStructAsymId;
function getOperatorOptions(structure, modelEntityId, chainGroupId) {
var options = [];
var l = structure_1.StructureElement.Location.create(structure);
var seen = new Set();
var _a = splitModelEntityId(modelEntityId), modelIdx = _a[0], entityId = _a[1];
for (var _i = 0, _b = structure.units; _i < _b.length; _i++) {
var unit = _b[_i];
structure_1.StructureElement.Location.set(l, structure, unit, unit.elements[0]);
if (structure.getModelIndex(unit.model) !== modelIdx)
continue;
if (structure_1.StructureProperties.entity.id(l) !== entityId)
continue;
if (unit.chainGroupId !== chainGroupId)
continue;
var id = opKey(l);
if (seen.has(id))
continue;
var label = unit.conformation.operator.name;
options.push([id, label]);
seen.add(id);
if (options.length > MaxSelectOptionsCount) {
return [['', 'Too many operators']];
}
}
if (options.length === 0)
options.push(['', 'No operators']);
return options;
}
exports.getOperatorOptions = getOperatorOptions;
function getStructureOptions(state) {
var _a;
var options = [];
var all = [];
var structures = state.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Structure));
for (var _i = 0, structures_1 = structures; _i < structures_1.length; _i++) {
var s = structures_1[_i];
if (!((_a = s.obj) === null || _a === void 0 ? void 0 : _a.data))
continue;
all.push(s.obj.data);
options.push([s.transform.ref, s.obj.data.label]);
}
if (options.length === 0)
options.push(['', 'No structure']);
return { options: options, all: all };
}
exports.getStructureOptions = getStructureOptions;
function getStructure(state, ref) {
var cell = state.select(ref)[0];
if (!ref || !cell || !cell.obj)
return structure_1.Structure.Empty;
return cell.obj.data;
}
exports.getStructure = getStructure;
var SequenceViewModeParam = param_definition_1.ParamDefinition.Select("single", [
["single", "Chain"],
["polymers", "Polymers"],
["all", "Everything"],
]);
var SequenceView = /** @class */ (function (_super) {
tslib_1.__extends(SequenceView, _super);
function SequenceView() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
structureOptions: { options: [], all: [] },
structure: structure_1.Structure.Empty,
structureRef: "",
modelEntityId: "",
chainGroupId: -1,
operatorKey: "",
mode: "single",
};
_this.setParamProps = function (p) {
var state = tslib_1.__assign({}, _this.state);
switch (p.name) {
case 'mode':
state.mode = p.value;
if (_this.state.mode === state.mode)
return;
if (state.mode === 'all' || state.mode === 'polymers') {
break;
}
case 'structure':
if (p.name === 'structure')
state.structureRef = p.value;
state.structure = _this.getStructure(state.structureRef);
state.modelEntityId = getModelEntityOptions(state.structure, { onlyPolymers: false })[0][0];
state.chainGroupId = getChainOptions(state.structure, state.modelEntityId)[0][0];
state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.chainGroupId)[0][0];
break;
case 'entity':
if (state.modelEntityId === p.value)
return;
state.modelEntityId = p.value;
state.chainGroupId = getChainOptions(state.structure, state.modelEntityId)[0][0];
_this.updateChainInViewer(state.chainGroupId, state);
state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.chainGroupId)[0][0];
break;
case 'chain':
if (state.chainGroupId === p.value)
return;
state.chainGroupId = p.value;
_this.updateChainInViewer(p.value, state);
state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.chainGroupId)[0][0];
break;
case 'operator':
state.operatorKey = p.value;
break;
}
_this.setState(state);
};
return _this;
}
SequenceView.prototype.componentDidMount = function () {
var _this = this;
this.updateViewerChain = this.props.onChainUpdate;
this.isLigandView = this.props.isLigandView;
this.props.plugin.events.chainUpdate.subscribe({
next: function (chainId) {
console.debug("molstar.events.chainUpdate", chainId);
if (!_this.entityChainPairs)
return;
var firstItem = _this.entityChainPairs.chainOptions[0];
if (_this.entityChainPairs.chainOptions.length === 1 &&
firstItem &&
firstItem.entityId === "")
return;
var entityId = getEntityIdFromChainId(_this.entityChainPairs.chainOptions, chainId);
var chainNumber = getChainNumberedIdFromChainId(_this.entityChainPairs.chainOptions, chainId);
console.debug("Updating sequence selected options", entityId, chainNumber);
_this.setParamProps({
name: "entity",
param: _this.params.entity,
value: entityId
});
_this.setParamProps({
name: "chain",
param: _this.params.chain,
value: chainNumber
});
},
error: function (err) {
console.error(err);
},
});
this.props.plugin.events.ligandUpdate.subscribe({
next: function (options) {
console.debug("molstar.events.ligandUpdate", options);
if (!_this.entityChainPairs)
return;
if (!_this.notPolymerEntityChainPairs)
return;
var ligand = getLigand(options, _this.state.structure);
if (!ligand)
return;
if (!ligand.structAsymId)
return;
var entityId = getEntityIdFromStructAsymId(_this.notPolymerEntityChainPairs.chainOptions, ligand.structAsymId);
var chainNumber = getChainNumberedIdFromStructAsymId(_this.notPolymerEntityChainPairs.chainOptions, ligand.structAsymId);
console.debug("Updating sequence selected options", entityId, chainNumber);
_this.setParamProps({
name: "entity",
param: _this.params.entity,
value: entityId
});
_this.setParamProps({
name: "chain",
param: _this.params.chain,
value: chainNumber
});
_this.props.plugin.canvas.hideToasts();
},
error: function (err) {
console.error(err);
},
});
this.props.plugin.events.dependencyChanged.onChainUpdate.subscribe({
next: function (callback) {
console.debug("molstar.events.dependencyChanged.onChainUpdate");
_this.updateViewerChain = callback;
},
error: function (err) {
console.error(err);
},
});
this.props.plugin.events.dependencyChanged.isLigandView.subscribe({
next: function (callback) {
console.debug("molstar.events.dependencyChanged.isLigandView");
_this.isLigandView = callback;
},
error: function (err) {
console.error(err);
},
});
if (this.plugin.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Structure)).length > 0)
this.setState(this.getInitialState());
this.subscribe(this.plugin.state.events.object.updated, function (_a) {
var ref = _a.ref, obj = _a.obj;
if (ref === _this.state.structureRef &&
obj &&
obj.type === objects_1.PluginStateObject.Molecule.Structure.type &&
obj.data !== _this.state.structure) {
_this.sync();
}
});
this.subscribe(this.plugin.state.events.object.created, function (_a) {
var obj = _a.obj;
if (obj && obj.type === objects_1.PluginStateObject.Molecule.Structure.type) {
_this.sync();
}
});
this.subscribe(this.plugin.state.events.object.removed, function (_a) {
var obj = _a.obj;
if (obj && obj.type === objects_1.PluginStateObject.Molecule.Structure.type && obj.data === _this.state.structure) {
_this.sync();
}
});
};
SequenceView.prototype.sync = function () {
var structureOptions = getStructureOptions(this.plugin.state.data);
if ((0, array_1.arrayEqual)(structureOptions.all, this.state.structureOptions.all))
return;
this.setState(this.getInitialState());
this.props.sequenceCompleted();
};
SequenceView.prototype.getStructure = function (ref) {
var state = this.plugin.state.data;
return getStructure(state, ref);
};
SequenceView.prototype.getSequenceWrapper = function (params) {
return {
wrapper: getSequenceWrapper(this.state, this.plugin.managers.structure.selection),
label: "".concat(param_definition_1.ParamDefinition.optionLabel(params.chain, this.state.chainGroupId), " | ").concat(param_definition_1.ParamDefinition.optionLabel(params.entity, this.state.modelEntityId)),
};
};
SequenceView.prototype.getSequenceWrappers = function (params) {
if (this.state.mode === 'single')
return [this.getSequenceWrapper(params)];
var structure = this.getStructure(this.state.structureRef);
var wrappers = [];
for (var _i = 0, _a = getModelEntityOptions(structure, {
onlyPolymers: this.state.mode === "polymers",
}); _i < _a.length; _i++) {
var _b = _a[_i], modelEntityId = _b[0], eLabel = _b[1];
for (var _c = 0, _d = getChainOptions(structure, modelEntityId); _c < _d.length; _c++) {
var _e = _d[_c], chainGroupId = _e[0], cLabel = _e[1];
for (var _f = 0, _g = getOperatorOptions(structure, modelEntityId, chainGroupId); _f < _g.length; _f++) {
var operatorKey = _g[_f][0];
wrappers.push({
wrapper: getSequenceWrapper({
structure: structure,
modelEntityId: modelEntityId,
chainGroupId: chainGroupId,
operatorKey: operatorKey,
}, this.plugin.managers.structure.selection),
label: "".concat(cLabel, " | ").concat(eLabel),
});
if (wrappers.length > MaxSequenceWrappersCount)
return [];
}
}
}
return wrappers;
};
SequenceView.prototype.getInitialState = function () {
var _a;
var structureOptions = getStructureOptions(this.plugin.state.data);
var structureRef = structureOptions.options[0][0];
var structure = this.getStructure(structureRef);
var modelEntityId = getModelEntityOptions(structure, { onlyPolymers: false })[0][0];
var chainGroupId = getChainOptions(structure, modelEntityId)[0][0];
var operatorKey = getOperatorOptions(structure, modelEntityId, chainGroupId)[0][0];
try {
this.entityChainPairs = getEntityChainPairs(this.plugin.state.data, { onlyPolymers: true });
this.notPolymerEntityChainPairs = getEntityChainPairs(this.plugin.state.data, { onlyPolymers: false });
if (this.entityChainPairs) {
try {
var chainId = getChainIdFromNumberedId(this.entityChainPairs.chainOptions, String(chainGroupId));
this.lastValidChainId = chainId;
}
catch (error) {
console.error("Unable to set the first state of lastValidChain", error);
}
}
}
catch (error) {
console.error(error);
}
if (this.state.structure && this.state.structure === structure) {
modelEntityId = this.state.modelEntityId;
chainGroupId = this.state.chainGroupId;
operatorKey = this.state.operatorKey;
}
return {
structureOptions: structureOptions,
structure: structure,
structureRef: structureRef,
modelEntityId: modelEntityId,
chainGroupId: chainGroupId,
operatorKey: operatorKey,
mode: (_a = this.props.defaultMode) !== null && _a !== void 0 ? _a : "single",
};
};
Object.defineProperty(SequenceView.prototype, "params", {
get: function () {
var _a = this.state, structureOptions = _a.structureOptions, structure = _a.structure, modelEntityId = _a.modelEntityId, chainGroupId = _a.chainGroupId;
var entityOptions = getModelEntityOptions(structure, { onlyPolymers: false });
var chainOptions = getChainOptions(structure, modelEntityId);
var operatorOptions = getOperatorOptions(structure, modelEntityId, chainGroupId);
return {
structure: param_definition_1.ParamDefinition.Select(structureOptions.options[0][0], structureOptions.options, { shortLabel: true }),
entity: param_definition_1.ParamDefinition.Select(entityOptions[0][0], entityOptions, { shortLabel: true }),
chain: param_definition_1.ParamDefinition.Select(chainOptions[0][0], chainOptions, { shortLabel: true, twoColumns: true, label: 'Chain' }),
operator: param_definition_1.ParamDefinition.Select(operatorOptions[0][0], operatorOptions, { shortLabel: true, twoColumns: true }),
mode: SequenceViewModeParam
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(SequenceView.prototype, "values", {
get: function () {
return {
structure: this.state.structureRef,
entity: this.state.modelEntityId,
chain: this.state.chainGroupId,
operator: this.state.operatorKey,
mode: this.state.mode
};
},
enumerable: false,
configurable: true
});
SequenceView.prototype.updateChainInViewer = function (value, state) {
if (this.entityChainPairs && !this.isLigandView()) {
try {
var chainId = getChainIdFromNumberedId(this.entityChainPairs.chainOptions, String(value));
this.lastValidChainId = chainId;
this.updateViewerChain(chainId);
this.props.plugin.canvas.hideToasts();
}
catch (error) {
this.handleInvalidChain(error, this.entityChainPairs.chainOptions, state);
}
}
};
// Can happen only if user is changing the entity through molstar sequence because he wants to look for surrounding residues
SequenceView.prototype.handleInvalidChain = function (error, chainOptions, state) {
console.error("Chain to change is not in one of the polymers.", error);
if (this.lastValidChainId) {
try {
var previousStructAsymId = getStructAsymIdFromChainId(chainOptions, this.lastValidChainId);
var key = "".concat(state.structureRef, "-").concat(state.modelEntityId, "-").concat(state.chainGroupId);
this.props.plugin.canvas.showToast({
title: "Chain not in entry",
message: "Still showing previous chain: ".concat(previousStructAsymId, " [auth ").concat(this.lastValidChainId, "]"),
key: key,
});
}
catch (error) {
console.error("Previous valid chain is not in one of the polymers. This should not happen.", error);
}
}
};
SequenceView.prototype.render = function () {
if (this.getStructure(this.state.structureRef) === structure_1.Structure.Empty) {
return (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: 'msp-sequence' }, { children: (0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ className: 'msp-sequence-select' }, { children: [(0, jsx_runtime_1.jsx)(icons_1.Icon, { svg: icons_1.HelpOutlineSvg, style: { cursor: 'help', position: 'absolute', right: 0, top: 0 }, title: 'Shows a sequence of one or more chains. Use the controls to alter selection.' }), (0, jsx_runtime_1.jsx)("span", { children: "Sequence" }), (0, jsx_runtime_1.jsx)("span", tslib_1.__assign({ style: { fontWeight: 'normal' } }, { children: "No structure available" }))] })) }));
}
var params = this.params;
var values = this.values;
var sequenceWrappers = this.getSequenceWrappers(params);
return ((0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ className: "msp-sequence" }, { children: [(0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ className: "msp-sequence-select" }, { children: [(0, jsx_runtime_1.jsx)(icons_1.Icon, { svg: icons_1.HelpOutlineSvg, style: {
cursor: "help",
position: "absolute",
right: 0,
top: 0,
}, title: "This shows a single sequence. Use the controls to show a different sequence." }), (0, jsx_runtime_1.jsx)("span", { children: "Sequence of" }), (0, jsx_runtime_1.jsx)(parameters_1.PureSelectControl, { title: "[Structure] ".concat(param_definition_1.ParamDefinition.optionLabel(params.structure, values.structure)), param: params.structure, name: "structure", value: values.structure, onChange: this.setParamProps }), (0, jsx_runtime_1.jsx)(parameters_1.PureSelectControl, { title: "[Mode]", param: SequenceViewModeParam, name: "mode", value: values.mode, onChange: this.setParamProps }), values.mode === "single" && ((0, jsx_runtime_1.jsx)(parameters_1.PureSelectControl, { title: "[Entity] ".concat(param_definition_1.ParamDefinition.optionLabel(params.entity, values.entity)), param: params.entity, name: "entity", value: values.entity, onChange: this.setParamProps })), values.mode === "single" && ((0, jsx_runtime_1.jsx)(parameters_1.PureSelectControl, { title: "[Chain] ".concat(param_definition_1.ParamDefinition.optionLabel(params.chain, values.chain)), param: params.chain, name: "chain", value: values.chain, onChange: this.setParamProps })), params.operator.options.length > 1 && ((0, jsx_runtime_1.jsx)(parameters_1.PureSelectControl, { title: "[Instance] ".concat(param_definition_1.ParamDefinition.optionLabel(params.operator, values.operator)), param: params.operator, name: "operator", value: values.operator, onChange: this.setParamProps }))] })), (0, jsx_runtime_1.jsx)(NonEmptySequenceWrapper, { children: sequenceWrappers.map(function (s, i) {
var elem = typeof s.wrapper === "string" ? ((0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: "msp-sequence-wrapper" }, { children: s.wrapper }), i)) : ((0, jsx_runtime_1.jsx)(sequence_1.Sequence, { sequenceWrapper: s.wrapper }, i));
if (values.mode === "single")
return elem;
return ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: "msp-sequence-chain-label" }, { children: s.label })), elem] }, i));
}) })] })));
};
return SequenceView;
}(base_1.PluginUIComponent));
exports.SequenceView = SequenceView;
function NonEmptySequenceWrapper(_a) {
var children = _a.children;
return (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: 'msp-sequence-wrapper-non-empty' }, { children: children }));
}
//# sourceMappingURL=sequence_2.js.map