molstar
Version:
A comprehensive macromolecular library.
156 lines • 7.69 kB
JavaScript
/**
* 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>
*/
import { __awaiter, __generator } from "tslib";
import { Model } from '../../../../mol-model/structure';
import { MmcifFormat } from '../../../../mol-model-formats/structure/mmcif';
import { PluginConfig } from '../../../config';
export function getStreamingMethod(s, defaultKind) {
if (defaultKind === void 0) { defaultKind = 'x-ray'; }
if (!s)
return defaultKind;
var model = s.models[0];
if (!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 (Model.hasEmMap(model))
return 'em';
if (Model.hasXrayMap(model))
return 'x-ray';
// Fallbacks based on experimental method
if (Model.isFromEm(model))
return 'em';
if (Model.isFromXray(model))
return 'x-ray';
return defaultKind;
}
/** Returns EMD ID when available, otherwise falls back to PDB ID */
export function getEmIds(model) {
var ids = [];
if (!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;
}
export function getXrayIds(model) {
return [model.entryId];
}
export 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);
}
}
export function getContourLevel(provider, plugin, taskCtx, emdbId) {
return __awaiter(this, void 0, void 0, function () {
return __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*/];
});
});
}
export function getContourLevelEmdb(plugin, taskCtx, emdbId) {
return __awaiter(this, void 0, void 0, function () {
var emdbHeaderServer, header, map, contourLevel;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
emdbHeaderServer = plugin.config.get(PluginConfig.VolumeStreaming.EmdbHeaderServer);
return [4 /*yield*/, plugin.fetch({ url: emdbHeaderServer + "/" + emdbId.toUpperCase() + "/header/" + emdbId.toLowerCase() + ".xml", type: 'xml' }).runInContext(taskCtx)];
case 1:
header = _a.sent();
map = header.getElementsByTagName('map')[0];
contourLevel = parseFloat(map.getElementsByTagName('contourLevel')[0].textContent);
return [2 /*return*/, contourLevel];
}
});
});
}
export function getContourLevelPdbe(plugin, taskCtx, emdbId) {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function () {
var header, contours;
return __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/" + 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];
}
});
});
}
function getContourLevelPdbeLegacy(plugin, taskCtx, emdbId) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var header, emdbEntry, contourLevel;
return __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/" + 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];
}
});
});
}
export function getEmdbIds(plugin, taskCtx, pdbId) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var summary, summaryEntry, emdbIds, emdb;
return __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/" + 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 '" + pdbId + "'.");
}
emdbIds.push.apply(emdbIds, emdb.map(function (e) { return e.accession; }));
}
else {
throw new Error("No related EMDB entry found for '" + pdbId + "'.");
}
return [2 /*return*/, emdbIds];
}
});
});
}
//# sourceMappingURL=util.js.map