@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
157 lines (156 loc) • 10.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rcsbRequestCtxManager = void 0;
const tslib_1 = require("tslib");
const PolymerEntityInstanceTranslate_1 = require("../RcsbUtils/Translators/PolymerEntityInstanceTranslate");
const EntryAssemblyTranslate_1 = require("../RcsbUtils/Translators/EntryAssemblyTranslate");
const GroupPropertiesProvider_1 = require("../RcsbUtils/Groups/GroupPropertiesProvider");
const InterfaceInstanceTranslate_1 = require("../RcsbUtils/Translators/InterfaceInstanceTranslate");
const AssemblyInterfacesTranslate_1 = require("../RcsbUtils/Translators/AssemblyInterfacesTranslate");
const PolymerEntityInstancesCollector_1 = require("../RcsbCollectTools/DataCollectors/PolymerEntityInstancesCollector");
const EntryAssembliesCollector_1 = require("../RcsbCollectTools/DataCollectors/EntryAssembliesCollector");
const PolymerEntityChromosomeTranslate_1 = require("../RcsbUtils/Translators/PolymerEntityChromosomeTranslate");
const PolymerEntityChromosomeCollector_1 = require("../RcsbCollectTools/DataCollectors/PolymerEntityChromosomeCollector");
const GroupMemberCollector_1 = require("../RcsbCollectTools/DataCollectors/GroupMemberCollector");
const MultipleEntryPropertyCollector_1 = require("../RcsbCollectTools/DataCollectors/MultipleEntryPropertyCollector");
const Operator_1 = require("../RcsbUtils/Helpers/Operator");
const SearchRequestProperty_1 = require("../RcsbSeacrh/SearchRequestProperty");
const object_hash_1 = require("object-hash");
const InterfaceInstanceCollector_1 = require("../RcsbCollectTools/DataCollectors/InterfaceInstanceCollector");
const AssemblyInterfacesCollector_1 = require("../RcsbCollectTools/DataCollectors/AssemblyInterfacesCollector");
const RcsbRequestTools_1 = require("./RcsbRequestTools");
const RcsbRequestClient_1 = require("./RcsbRequestClient");
const GraphQLRequest_1 = require("@rcsb/rcsb-api-tools/lib/RcsbGraphQL/GraphQLRequest");
const SearchRequest_1 = require("@rcsb/rcsb-api-tools/lib/RcsbSearch/SearchRequest");
const Assertions_1 = require("../RcsbUtils/Helpers/Assertions");
var assertDefined = Assertions_1.Assertions.assertDefined;
const MultiplePolymerEntityCollector_1 = require("../RcsbCollectTools/DataCollectors/MultiplePolymerEntityCollector");
const MultipleInstanceSequencesCollector_1 = require("../RcsbCollectTools/DataCollectors/MultipleInstanceSequencesCollector");
const TagDelimiter_1 = require("@rcsb/rcsb-api-tools/lib/RcsbUtils/TagDelimiter");
class RcsbRequestContextManager {
constructor() {
this.polymerEntityToInstanceMap = new Map();
this.entryToAssemblyMap = new Map();
this.groupPropertyMap = new Map();
this.searchRequestMap = new Map();
this.interfaceToInstanceMap = new Map();
this.assemblyInterfacesMap = new Map();
this.entryPropertyMap = new Map();
this.entityPropertyMap = new Map();
this.instanceSequenceMap = new Map();
this.instanceCollector = new PolymerEntityInstancesCollector_1.PolymerEntityInstancesCollector();
this.assemblyCollector = new EntryAssembliesCollector_1.EntryAssembliesCollector();
this.entityChrCollector = new PolymerEntityChromosomeCollector_1.PolymerEntityChromosomeCollector();
this.groupMemberCollector = new GroupMemberCollector_1.GroupMemberCollector();
this.multipleEntryPropertyCollector = new MultipleEntryPropertyCollector_1.MultipleEntryPropertyCollector();
this.interfaceCollector = new InterfaceInstanceCollector_1.InterfaceInstanceCollector();
this.assemblyInterfacesCollector = new AssemblyInterfacesCollector_1.AssemblyInterfacesCollector();
this.multipleEntityCollector = new MultiplePolymerEntityCollector_1.MultiplePolymerEntityCollector();
this.multipleInstanceSequenceCollector = new MultipleInstanceSequencesCollector_1.MultipleInstanceSequencesCollector();
this.modelKey = EntryAssembliesCollector_1.EntryAssembliesCollector.modelKey;
}
getEntityProperties(entityIds) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return RcsbRequestTools_1.RcsbRequestTools.getMultipleObjectProperties(entityIds, this.entityPropertyMap, this.multipleEntityCollector, "entity_ids", (e) => (e.entryId + TagDelimiter_1.TagDelimiter.entity + e.entityId));
});
}
getEntryProperties(entryIds) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return RcsbRequestTools_1.RcsbRequestTools.getMultipleObjectProperties(entryIds, this.entryPropertyMap, this.multipleEntryPropertyCollector, "entry_ids", (e) => (e.entryId));
});
}
getInstanceSequences(instanceIds) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return RcsbRequestTools_1.RcsbRequestTools.getMultipleObjectProperties(instanceIds, this.instanceSequenceMap, this.multipleInstanceSequenceCollector, "instance_ids", (e) => (e.rcsbId));
});
}
getEntityToInstance(entryId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = entryId.toUpperCase();
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(key, this.polymerEntityToInstanceMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (new PolymerEntityInstanceTranslate_1.PolymerEntityInstanceTranslate(yield this.instanceCollector.collect({ entry_id: key }))); }));
});
}
getEntryToAssembly(entryId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(entryId, this.entryToAssemblyMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.assemblyCollector.collect({ entry_id: entryId });
const eti = this.polymerEntityToInstanceMap.get(entryId);
const etit = result.get(this.modelKey);
assertDefined(eti), assertDefined(etit);
return new EntryAssemblyTranslate_1.EntryAssemblyTranslate(result);
}));
});
}
getEntityToChromosome(entityIds) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const chrMap = yield this.entityChrCollector.collect(entityIds);
return new PolymerEntityChromosomeTranslate_1.PolymerEntityChromosomeTranslate(chrMap);
});
}
getGroupMemberProperties(groupQuery) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const groupId = groupQuery.group_id.toUpperCase();
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(groupId, this.groupPropertyMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.groupMemberCollector.collect(groupQuery);
const entriesProperties = yield this.multipleEntryPropertyCollector.collect({ entry_ids: Operator_1.Operator.uniqueValues(result.map(r => r.entryId)) });
return new GroupPropertiesProvider_1.GroupPropertiesProvider({ entryProperties: entriesProperties });
}));
});
}
getSearchQuery(searchQuery) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = (0, object_hash_1.sha1)(searchQuery);
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(key, this.searchRequestMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield SearchRequestProperty_1.searchRequestProperty.request(searchQuery)); }));
});
}
getSearchQueryFacets(query, facets, returnType, resultsContentType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = (0, object_hash_1.sha1)(query) + "." + (0, object_hash_1.sha1)(facets);
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(key, this.searchRequestMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield SearchRequestProperty_1.searchRequestProperty.requestFacets(query, facets, returnType, resultsContentType)); }));
});
}
getInterfaceToInstance(interfaceId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b;
const key = interfaceId;
const assemblyId = interfaceId.split(TagDelimiter_1.TagDelimiter.instance)[0];
if (this.interfaceToInstanceMap.get(key)) {
const d = this.interfaceToInstanceMap.get(key);
assertDefined(d);
return d;
}
else {
const assemblyInterfaces = yield this.getAssemblyInterfaces(assemblyId);
const interfaceIds = assemblyInterfaces.getInterfaces(assemblyId);
const result = interfaceIds ? yield this.interfaceCollector.collect({ interface_ids: interfaceIds }) : [];
const translator = new InterfaceInstanceTranslate_1.InterfaceInstanceTranslate(result);
if (((_a = assemblyInterfaces.getInterfaces(assemblyId)) === null || _a === void 0 ? void 0 : _a.length) == 0) {
this.interfaceToInstanceMap.set(key, new Promise(resolve => resolve(translator)));
}
((_b = assemblyInterfaces.getInterfaces(assemblyId)) !== null && _b !== void 0 ? _b : []).filter(id => !this.interfaceToInstanceMap.has(id)).forEach(id => {
this.interfaceToInstanceMap.set(id, new Promise(resolve => resolve(translator)));
});
return translator;
}
});
}
getAssemblyInterfaces(assemblyId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return RcsbRequestTools_1.RcsbRequestTools.getSingleObjectData(assemblyId, this.assemblyInterfacesMap, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
return (new AssemblyInterfacesTranslate_1.AssemblyInterfacesTranslate(yield this.assemblyInterfacesCollector.collect({ assembly_ids: [assemblyId] })));
}));
});
}
initializeBorregoClient(config) {
var _a;
RcsbRequestClient_1.rcsbRequestClient.borrego = new GraphQLRequest_1.GraphQLRequest((_a = config.api) !== null && _a !== void 0 ? _a : "1d-coordinates", config.requestConfig);
}
initializeYosemiteClient(config) {
var _a;
RcsbRequestClient_1.rcsbRequestClient.yosemite = new GraphQLRequest_1.GraphQLRequest((_a = config.api) !== null && _a !== void 0 ? _a : "data-api", config.requestConfig);
}
initializeArchesClient(config) {
RcsbRequestClient_1.rcsbRequestClient.arches = new SearchRequest_1.SearchRequest(config.uri, config.fetch, config.requestConfig);
}
}
exports.rcsbRequestCtxManager = new RcsbRequestContextManager();