UNPKG

molstar

Version:

A comprehensive macromolecular library.

129 lines (128 loc) 6.37 kB
/** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __extends } from "tslib"; import { StructureSelection, StructureQuery, Structure, Queries, StructureProperties as SP, StructureElement, Unit } from '../../mol-model/structure'; import { SequenceWrapper } from './wrapper'; import { OrderedSet, Interval, SortedArray } from '../../mol-data/int'; import { ColorNames } from '../../mol-util/color/names'; import { applyMarkerAction, applyMarkerActionAtPosition } from '../../mol-util/marker-action'; var PolymerSequenceWrapper = /** @class */ (function (_super) { __extends(PolymerSequenceWrapper, _super); function PolymerSequenceWrapper(data) { var _this = this; var l = StructureElement.Location.create(data.structure, data.units[0], data.units[0].elements[0]); var entitySeq = data.units[0].model.sequence.byEntityKey[SP.entity.key(l)]; var length = entitySeq.sequence.length; var markerArray = new Uint8Array(length); _this = _super.call(this, data, markerArray, length) || this; _this.unitMap = new Map(); for (var _i = 0, _a = data.units; _i < _a.length; _i++) { var unit = _a[_i]; _this.unitMap.set(unit.id, unit); } _this.sequence = entitySeq.sequence; _this.missing = data.units[0].model.properties.missingResidues; _this.modelNum = data.units[0].model.modelNum; _this.asymId = Unit.isAtomic(data.units[0]) ? SP.chain.label_asym_id(l) : SP.coarse.asym_id(l); var missing = []; for (var i = 0; i < length; ++i) { if (_this.missing.has(_this.modelNum, _this.asymId, _this.seqId(i))) missing.push(i); } _this.observed = OrderedSet.subtract(Interval.ofBounds(0, length), SortedArray.ofSortedArray(missing)); return _this; } PolymerSequenceWrapper.prototype.seqId = function (seqIdx) { return this.sequence.seqId.value(seqIdx); }; PolymerSequenceWrapper.prototype.residueLabel = function (seqIdx) { return this.sequence.label.value(seqIdx) || this.sequence.code.value(seqIdx); }; PolymerSequenceWrapper.prototype.residueColor = function (seqIdx) { return this.missing.has(this.modelNum, this.asymId, this.seqId(seqIdx)) ? ColorNames.grey : ColorNames.black; }; PolymerSequenceWrapper.prototype.residueClass = function (seqIdx) { return this.missing.has(this.modelNum, this.asymId, this.seqId(seqIdx)) ? 'msp-sequence-missing' : 'msp-sequence-present'; }; PolymerSequenceWrapper.prototype.mark = function (loci, action) { var _this = this; var changed = false; var structure = this.data.structure; var index = function (seqId) { return _this.sequence.index(seqId); }; if (StructureElement.Loci.is(loci)) { if (!Structure.areRootsEquivalent(loci.structure, structure)) return false; loci = StructureElement.Loci.remap(loci, structure); for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) { var e = _a[_i]; if (!this.unitMap.has(e.unit.id)) continue; if (Unit.isAtomic(e.unit)) { changed = applyMarkerAtomic(e, action, this.markerArray, index) || changed; } else { changed = applyMarkerCoarse(e, action, this.markerArray, index) || changed; } } } else if (Structure.isLoci(loci)) { if (!Structure.areRootsEquivalent(loci.structure, structure)) return false; if (applyMarkerAction(this.markerArray, this.observed, action)) changed = true; } return changed; }; PolymerSequenceWrapper.prototype.getLoci = function (seqIdx) { var query = createResidueQuery(this.data.units[0].chainGroupId, this.data.units[0].conformation.operator.name, this.seqId(seqIdx)); return StructureSelection.toLociWithSourceUnits(StructureQuery.run(query, this.data.structure)); }; return PolymerSequenceWrapper; }(SequenceWrapper)); export { PolymerSequenceWrapper }; function createResidueQuery(chainGroupId, operatorName, label_seq_id) { return Queries.generators.atoms({ unitTest: function (ctx) { return (SP.unit.chainGroupId(ctx.element) === chainGroupId && SP.unit.operator_name(ctx.element) === operatorName); }, residueTest: function (ctx) { if (ctx.element.unit.kind === 0 /* Unit.Kind.Atomic */) { return SP.residue.label_seq_id(ctx.element) === label_seq_id; } else { return (SP.coarse.seq_id_begin(ctx.element) <= label_seq_id && SP.coarse.seq_id_end(ctx.element) >= label_seq_id); } } }); } function applyMarkerAtomic(e, action, markerArray, index) { var _a = e.unit, model = _a.model, elements = _a.elements; var residueIndex = model.atomicHierarchy.residueAtomSegments.index; var label_seq_id = model.atomicHierarchy.residues.label_seq_id; OrderedSet.forEachSegment(e.indices, function (i) { return residueIndex[elements[i]]; }, function (rI) { var seqId = label_seq_id.value(rI); applyMarkerActionAtPosition(markerArray, index(seqId), action); }); return true; } function applyMarkerCoarse(e, action, markerArray, index) { var _a = e.unit, model = _a.model, elements = _a.elements; var begin = Unit.isSpheres(e.unit) ? model.coarseHierarchy.spheres.seq_id_begin : model.coarseHierarchy.gaussians.seq_id_begin; var end = Unit.isSpheres(e.unit) ? model.coarseHierarchy.spheres.seq_id_end : model.coarseHierarchy.gaussians.seq_id_end; OrderedSet.forEach(e.indices, function (i) { var eI = elements[i]; for (var s = index(begin.value(eI)), e_1 = index(end.value(eI)); s <= e_1; s++) { applyMarkerActionAtPosition(markerArray, s, action); } }); return true; }