molstar
Version:
A comprehensive macromolecular library.
103 lines • 4.8 kB
JavaScript
/**
* 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 { Structure, StructureElement } from '../../mol-model/structure';
import { SequenceWrapper } from './wrapper';
import { OrderedSet, Segmentation, Interval, SortedArray } from '../../mol-data/int';
import { ColorNames } from '../../mol-util/color/names';
import { applyMarkerAction } from '../../mol-util/marker-action';
var HeteroSequenceWrapper = /** @class */ (function (_super) {
__extends(HeteroSequenceWrapper, _super);
function HeteroSequenceWrapper(data) {
var _this = this;
var sequence = [];
var sequenceIndices = new Map();
var residueIndices = new Map();
var seqToUnit = new Map();
for (var i = 0, il = data.units.length; i < il; ++i) {
var unit = data.units[i];
var _a = unit.model.atomicHierarchy, residueAtomSegments = _a.residueAtomSegments, atoms = _a.atoms;
var residueIt = Segmentation.transientSegments(residueAtomSegments, unit.elements);
while (residueIt.hasNext) {
var index = residueIt.move().index;
sequenceIndices.set(index, sequence.length);
residueIndices.set(sequence.length, index);
seqToUnit.set(sequence.length, unit);
sequence.push(atoms.label_comp_id.value(residueAtomSegments.offsets[index]));
}
}
var length = sequence.length;
var markerArray = new Uint8Array(length);
_this = _super.call(this, data, markerArray, length) || this;
_this.unitMap = new Map();
for (var _i = 0, _b = data.units; _i < _b.length; _i++) {
var unit = _b[_i];
_this.unitMap.set(unit.id, unit);
}
_this.sequence = sequence;
_this.sequenceIndices = sequenceIndices;
_this.residueIndices = residueIndices;
_this.seqToUnit = seqToUnit;
return _this;
}
HeteroSequenceWrapper.prototype.residueLabel = function (seqIdx) {
return this.sequence[seqIdx];
};
HeteroSequenceWrapper.prototype.residueColor = function (seqIdx) {
return ColorNames.black;
};
HeteroSequenceWrapper.prototype.residueClass = function (seqIdx) {
return 'msp-sequence-present';
};
HeteroSequenceWrapper.prototype.mark = function (loci, action) {
var _this = this;
var changed = false;
var structure = this.data.structure;
if (StructureElement.Loci.is(loci)) {
if (!Structure.areRootsEquivalent(loci.structure, structure))
return false;
loci = StructureElement.Loci.remap(loci, structure);
var _loop_1 = function (e) {
var unit = this_1.unitMap.get(e.unit.id);
if (unit) {
var residueIndex_1 = e.unit.model.atomicHierarchy.residueAtomSegments.index;
OrderedSet.forEach(e.indices, function (v) {
var seqIdx = _this.sequenceIndices.get(residueIndex_1[unit.elements[v]]);
if (seqIdx !== undefined && applyMarkerAction(_this.markerArray, Interval.ofSingleton(seqIdx), action))
changed = true;
});
}
};
var this_1 = this;
for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) {
var e = _a[_i];
_loop_1(e);
}
}
else if (Structure.isLoci(loci)) {
if (!Structure.areRootsEquivalent(loci.structure, structure))
return false;
if (applyMarkerAction(this.markerArray, Interval.ofBounds(0, this.length), action))
changed = true;
}
return changed;
};
HeteroSequenceWrapper.prototype.getLoci = function (seqIdx) {
var elements = [];
var rI = this.residueIndices.get(seqIdx);
if (rI !== undefined) {
var unit = this.seqToUnit.get(seqIdx);
var offsets = unit.model.atomicHierarchy.residueAtomSegments.offsets;
var start = SortedArray.findPredecessorIndex(unit.elements, offsets[rI]);
var end = SortedArray.findPredecessorIndex(unit.elements, offsets[rI + 1]);
elements.push({ unit: unit, indices: Interval.ofBounds(start, end) });
}
return StructureElement.Loci(this.data.structure, elements);
};
return HeteroSequenceWrapper;
}(SequenceWrapper));
export { HeteroSequenceWrapper };
//# sourceMappingURL=hetero.js.map