Skip to content
Snippets Groups Projects
Commit 77ec7c09 authored by David Sehnal's avatar David Sehnal
Browse files

model-server: tweak api, added examples to landing page

parent 2fa188dc
Branches mol-model
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ let exampleWorkload: LocalInput = [{ ...@@ -19,7 +19,7 @@ let exampleWorkload: LocalInput = [{
input: 'c:/test/quick/1tqn.cif', input: 'c:/test/quick/1tqn.cif',
output: 'c:/test/quick/localapi/1tqn_full.bcif', output: 'c:/test/quick/localapi/1tqn_full.bcif',
query: 'full', query: 'full',
params: { binary: true } params: {}
}, { }, {
input: 'c:/test/quick/1cbs_updated.cif', input: 'c:/test/quick/1cbs_updated.cif',
output: 'c:/test/quick/localapi/1cbs_ligint.cif', output: 'c:/test/quick/localapi/1cbs_ligint.cif',
...@@ -29,7 +29,7 @@ let exampleWorkload: LocalInput = [{ ...@@ -29,7 +29,7 @@ let exampleWorkload: LocalInput = [{
input: 'c:/test/quick/1cbs_updated.cif', // multiple files that are repeated will only be parsed once input: 'c:/test/quick/1cbs_updated.cif', // multiple files that are repeated will only be parsed once
output: 'c:/test/quick/localapi/1cbs_ligint.bcif', output: 'c:/test/quick/localapi/1cbs_ligint.bcif',
query: 'residueInteraction', query: 'residueInteraction',
params: { label_comp_id: 'REA', binary: true } // parameters are just a JSON version of the query string params: { label_comp_id: 'REA' } // parameters are just a JSON version of the query string
} }
]; ];
......
...@@ -18,7 +18,8 @@ export type LocalInput = { ...@@ -18,7 +18,8 @@ export type LocalInput = {
output: string, output: string,
query: string, query: string,
modelNums?: number[], modelNums?: number[],
params?: any params?: any,
binary?: boolean
}[]; }[];
export async function runLocal(input: LocalInput) { export async function runLocal(input: LocalInput) {
...@@ -28,7 +29,12 @@ export async function runLocal(input: LocalInput) { ...@@ -28,7 +29,12 @@ export async function runLocal(input: LocalInput) {
} }
for (const job of input) { for (const job of input) {
JobManager.add('_local_', job.input, job.query, job.params || { }, job.modelNums, job.output); const binary = /\.bcif/.test(job.output);
JobManager.add('_local_', job.input, job.query, job.params || { }, {
modelNums: job.modelNums,
outputFilename: job.output,
binary
});
} }
JobManager.sort(); JobManager.sort();
......
...@@ -133,8 +133,8 @@ export function initWebApi(app: express.Express) { ...@@ -133,8 +133,8 @@ export function initWebApi(app: express.Express) {
const args = JSON.parse(decodeURIComponent(query)); const args = JSON.parse(decodeURIComponent(query));
const name = args.name; const name = args.name;
const entryId = args.id; const entryId = args.id;
const params = args.params || { }; const queryParams = args.params || { };
const jobId = JobManager.add('pdb', entryId, name, params, args.modelNums); const jobId = JobManager.add('pdb', entryId, name, queryParams, { modelNums: args.modelNums, binary: args.binary });
responseMap.set(jobId, res); responseMap.set(jobId, res);
if (JobManager.size === 1) processNextJob(); if (JobManager.size === 1) processNextJob();
}); });
......
...@@ -28,11 +28,12 @@ export interface Job { ...@@ -28,11 +28,12 @@ export interface Job {
outputFilename?: string outputFilename?: string
} }
export function createJob(sourceId: '_local_' | string, entryId: string, queryName: string, params: any, modelNums?: number[], outputFilename?: string): Job { export function createJob(sourceId: '_local_' | string, entryId: string, queryName: string, queryParams: any,
options ?: { modelNums?: number[], outputFilename?: string, binary?: boolean }): Job {
const queryDefinition = getQueryByName(queryName); const queryDefinition = getQueryByName(queryName);
if (!queryDefinition) throw new Error(`Query '${queryName}' is not supported.`); if (!queryDefinition) throw new Error(`Query '${queryName}' is not supported.`);
const normalizedParams = normalizeQueryParams(queryDefinition, params); const normalizedParams = normalizeQueryParams(queryDefinition, queryParams);
return { return {
id: UUID.create(), id: UUID.create(),
...@@ -42,9 +43,9 @@ export function createJob(sourceId: '_local_' | string, entryId: string, queryNa ...@@ -42,9 +43,9 @@ export function createJob(sourceId: '_local_' | string, entryId: string, queryNa
entryId, entryId,
queryDefinition, queryDefinition,
normalizedParams, normalizedParams,
responseFormat: { isBinary: !!params.binary }, responseFormat: { isBinary: !!(options && options.binary) },
modelNums, modelNums: options && options.modelNums,
outputFilename outputFilename: options && options.outputFilename
}; };
} }
...@@ -55,8 +56,9 @@ class _JobQueue { ...@@ -55,8 +56,9 @@ class _JobQueue {
return this.list.count; return this.list.count;
} }
add(sourceId: '_local_' | string, entryId: string, queryName: string, params: any, modelNums?: number[], outputFilename?: string) { add(sourceId: '_local_' | string, entryId: string, queryName: string, queryParams: any,
const job = createJob(sourceId, entryId, queryName, params, modelNums, outputFilename); options?: { modelNums?: number[], outputFilename?: string, binary?: boolean }) {
const job = createJob(sourceId, entryId, queryName, queryParams, options);
this.list.addLast(job); this.list.addLast(job);
return job.id; return job.id;
} }
......
...@@ -6,6 +6,45 @@ ...@@ -6,6 +6,45 @@
import Version from '../version' import Version from '../version'
const examples = [{
name: 'Atoms',
params: {
id: '1cbs',
name: 'atoms',
params: { atom_site: { label_comp_id: 'ALA' } }
}
}, {
name: 'Residue Interaction',
params: {
id: '1cbs',
name: 'residueInteraction',
params: {
radius: 5,
atom_site: { 'label_comp_id': 'REA' }
}
}
}, {
name: 'Full',
params: {
id: '1tqn',
name: 'full'
}
}, {
name: 'Full (binary)',
params: {
id: '1tqn',
name: 'full',
binary: true
}
}, {
name: 'Full (specific models)',
params: {
id: '1grm',
name: 'full',
modelNums: [ 2, 3 ]
}
}];
function create() { function create() {
return `<!DOCTYPE html> return `<!DOCTYPE html>
<html lang="en"> <html lang="en">
...@@ -17,30 +56,35 @@ function create() { ...@@ -17,30 +56,35 @@ function create() {
</head> </head>
<body> <body>
<h1>Mol* Model Server ${Version}</h1> <h1>Mol* Model Server ${Version}</h1>
<textarea style="height: 280px; width: 600px; font-family: monospace" id="query-text">{ <select id='example'>
"id": "1cbs", <option value='-1'>Select example...</option>
"name": "residueInteraction", ${examples.map((e, i) => `<option value=${i}>${e.name}</option>`)}
"params": { </select>
"radius": 5, <br/>
"atom_site": { "label_comp_id": "REA" } <textarea style="height: 280px; width: 600px; font-family: monospace" id="query-text"></textarea><br>
}
}</textarea><br>
<button class="button button-primary" style="width: 600px" id="query">Query</button> <button class="button button-primary" style="width: 600px" id="query">Query</button>
<div id='error' style='color: red; font-weight: blue'></div> <div id='error' style='color: red; font-weight: blue'></div>
<div>Static input files available as CIF and BinaryCIF at <a href='ModelServer/static/cif/1cbs' target='_blank'>static/cif/id</a> and <a href='ModelServer/static/bcif/1cbs' target='_blank'>static/bcif/id</a> respectively.</div> <div>Static input files available as CIF and BinaryCIF at <a href='ModelServer/static/cif/1cbs' target='_blank'>static/cif/id</a> and <a href='ModelServer/static/bcif/1cbs' target='_blank'>static/bcif/id</a> respectively.</div>
<script> <script>
const err = document.getElementById('error'); var Examples = ${JSON.stringify(examples)};
var err = document.getElementById('error');
var exampleEl = document.getElementById('example'), queryTextEl = document.getElementById('query-text');
exampleEl.onchange = function () {
var i = +exampleEl.value;
if (i < 0) return;
queryTextEl.value = JSON.stringify(Examples[i].params, null, 2);
};
document.getElementById('query').onclick = function () { document.getElementById('query').onclick = function () {
err.innerText = ''; err.innerText = '';
try { try {
var q = JSON.parse(document.getElementById('query-text').value); var q = JSON.parse(queryTextEl.value);
var path = 'ModelServer/api/v1?' + encodeURIComponent(JSON.stringify(q)); var path = 'ModelServer/api/v1?' + encodeURIComponent(JSON.stringify(q));
console.log(path); console.log(path);
window.open(path, '_blank'); window.open(path, '_blank');
} catch (e) { } catch (e) {
err.innerText = '' + e; err.innerText = '' + e;
} }
} };
</script> </script>
</body> </body>
</html>`; </html>`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment