drugflow-molstar
Version:
Molstar implementation for DrugFlow
138 lines (137 loc) • 6.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.lociDetails = lociDetails;
exports.bondLabel = bondLabel;
exports._bundleLabel = _bundleLabel;
var tslib_1 = require("tslib");
var structure_1 = require("Molstar/mol-model/structure");
var int_1 = require("Molstar/mol-data/int");
var sifts_mapping_1 = require("Molstar/mol-model-props/sequence/sifts-mapping");
function lociDetails(loci) {
switch (loci.kind) {
case 'structure-loci':
return { models: loci.structure.models.map(function (m) { return m.entry; }).filter(function (l) { return !!l; }) };
case 'element-loci':
return structureElementStatsDetail(structure_1.StructureElement.Stats.ofLoci(loci));
case 'bond-loci':
var bond = loci.bonds[0];
return bond ? bondLabel(bond, 'element') : undefined;
default:
return void 0;
}
}
function structureElementStatsDetail(stats) {
var chainCount = stats.chainCount, residueCount = stats.residueCount, elementCount = stats.elementCount;
if (elementCount === 1 && residueCount === 0 && chainCount === 0) {
return getElementDetails(stats.firstElementLoc, 'element');
}
else if (elementCount === 0 && residueCount === 1 && chainCount === 0) {
return getElementDetails(stats.firstResidueLoc, 'residue');
}
else {
return void 0;
}
}
function getElementDetails(location, granularity) {
if (granularity === void 0) { granularity = 'element'; }
var basicDetails = {};
var entry = location.unit.model.entry;
if (entry.length > 30)
entry = entry.substr(0, 27) + '\u2026'; // ellipsis
basicDetails['entry_id'] = entry; // entry
if (granularity !== 'structure') {
basicDetails['model'] = location.unit.model.modelNum; // model
basicDetails['instance'] = location.unit.conformation.operator.name; // instance
}
var elementDetails;
if (structure_1.Unit.isAtomic(location.unit)) {
elementDetails = atomicElementDetails(location, granularity);
}
else if (structure_1.Unit.isCoarse(location.unit)) {
elementDetails = coarseElementDetails(location, granularity);
}
return tslib_1.__assign(tslib_1.__assign({}, basicDetails), elementDetails);
}
function atomicElementDetails(location, granularity) {
var elementDetails = {
entity_id: structure_1.StructureProperties.chain.label_entity_id(location),
label_asym_id: structure_1.StructureProperties.chain.label_asym_id(location),
auth_asym_id: structure_1.StructureProperties.chain.auth_asym_id(location),
unp_accession: undefined,
unp_seq_id: undefined,
seq_id: structure_1.StructureProperties.residue.label_seq_id(location),
auth_seq_id: structure_1.StructureProperties.residue.auth_seq_id(location),
ins_code: structure_1.StructureProperties.residue.pdbx_PDB_ins_code(location),
comp_id: structure_1.StructureProperties.atom.label_comp_id(location),
atom_id: [structure_1.StructureProperties.atom.label_atom_id(location)],
alt_id: structure_1.StructureProperties.atom.label_alt_id(location)
};
var unpLabel = sifts_mapping_1.SIFTSMapping.getLabel(location);
if (unpLabel) {
var unpLabelDetails = unpLabel.split(' ');
if (unpLabelDetails[0] === 'UNP') {
elementDetails.unp_accession = unpLabelDetails[1];
elementDetails.unp_seq_id = +unpLabelDetails[2];
}
}
var microHetCompIds = structure_1.StructureProperties.residue.microheterogeneityCompIds(location);
elementDetails['micro_het_comp_ids'] = granularity === 'residue' && microHetCompIds.length > 1 ?
microHetCompIds : [elementDetails['comp_id']];
return elementDetails;
}
function coarseElementDetails(location, granularity) {
var elementDetails = {
asym_id: structure_1.StructureProperties.coarse.asym_id(location),
seq_id_begin: structure_1.StructureProperties.coarse.seq_id_begin(location),
seq_id_end: structure_1.StructureProperties.coarse.seq_id_end(location)
};
if (granularity === 'residue') {
if (elementDetails.seq_id_begin === elementDetails.seq_id_end) {
var entityIndex = structure_1.StructureProperties.coarse.entityKey(location);
var seq = location.unit.model.sequence.byEntityKey[entityIndex];
elementDetails['comp_id'] = seq.sequence.compId.value(elementDetails.seq_id_begin - 1); // 1-indexed
}
}
return elementDetails;
}
function bondLabel(bond, granularity) {
return _bundleLabel({ loci: [
structure_1.StructureElement.Loci(bond.aStructure, [{ unit: bond.aUnit, indices: int_1.OrderedSet.ofSingleton(bond.aIndex) }]),
structure_1.StructureElement.Loci(bond.bStructure, [{ unit: bond.bUnit, indices: int_1.OrderedSet.ofSingleton(bond.bIndex) }])
] }, granularity);
}
function _bundleLabel(bundle, granularity) {
var e_1, _a;
var isSingleElements = true;
try {
for (var _b = tslib_1.__values(bundle.loci), _c = _b.next(); !_c.done; _c = _b.next()) {
var l = _c.value;
if (!structure_1.StructureElement.Loci.is(l) || structure_1.StructureElement.Loci.size(l) !== 1) {
isSingleElements = false;
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
if (isSingleElements) {
var locations = bundle.loci.map(function (l) {
var _a = l.elements[0], unit = _a.unit, indices = _a.indices;
return structure_1.StructureElement.Location.create(l.structure, unit, unit.elements[int_1.OrderedSet.start(indices)]);
});
var elementDetailsArr = locations.map(function (l) { return getElementDetails(l, granularity); });
var atomIds = [elementDetailsArr[0].atom_id[0], elementDetailsArr[1].atom_id[0]];
var elementDetails = elementDetailsArr[0];
elementDetails['atom_id'] = atomIds;
return elementDetails;
}
else {
var elementDetails = bundle.loci.map(function (l) { return lociDetails(l); });
return elementDetails;
}
}