From f7fa68d9aa2a6e5f4dd7075e73625feab84f0dbc Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Mon, 10 Sep 2018 16:01:47 +0200 Subject: [PATCH] Added BinaryCIF support to the Canvas app --- src/apps/canvas/app.ts | 14 ++++++++------ src/apps/canvas/component/app.tsx | 12 ++++++++---- src/apps/canvas/index.ts | 2 +- src/apps/canvas/util.ts | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/apps/canvas/app.ts b/src/apps/canvas/app.ts index 9aeeccf00..af974f06c 100644 --- a/src/apps/canvas/app.ts +++ b/src/apps/canvas/app.ts @@ -38,15 +38,17 @@ export class App { this.pdbIdLoaded.next(this.structureView) } - async loadPdbId(id: string, assemblyId?: string) { - if (this.structureView) this.structureView.destroy() - const cif = await getCifFromUrl(`https://files.rcsb.org/download/${id}.cif`) - this.loadCif(cif, assemblyId) + async loadPdbIdOrUrl(idOrUrl: string, options?: { assemblyId?: string, binary?: boolean }) { + if (this.structureView) this.structureView.destroy(); + const url = idOrUrl.length <= 4 ? `https://files.rcsb.org/download/${idOrUrl}.cif` : idOrUrl; + const cif = await getCifFromUrl(url, options ? !!options.binary : false) + this.loadCif(cif, options ? options.assemblyId : void 0) } async loadCifFile(file: File) { - if (this.structureView) this.structureView.destroy() - const cif = await getCifFromFile(file) + if (this.structureView) this.structureView.destroy(); + const binary = /\.bcif$/.test(file.name); + const cif = await getCifFromFile(file, binary) this.loadCif(cif) } } \ No newline at end of file diff --git a/src/apps/canvas/component/app.tsx b/src/apps/canvas/component/app.tsx index c1d099b6a..ec4cb9be2 100644 --- a/src/apps/canvas/component/app.tsx +++ b/src/apps/canvas/component/app.tsx @@ -16,12 +16,14 @@ export interface AppProps { } export interface AppState { - structureView: StructureView | null + structureView: StructureView | null, + binary: boolean } export class AppComponent extends React.Component<AppProps, AppState> { state = { structureView: this.props.app.structureView, + binary: false } componentDidMount() { @@ -42,14 +44,16 @@ export class AppComponent extends React.Component<AppProps, AppState> { <div style={{width: '330px', paddingLeft: '10px', paddingRight: '10px', right: '0px', height: '100%', position: 'absolute', overflow: 'auto'}}> <div style={{marginTop: '10px'}}> - <span>Load PDB ID </span> + <span>Load PDB ID or URL</span> + <input type='checkbox' checked={this.state.binary} onChange={e => this.setState({ binary: e.target.checked })} /> Binary<br /> <input + style={{ width: '100%' }} type='text' onKeyDown={e => { if (e.keyCode === 13) { const value = e.currentTarget.value.trim() if (value) { - this.props.app.loadPdbId(value) + this.props.app.loadPdbIdOrUrl(value, { binary: this.state.binary }) } } }} @@ -70,7 +74,7 @@ export class AppComponent extends React.Component<AppProps, AppState> { <select style={{width: '200px'}} onChange={e => { - this.props.app.loadPdbId(e.target.value) + this.props.app.loadPdbIdOrUrl(e.target.value) }} > <option value=''></option> diff --git a/src/apps/canvas/index.ts b/src/apps/canvas/index.ts index 0c110a885..05ec4d373 100644 --- a/src/apps/canvas/index.ts +++ b/src/apps/canvas/index.ts @@ -21,4 +21,4 @@ ReactDOM.render(React.createElement(AppComponent, { app }), elm); const assemblyId = urlQueryParameter('assembly') const pdbId = urlQueryParameter('pdb') -if (pdbId) app.loadPdbId(pdbId, assemblyId) \ No newline at end of file +if (pdbId) app.loadPdbIdOrUrl(pdbId, { assemblyId }) \ No newline at end of file diff --git a/src/apps/canvas/util.ts b/src/apps/canvas/util.ts index 9a2c8f7fa..577c3a3da 100644 --- a/src/apps/canvas/util.ts +++ b/src/apps/canvas/util.ts @@ -24,8 +24,8 @@ export async function getCifFromData(data: string | Uint8Array) { return parsed.result.blocks[0] } -export async function getCifFromUrl(url: string) { - return getCifFromData(await readUrlAs(url, false)) +export async function getCifFromUrl(url: string, binary = false) { + return getCifFromData(await readUrlAs(url, binary)) } export async function getCifFromFile(file: File, binary = false) { -- GitLab