UNPKG

pdbe-molstar

Version:
128 lines (127 loc) 5.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lociDetails = lociDetails; exports.bondLabel = bondLabel; exports._bundleLabel = _bundleLabel; const int_1 = require("molstar/lib/mol-data/int"); const sifts_mapping_1 = require("molstar/lib/mol-model-props/sequence/sifts-mapping"); const structure_1 = require("molstar/lib/mol-model/structure"); function lociDetails(loci) { switch (loci.kind) { case 'structure-loci': return { models: loci.structure.models.map(m => m.entry).filter(l => !!l) }; case 'element-loci': return structureElementStatsDetail(structure_1.StructureElement.Stats.ofLoci(loci)); case 'bond-loci': { const bond = loci.bonds[0]; return bond ? bondLabel(bond, 'element') : {}; } default: return undefined; } } function structureElementStatsDetail(stats) { const { chainCount, residueCount, elementCount } = stats; 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 undefined; } } function getElementDetails(location, granularity = 'element') { const basicDetails = {}; let 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 } let 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 Object.assign(Object.assign({}, basicDetails), elementDetails); } function atomicElementDetails(location, granularity) { const 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), }; const unpLabel = sifts_mapping_1.SIFTSMapping.getLabel(location); if (unpLabel) { const unpLabelDetails = unpLabel.split(' '); if (unpLabelDetails[0] === 'UNP') { elementDetails.unp_accession = unpLabelDetails[1]; elementDetails.unp_seq_id = +unpLabelDetails[2]; } } const 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) { const 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) { const entityIndex = structure_1.StructureProperties.coarse.entityKey(location); const 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) { let isSingleElements = true; for (const l of bundle.loci) { if (!structure_1.StructureElement.Loci.is(l) || structure_1.StructureElement.Loci.size(l) !== 1) { isSingleElements = false; break; } } if (isSingleElements) { const locations = bundle.loci.map(l => { const { unit, indices } = l.elements[0]; return structure_1.StructureElement.Location.create(l.structure, unit, unit.elements[int_1.OrderedSet.start(indices)]); }); const elementDetailsArr = locations.map(l => getElementDetails(l, granularity)); const atomIds = [elementDetailsArr[0].atom_id[0], elementDetailsArr[1].atom_id[0]]; const elementDetails = elementDetailsArr[0]; elementDetails['atom_id'] = atomIds; return elementDetails; } else { const elementDetails = bundle.loci.map(l => lociDetails(l)); return elementDetails; } }