UNPKG

molstar

Version:

A comprehensive macromolecular library.

175 lines (174 loc) 8.82 kB
"use strict"; /** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getEmdbIds = exports.getContourLevelPdbe = exports.getContourLevelEmdb = exports.getContourLevel = exports.getIds = exports.getXrayIds = exports.getEmIds = exports.getStreamingMethod = void 0; var tslib_1 = require("tslib"); var structure_1 = require("../../../../mol-model/structure"); var mmcif_1 = require("../../../../mol-model-formats/structure/mmcif"); var config_1 = require("../../../config"); function getStreamingMethod(s, defaultKind) { if (defaultKind === void 0) { defaultKind = 'x-ray'; } if (!s) return defaultKind; var model = s.models[0]; if (!mmcif_1.MmcifFormat.is(model.sourceData)) return defaultKind; // Prefer EMDB entries over structure-factors (SF) e.g. for 'ELECTRON CRYSTALLOGRAPHY' entries // like 6AXZ or 6KJ3 for which EMDB entries are available but map calculation from SF is hard. if (structure_1.Model.hasEmMap(model)) return 'em'; if (structure_1.Model.hasXrayMap(model)) return 'x-ray'; // Fallbacks based on experimental method if (structure_1.Model.isFromEm(model)) return 'em'; if (structure_1.Model.isFromXray(model)) return 'x-ray'; return defaultKind; } exports.getStreamingMethod = getStreamingMethod; /** Returns EMD ID when available, otherwise falls back to PDB ID */ function getEmIds(model) { var ids = []; if (!mmcif_1.MmcifFormat.is(model.sourceData)) return [model.entryId]; var _a = model.sourceData.data.db.pdbx_database_related, db_id = _a.db_id, db_name = _a.db_name, content_type = _a.content_type; if (!db_name.isDefined) return [model.entryId]; for (var i = 0, il = db_name.rowCount; i < il; ++i) { if (db_name.value(i).toUpperCase() === 'EMDB' && content_type.value(i) === 'associated EM volume') { ids.push(db_id.value(i)); } } return ids; } exports.getEmIds = getEmIds; function getXrayIds(model) { return [model.entryId]; } exports.getXrayIds = getXrayIds; function getIds(method, s) { if (!s || !s.models.length) return []; var model = s.models[0]; switch (method) { case 'em': return getEmIds(model); case 'x-ray': return getXrayIds(model); } } exports.getIds = getIds; function getContourLevel(provider, plugin, taskCtx, emdbId) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (provider) { case 'emdb': return [2 /*return*/, getContourLevelEmdb(plugin, taskCtx, emdbId)]; case 'pdbe': return [2 /*return*/, getContourLevelPdbe(plugin, taskCtx, emdbId)]; } return [2 /*return*/]; }); }); } exports.getContourLevel = getContourLevel; function getContourLevelEmdb(plugin, taskCtx, emdbId) { return tslib_1.__awaiter(this, void 0, void 0, function () { var emdbHeaderServer, header, map, contours, primaryContour, i, contourLevel; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: emdbHeaderServer = plugin.config.get(config_1.PluginConfig.VolumeStreaming.EmdbHeaderServer); return [4 /*yield*/, plugin.fetch({ url: "".concat(emdbHeaderServer, "/").concat(emdbId.toUpperCase(), "/header/").concat(emdbId.toLowerCase(), ".xml"), type: 'xml' }).runInContext(taskCtx)]; case 1: header = _a.sent(); map = header.getElementsByTagName('map')[0]; contours = map.getElementsByTagName('contour'); primaryContour = contours[0]; for (i = 1; i < contours.length; i++) { if (contours[i].getAttribute('primary') === 'true') { primaryContour = contours[i]; break; } } contourLevel = parseFloat(primaryContour.getElementsByTagName('level')[0].textContent); return [2 /*return*/, contourLevel]; } }); }); } exports.getContourLevelEmdb = getContourLevelEmdb; function getContourLevelPdbe(plugin, taskCtx, emdbId) { var _a, _b, _c, _d; return tslib_1.__awaiter(this, void 0, void 0, function () { var header, contours; return tslib_1.__generator(this, function (_e) { switch (_e.label) { case 0: // TODO: parametrize URL in plugin settings? emdbId = emdbId.toUpperCase(); return [4 /*yield*/, plugin.fetch({ url: "https://www.ebi.ac.uk/emdb/api/entry/map/".concat(emdbId), type: 'json' }).runInContext(taskCtx)]; case 1: header = _e.sent(); contours = (_b = (_a = header === null || header === void 0 ? void 0 : header.map) === null || _a === void 0 ? void 0 : _a.contour_list) === null || _b === void 0 ? void 0 : _b.contour; if (!contours || contours.length === 0) { // try fallback to the old API return [2 /*return*/, getContourLevelPdbeLegacy(plugin, taskCtx, emdbId)]; } return [2 /*return*/, (_d = (_c = contours.find(function (c) { return c.primary; })) === null || _c === void 0 ? void 0 : _c.level) !== null && _d !== void 0 ? _d : contours[0].level]; } }); }); } exports.getContourLevelPdbe = getContourLevelPdbe; function getContourLevelPdbeLegacy(plugin, taskCtx, emdbId) { var _a, _b, _c; return tslib_1.__awaiter(this, void 0, void 0, function () { var header, emdbEntry, contourLevel; return tslib_1.__generator(this, function (_d) { switch (_d.label) { case 0: // TODO: parametrize URL in plugin settings? emdbId = emdbId.toUpperCase(); return [4 /*yield*/, plugin.fetch({ url: "https://www.ebi.ac.uk/pdbe/api/emdb/entry/map/".concat(emdbId), type: 'json' }).runInContext(taskCtx)]; case 1: header = _d.sent(); emdbEntry = header === null || header === void 0 ? void 0 : header[emdbId]; contourLevel = void 0; if (((_c = (_b = (_a = emdbEntry === null || emdbEntry === void 0 ? void 0 : emdbEntry[0]) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.contour_level) === null || _c === void 0 ? void 0 : _c.value) !== void 0) { contourLevel = +emdbEntry[0].map.contour_level.value; } return [2 /*return*/, contourLevel]; } }); }); } function getEmdbIds(plugin, taskCtx, pdbId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function () { var summary, summaryEntry, emdbIds, emdb; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, plugin.fetch({ url: "https://www.ebi.ac.uk/pdbe/api/pdb/entry/summary/".concat(pdbId), type: 'json' }).runInContext(taskCtx)]; case 1: summary = _b.sent(); summaryEntry = summary === null || summary === void 0 ? void 0 : summary[pdbId]; emdbIds = []; if ((_a = summaryEntry === null || summaryEntry === void 0 ? void 0 : summaryEntry[0]) === null || _a === void 0 ? void 0 : _a.related_structures) { emdb = summaryEntry[0].related_structures.filter(function (s) { return s.resource === 'EMDB' && s.relationship === 'associated EM volume'; }); if (!emdb.length) { throw new Error("No related EMDB entry found for '".concat(pdbId, "'.")); } emdbIds.push.apply(emdbIds, emdb.map(function (e) { return e.accession; })); } else { throw new Error("No related EMDB entry found for '".concat(pdbId, "'.")); } return [2 /*return*/, emdbIds]; } }); }); } exports.getEmdbIds = getEmdbIds;