Commit 2c11db91 authored by Lukas Pravda's avatar Lukas Pravda
Browse files

refactor thw way resources are consumed

parent cdaee595
......@@ -38,8 +38,8 @@ class Visualization {
this.environment = this.parseEnvironment(env);
this.parent.style.cssText += "display: block; height: 100%; width: 100%; position: relative;";
this.visualsMapper = new VisualsMapper();
this.rProvider = ResidueProvider.getInstance();
this.visualsMapper = new VisualsMapper(this.environment);
this.rProvider = ResidueProvider.getInstance(this.environment);
this.fullScreen = false;
if (uiParameters === undefined) uiParameters = new Config.UIParameters();
......@@ -326,7 +326,7 @@ class Visualization {
// #region menu functions
public saveSvg() {
d3.text(Resources.componentSvgCss)
d3.text(Resources.ligEnvCSSAPI(this.environment))
.then(x => {
let svgData = `
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" style="background-color: white;">
......@@ -373,6 +373,7 @@ class Visualization {
* @memberof Visualization
*/
public reinitialize() {
if (this.depiction === undefined) this.setupScene();
else this.setupLigandScene();
......@@ -729,7 +730,7 @@ class Visualization {
this.setupLinks();
// setup nodes; wait for resources to be ready
this.bindingSite.interactionNodes.forEach(x => ResidueProvider.getInstance().downloadAnnotation(x.residue));
this.bindingSite.interactionNodes.forEach(x => ResidueProvider.getInstance(this.environment).downloadAnnotation(x.residue));
await Promise.all(this.rProvider.downloadPromises);
await Promise.all([this.visualsMapper.graphicsPromise, this.visualsMapper.mappingPromise]);
......
......@@ -5,6 +5,7 @@
*/
class ResidueProvider {
private static instance: ResidueProvider;
private environment: Model.Environment;
private mapping: Map<string, string>;
public downloadPromises: Array<Promise<any>>;
......@@ -14,7 +15,8 @@ class ResidueProvider {
* construction calls with the `new` operator.
* @memberof ResidueProvider
*/
private constructor() {
private constructor(env: Model.Environment) {
this.environment = env;
this.mapping = new Map<string, string>(Config.aaAbreviations);
this.downloadPromises = new Array<Promise<any>>();
}
......@@ -30,9 +32,9 @@ class ResidueProvider {
* @returns {ResidueProvider}
* @memberof ResidueProvider
*/
public static getInstance(): ResidueProvider {
public static getInstance(env: Model.Environment = Model.Environment.Production): ResidueProvider {
if (!ResidueProvider.instance) {
ResidueProvider.instance = new ResidueProvider();
ResidueProvider.instance = new ResidueProvider(env);
}
return ResidueProvider.instance;
......@@ -61,7 +63,7 @@ class ResidueProvider {
public downloadAnnotation(r: Model.Residue): void {
if (this.mapping.has(r.chemCompId) || r.isLigand) return;
let url = Resources.residueTypeAPI(r.chemCompId);
let url = Resources.residueTypeAPI(r.chemCompId, this.environment);
let res = d3.json(url).then(x => {
let code = x[r.chemCompId][0].one_letter_code;
this.mapping.set(r.chemCompId, code);
......
namespace Resources {
export const productionAPI: string = 'https://www.ebi.ac.uk/pdbe/graph-api';
export const devAPI: string = 'https://wwwdev.ebi.ac.uk/pdbe/graph-api';
export const intAPI: string = 'https://wwwint.ebi.ac.uk/pdbe/graph-api';
export const productionAPI: string = 'https://www.ebi.ac.uk/pdbe';
export const devAPI: string = 'https://wwwdev.ebi.ac.uk/pdbe';
export const intAPI: string = 'https://wwwint.ebi.ac.uk/pdbe';
// export const glycanSymbols: string = 'https://pdbe.gitdocs.ebi.ac.uk/web-components/ligand-env/pdb-snfg-visuals.xml';
// export const glycanMapping: string = 'https://pdbe.gitdocs.ebi.ac.uk/web-components/ligand-env/het_mapping.json';
// export const componentSvgCss: string = 'https://pdbe.gitdocs.ebi.ac.uk/web-components/ligand-env/pdb-ligand-env-svg.css';
export const boundMoleculeURL: string = 'graph-api/pdb/bound_molecule_interactions';
export const carbohydrateURL: string = 'graph-api/pdb/carbohydrate_polymer_interactions';
export const boundLigandURL: string = 'graph-api/pdb/bound_ligand_interactions';
export const compoundSummaryURL: string = 'api/pdb/compound/summary';
export const componentLibraryURL: string = 'pdb-component-library/data/ligand-env';
export const staticFilesURL: string = 'static/files/pdbechem_v2';
export const glycanSymbols: string = 'https://www.ebi.ac.uk/pdbe/pdb-component-library/data/ligand-env/pdb-snfg-visuals.xml';
export const glycanMapping: string = 'https://www.ebi.ac.uk/pdbe/pdb-component-library/data/het_mapping.json';
export const componentSvgCss: string = 'https://www.ebi.ac.uk/pdbe/pdb-component-library/data/pdb-ligand-env-svg.css';
export function glycanSymbolsAPI(env: Model.Environment) {
let url = '';
switch (env) {
case Model.Environment.Internal:
case Model.Environment.Development: {
url = `${devAPI}/${componentLibraryURL}/pdb-snfg-visuals.xml`;
break;
}
default: {
url = `${productionAPI}/${componentLibraryURL}/pdb-snfg-visuals.xml`;
break;
}
}
return url;
}
export const residueTypeURL: string = "https://www.ebi.ac.uk/pdbe/api/pdb/compound/summary/";
export function ligandAnnotationAPI(ligandName: string, env: Model.Environment): string {
export function hetMappingAPI(env: Model.Environment) {
let url = '';
switch (env) {
case Model.Environment.Production: {
url = `https://www.ebi.ac.uk/pdbe/static/files/pdbechem_v2/${ligandName}/annotation`;
break;
switch (env) {
case Model.Environment.Internal:
case Model.Environment.Development: {
url = `${devAPI}/${componentLibraryURL}/het_mapping.json`;
break;
}
case Model.Environment.Development:
default: {
url = `${productionAPI}/${componentLibraryURL}/het_mapping.json`;
break;
}
}
return url;
}
export function ligEnvCSSAPI(env: Model.Environment) {
let url = '';
switch (env) {
case Model.Environment.Internal:
url = `https://wwwdev.ebi.ac.uk/pdbe/static/files/pdbechem_v2/${ligandName}/annotation`;
case Model.Environment.Development: {
url = `${devAPI}/pdbe/pdb-component-library/css/pdb-ligand-env-svg.css`;
break;
}
default: {
url = `${productionAPI}/pdbe/pdb-component-library/css/pdb-ligand-env-svg.css`;
break;
}
}
return url;
}
export function boundMoleculeAPI(pdbId: string, bmId: string, env: Model.Environment): string {
export function ligandAnnotationAPI(ligandName: string, env: Model.Environment): string {
let url = '';
switch (env) {
case Model.Environment.Production: {
url = `${productionAPI}/pdb/bound_molecule_interactions/${pdbId}/${bmId}`;
url = `${productionAPI}/${staticFilesURL}/${ligandName}/annotation`;
break;
}
case Model.Environment.Development:
case Model.Environment.Internal:
url = `${devAPI}/${staticFilesURL}/${ligandName}/annotation`;
}
return url;
}
export function boundMoleculeAPI(pdbId: string, bmId: string, env: Model.Environment): string {
let url = '';
switch (env) {
case Model.Environment.Development: {
url = `${devAPI}/pdb/bound_molecule_interactions/${pdbId}/${bmId}`;
url = `${devAPI}/${boundMoleculeURL}/${pdbId}/${bmId}`;
break;
}
case Model.Environment.Internal: {
url = `${intAPI}/pdb/bound_molecule_interactions/${pdbId}/${bmId}`;
url = `${intAPI}/${boundMoleculeURL}/${pdbId}/${bmId}`;
break;
}
default:
url = `${productionAPI}/${boundMoleculeURL}/${pdbId}/${bmId}`;
break;
}
return url;
}
export function carbohydratePolymerAPI(pdbId: string, bmId: string, entityId: string, env: Model.Environment): string {
let url = '';
switch (env) {
case Model.Environment.Production: {
url = `${productionAPI}/pdb/carbohydrate_polymer_interactions/${pdbId}/${bmId}/${entityId}`;
break;
}
case Model.Environment.Development: {
url = `${devAPI}/pdb/carbohydrate_polymer_interactions/${pdbId}/${bmId}/${entityId}`;
url = `${devAPI}/${carbohydrateURL}/${pdbId}/${bmId}/${entityId}`;
break;
}
case Model.Environment.Internal: {
url = `${intAPI}/pdb/carbohydrate_polymer_interactions/${pdbId}/${bmId}/${entityId}`;
url = `${intAPI}/${carbohydrateURL}/${pdbId}/${bmId}/${entityId}`;
break;
}
default:
url = `${productionAPI}/${carbohydrateURL}/${pdbId}/${bmId}/${entityId}`;
break;
}
return url;
}
/**
* Retrieve ligand interactions URL given the environment
*
* @export
* @param {string} pdbId
* @param {string} chainId
* @param {number} resId
* @param {Model.Environment} env
* @returns
*/
export function ligandInteractionsAPI(pdbId: string, chainId: string, resId: number, env: Model.Environment) {
let url = '';
switch (env) {
case Model.Environment.Production: {
url = `${productionAPI}/pdb/bound_ligand_interactions/${pdbId}/${chainId}/${resId}`;
break;
}
case Model.Environment.Development: {
url = `${devAPI}/pdb/bound_ligand_interactions/${pdbId}/${chainId}/${resId}`;
url = `${devAPI}/${boundLigandURL}/${pdbId}/${chainId}/${resId}`;
break;
}
case Model.Environment.Internal: {
url = `${intAPI}/pdb/bound_ligand_interactions/${pdbId}/${chainId}/${resId}`;
url = `${intAPI}/${boundLigandURL}/${pdbId}/${chainId}/${resId}`;
break;
}
default:
url = `${productionAPI}/${boundLigandURL}/${pdbId}/${chainId}/${resId}`;
break;
}
return url;
}
export function residueTypeAPI(chemCompId: string): string {
return `${residueTypeURL}${chemCompId}`;
/**
* Return residue type URL API
*
* @export
* @param {string} chemCompId
* @param {Model.Environment} env
* @returns {string}
*/
export function residueTypeAPI(chemCompId: string, env: Model.Environment): string {
let url = '';
switch (env) {
case Model.Environment.Development: {
url = `${devAPI}/${compoundSummaryURL}/${chemCompId}`;
break;
}
case Model.Environment.Internal: {
url = `${intAPI}/${compoundSummaryURL}/${chemCompId}`;
break;
}
default:
url = `${productionAPI}/${compoundSummaryURL}/${chemCompId}`;
break;
}
return url;
}
}
......@@ -6,22 +6,25 @@
*
* @class VisualsMapper
*/
class VisualsMapper {
class VisualsMapper {
public glycanImages: Map<string, SVGElement>;
public glycanMapping: Map<string, string>;
public glycanMapping: Map<string, string>;
public graphicsPromise: Promise<void>;
public mappingPromise: Promise<void>;
constructor() {
constructor(env: Model.Environment) {
this.glycanMapping = new Map<string, string>();
this.glycanImages = new Map<string, SVGElement>();
this.graphicsPromise = this.parseSymbols(Resources.glycanSymbols);
this.mappingPromise = this.parseGlycanMapping(Resources.glycanMapping);
let symbolsUrl = Resources.glycanSymbolsAPI(env);
let mappingUrl = Resources.hetMappingAPI(env);
this.graphicsPromise = this.parseSymbols(symbolsUrl);
this.mappingPromise = this.parseGlycanMapping(mappingUrl);
}
/**
* Gets proper glycan in the SVG format based on teh glycan class.
*
......@@ -49,7 +52,7 @@ class VisualsMapper {
let parsedImages: any = x.documentElement.getElementsByTagName('glycans')[0].getElementsByTagName('g');
for (let img of parsedImages) {
this.glycanImages.set(img.getAttribute('name'), img.outerHTML);
}
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment