web-schema.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author David Sehnal <david.sehnal@gmail.com>
  6. */
  7. import VERSION from './version'
  8. import { LimitsConfig, ServerConfig } from '../config';
  9. export function getSchema() {
  10. function detail(i: number) {
  11. return `${i} (${Math.round(100 * LimitsConfig.maxOutputSizeInVoxelCountByPrecisionLevel[i] / 1000 / 1000) / 100 }M voxels)`;
  12. }
  13. const detailMax = LimitsConfig.maxOutputSizeInVoxelCountByPrecisionLevel.length - 1;
  14. const sources = ServerConfig.idMap.map(m => m[0])
  15. return {
  16. openapi: '3.0.0',
  17. info: {
  18. version: VERSION,
  19. title: 'Volume Server',
  20. description: 'The VolumeServer is a service for accessing subsets of volumetric data. It automatically downsamples the data depending on the volume of the requested region to reduce the bandwidth requirements and provide near-instant access to even the largest data sets.',
  21. },
  22. tags: [
  23. {
  24. name: 'General',
  25. }
  26. ],
  27. paths: {
  28. [`${ServerConfig.apiPrefix}/{source}/{id}/`]: {
  29. get: {
  30. tags: ['General'],
  31. summary: 'Returns a JSON response specifying if data is available and the maximum region that can be queried.',
  32. operationId: 'getInfo',
  33. parameters: [
  34. { $ref: '#/components/parameters/source' },
  35. { $ref: '#/components/parameters/id' },
  36. ],
  37. responses: {
  38. 200: {
  39. description: 'Volume availability and info',
  40. content: {
  41. 'application/json': {
  42. schema: { $ref: '#/components/schemas/info' }
  43. }
  44. }
  45. },
  46. },
  47. }
  48. },
  49. [`${ServerConfig.apiPrefix}/{source}/{id}/box/{a1,a2,a3}/{b1,b2,b3}/`]: {
  50. get: {
  51. tags: ['General'],
  52. summary: 'Returns density data inside the specified box for the given entry. For X-ray data, returns 2Fo-Fc and Fo-Fc volumes in a single response.',
  53. operationId: 'getBox',
  54. parameters: [
  55. { $ref: '#/components/parameters/source' },
  56. { $ref: '#/components/parameters/id' },
  57. {
  58. name: 'bottomLeftCorner',
  59. in: 'path',
  60. description: 'Bottom left corner of the query region in Cartesian or fractional coordinates (determined by the `space` query parameter).',
  61. required: true,
  62. schema: {
  63. type: 'list',
  64. items: {
  65. type: 'float',
  66. }
  67. },
  68. style: 'simple'
  69. },
  70. {
  71. name: 'topRightCorner',
  72. in: 'path',
  73. description: 'Top right corner of the query region in Cartesian or fractional coordinates (determined by the `space` query parameter).',
  74. required: true,
  75. schema: {
  76. type: 'list',
  77. items: {
  78. type: 'float',
  79. }
  80. },
  81. style: 'simple'
  82. },
  83. { $ref: '#/components/parameters/encoding' },
  84. { $ref: '#/components/parameters/detail' },
  85. {
  86. name: 'space',
  87. in: 'query',
  88. description: 'Determines the coordinate space the query is in. Can be cartesian or fractional. An optional argument, default values is cartesian.',
  89. schema: {
  90. type: 'string',
  91. enum: ['cartesian', 'fractional']
  92. },
  93. style: 'form'
  94. }
  95. ],
  96. responses: {
  97. 200: {
  98. description: 'Volume box',
  99. content: {
  100. 'text/plain': {},
  101. 'application/octet-stream': {},
  102. }
  103. },
  104. },
  105. }
  106. },
  107. [`${ServerConfig.apiPrefix}/{source}/{id}/cell/`]: {
  108. get: {
  109. tags: ['General'],
  110. summary: 'Returns (downsampled) volume data for the entire "data cell". For X-ray data, returns unit cell of 2Fo-Fc and Fo-Fc volumes, for EM data returns everything.',
  111. operationId: 'getCell',
  112. parameters: [
  113. { $ref: '#/components/parameters/source' },
  114. { $ref: '#/components/parameters/id' },
  115. { $ref: '#/components/parameters/encoding' },
  116. { $ref: '#/components/parameters/detail' },
  117. ],
  118. responses: {
  119. 200: {
  120. description: 'Volume cell',
  121. content: {
  122. 'text/plain': {},
  123. 'application/octet-stream': {},
  124. }
  125. },
  126. },
  127. }
  128. }
  129. },
  130. components: {
  131. schemas: {
  132. // TODO how to keep in sync with (or derive from) `api.ts/ExtendedHeader`
  133. info: {
  134. properties: {
  135. formatVersion: {
  136. type: 'string',
  137. description: 'Format version number'
  138. },
  139. axisOrder: {
  140. type: 'array',
  141. items: { type: 'number' },
  142. description: 'Axis order from the slowest to fastest moving, same as in CCP4'
  143. },
  144. origin: {
  145. type: 'array',
  146. items: { type: 'number' },
  147. description: 'Origin in fractional coordinates, in axisOrder'
  148. },
  149. dimensions: {
  150. type: 'array',
  151. items: { type: 'number' },
  152. description: 'Dimensions in fractional coordinates, in axisOrder'
  153. },
  154. spacegroup: {
  155. properties: {
  156. number: { type: 'number' },
  157. size: {
  158. type: 'array',
  159. items: { type: 'number' }
  160. },
  161. angles: {
  162. type: 'array',
  163. items: { type: 'number' }
  164. },
  165. isPeriodic: {
  166. type: 'boolean',
  167. description: 'Determine if the data should be treated as periodic or not. (e.g. X-ray = periodic, EM = not periodic)'
  168. },
  169. }
  170. },
  171. channels: {
  172. type: 'array',
  173. items: { type: 'string' }
  174. },
  175. valueType: {
  176. type: 'string',
  177. enum: ['float32', 'int16', 'int8'],
  178. description: 'Determines the data type of the values'
  179. },
  180. blockSize: {
  181. type: 'number',
  182. description: 'The value are stored in blockSize^3 cubes'
  183. },
  184. sampling: {
  185. type: 'array',
  186. items: {
  187. properties: {
  188. byteOffset: { type: 'number' },
  189. rate: {
  190. type: 'number',
  191. description: 'How many values along each axis were collapsed into 1'
  192. },
  193. valuesInfo: {
  194. properties: {
  195. mean: { type: 'number' },
  196. sigma: { type: 'number' },
  197. min: { type: 'number' },
  198. max: { type: 'number' },
  199. }
  200. },
  201. sampleCount: {
  202. type: 'array',
  203. items: { type: 'number' },
  204. description: 'Number of samples along each axis, in axisOrder'
  205. },
  206. }
  207. }
  208. }
  209. }
  210. }
  211. },
  212. parameters: {
  213. source: {
  214. name: 'source',
  215. in: 'path',
  216. description: `Specifies the data source (determined by the experiment method). Currently supported sources are: ${sources.join(', ')}.`,
  217. required: true,
  218. schema: {
  219. type: 'string',
  220. enum: sources
  221. },
  222. style: 'simple'
  223. },
  224. id: {
  225. name: 'id',
  226. in: 'path',
  227. description: 'Id of the entry. For x-ray, use PDB ID (i.e. 1cbs) and for em use EMDB id (i.e. emd-8116).',
  228. required: true,
  229. schema: {
  230. type: 'string',
  231. },
  232. style: 'simple'
  233. },
  234. encoding: {
  235. name: 'encoding',
  236. in: 'query',
  237. description: 'Determines if text based CIF or binary BinaryCIF encoding is used. An optional argument, default is BinaryCIF encoding.',
  238. schema: {
  239. type: 'string',
  240. enum: ['cif', 'bcif']
  241. },
  242. style: 'form'
  243. },
  244. detail: {
  245. name: 'detail',
  246. in: 'query',
  247. description: `Determines the maximum number of voxels the query can return. Possible values are in the range from ${detail(0)} to ${detail(detailMax)}. Default value is 0. Note: different detail levels might lead to the same result.`,
  248. schema: {
  249. type: 'integer',
  250. },
  251. style: 'form'
  252. }
  253. }
  254. }
  255. }
  256. }
  257. export const shortcutIconLink = `<link rel='shortcut icon' href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAnUExURQAAAMIrHrspHr0oH7soILonHrwqH7onILsoHrsoH7soH7woILwpIKgVokoAAAAMdFJOUwAQHzNxWmBHS5XO6jdtAmoAAACZSURBVDjLxZNRCsQgDAVNXmwb9f7nXZEaLRgXloXOhwQdjMYYwpOLw55fBT46KhbOKhmRR2zLcFJQj8UR+HxFgArIF5BKJbEncC6NDEdI5SatBRSDJwGAoiFDONrEJXWYhGMIcRJGCrb1TOtDahfUuQXd10jkFYq0ViIrbUpNcVT6redeC1+b9tH2WLR93Sx2VCzkv/7NjfABxjQHksGB7lAAAAAASUVORK5CYII=' />`