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
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ let exampleWorkload: LocalInput = [{
input: 'c:/test/quick/1tqn.cif',
output: 'c:/test/quick/localapi/1tqn_full.bcif',
query: 'full',
params: { binary: true }
params: {}
}, {
input: 'c:/test/quick/1cbs_updated.cif',
output: 'c:/test/quick/localapi/1cbs_ligint.cif',
......@@ -29,7 +29,7 @@ let exampleWorkload: LocalInput = [{
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',
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 = {
output: string,
query: string,
modelNums?: number[],
params?: any
params?: any,
binary?: boolean
}[];
export async function runLocal(input: LocalInput) {
......@@ -28,7 +29,12 @@ export async function runLocal(input: LocalInput) {
}
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();
......
......@@ -133,8 +133,8 @@ export function initWebApi(app: express.Express) {
const args = JSON.parse(decodeURIComponent(query));
const name = args.name;
const entryId = args.id;
const params = args.params || { };
const jobId = JobManager.add('pdb', entryId, name, params, args.modelNums);
const queryParams = args.params || { };
const jobId = JobManager.add('pdb', entryId, name, queryParams, { modelNums: args.modelNums, binary: args.binary });
responseMap.set(jobId, res);
if (JobManager.size === 1) processNextJob();
});
......
......@@ -28,11 +28,12 @@ export interface Job {
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);
if (!queryDefinition) throw new Error(`Query '${queryName}' is not supported.`);
const normalizedParams = normalizeQueryParams(queryDefinition, params);
const normalizedParams = normalizeQueryParams(queryDefinition, queryParams);
return {
id: UUID.create(),
......@@ -42,9 +43,9 @@ export function createJob(sourceId: '_local_' | string, entryId: string, queryNa
entryId,
queryDefinition,
normalizedParams,
responseFormat: { isBinary: !!params.binary },
modelNums,
outputFilename
responseFormat: { isBinary: !!(options && options.binary) },
modelNums: options && options.modelNums,
outputFilename: options && options.outputFilename
};
}
......@@ -55,8 +56,9 @@ class _JobQueue {
return this.list.count;
}
add(sourceId: '_local_' | string, entryId: string, queryName: string, params: any, modelNums?: number[], outputFilename?: string) {
const job = createJob(sourceId, entryId, queryName, params, modelNums, outputFilename);
add(sourceId: '_local_' | string, entryId: string, queryName: string, queryParams: any,
options?: { modelNums?: number[], outputFilename?: string, binary?: boolean }) {
const job = createJob(sourceId, entryId, queryName, queryParams, options);
this.list.addLast(job);
return job.id;
}
......
......@@ -6,6 +6,45 @@
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() {
return `<!DOCTYPE html>
<html lang="en">
......@@ -17,30 +56,35 @@ function create() {
</head>
<body>
<h1>Mol* Model Server ${Version}</h1>
<textarea style="height: 280px; width: 600px; font-family: monospace" id="query-text">{
"id": "1cbs",
"name": "residueInteraction",
"params": {
"radius": 5,
"atom_site": { "label_comp_id": "REA" }
}
}</textarea><br>
<select id='example'>
<option value='-1'>Select example...</option>
${examples.map((e, i) => `<option value=${i}>${e.name}</option>`)}
</select>
<br/>
<textarea style="height: 280px; width: 600px; font-family: monospace" id="query-text"></textarea><br>
<button class="button button-primary" style="width: 600px" id="query">Query</button>
<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>
<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 () {
err.innerText = '';
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));
console.log(path);
window.open(path, '_blank');
} catch (e) {
err.innerText = '' + e;
}
}
};
</script>
</body>
</html>`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment