-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathrcsb-datasource.ts
52 lines (46 loc) · 1.41 KB
/
rcsb-datasource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @file RCSB Datasource
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { Log, DatasourceRegistry } from '../globals'
import { getProtocol } from '../utils'
import { getFileInfo } from '../loader/loader-utils'
import Datasource from './datasource'
const baseUrl = '//files.rcsb.org/download/'
const mmtfBaseUrl = '//mmtf.rcsb.org/v1.0/'
const mmtfFullUrl = mmtfBaseUrl + 'full/'
const mmtfReducedUrl = mmtfBaseUrl + 'reduced/'
class RcsbDatasource extends Datasource {
getUrl (src: string) {
// valid path are
// XXXX.pdb, XXXX.pdb.gz, XXXX.cif, XXXX.cif.gz, XXXX.mmtf, XXXX.bb.mmtf
// XXXX defaults to XXXX.cif
const info = getFileInfo(src)
const pdbid = info.name.substr(0, 4)
let url
if ([ 'pdb', 'cif' ].includes(info.ext) &&
(info.compressed === false || info.compressed === 'gz')
) {
url = baseUrl + info.path
} else if (info.ext === 'mmtf') {
if (info.base.endsWith('.bb')) {
url = mmtfReducedUrl + pdbid
} else {
url = mmtfFullUrl + pdbid
}
} else if (!info.ext) {
url = mmtfFullUrl + pdbid
} else {
Log.warn('unsupported ext', info.ext)
url = mmtfFullUrl + pdbid
}
return getProtocol() + url
}
getExt (src: string) {
const ext = getFileInfo(src).ext
return ext ? ext : 'mmtf'
}
}
DatasourceRegistry.add('rcsb', new RcsbDatasource())
export default RcsbDatasource