schemas.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Copyright (c) 2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Adam Midlik <midlik@gmail.com>
  5. */
  6. import { Column, Table } from '../../../mol-data/db';
  7. import { pickObjectKeys } from '../../../mol-util/object';
  8. import { Choice } from '../../../mol-util/param-choice';
  9. const { str, int } = Column.Schema;
  10. /** Names of allowed MVS annotation schemas (values for the annotation schema parameter) */
  11. export type MVSAnnotationSchema = Choice.Values<typeof MVSAnnotationSchema>
  12. export const MVSAnnotationSchema = new Choice(
  13. {
  14. whole_structure: 'Whole Structure',
  15. entity: 'Entity',
  16. chain: 'Chain (label*)',
  17. auth_chain: 'Chain (auth*)',
  18. residue: 'Residue (label*)',
  19. auth_residue: 'Residue (auth*)',
  20. residue_range: 'Residue range (label*)',
  21. auth_residue_range: 'Residue range (auth*)',
  22. atom: 'Atom (label*)',
  23. auth_atom: 'Atom (auth*)',
  24. all_atomic: 'All atomic selectors',
  25. },
  26. 'all_atomic',
  27. );
  28. /** Represents a set of criteria for selection of atoms in a model (in `all_atomic` schema).
  29. * Missing/undefined values mean that we do not care about that specific atom property. */
  30. export type MVSAnnotationRow = Partial<Table.Row<typeof AllAtomicCifAnnotationSchema>>
  31. /** Get CIF schema definition for given annotation schema name */
  32. export function getCifAnnotationSchema<K extends MVSAnnotationSchema>(schemaName: K): Pick<typeof AllAtomicCifAnnotationSchema, (typeof FieldsForSchemas)[K][number]> {
  33. return pickObjectKeys(AllAtomicCifAnnotationSchema, FieldsForSchemas[schemaName]);
  34. }
  35. /** Definition of `all_atomic` schema for CIF (other atomic schemas are subschemas of this one) */
  36. const AllAtomicCifAnnotationSchema = {
  37. /** Tag for grouping multiple annotation rows with the same `group_id` (e.g. to show one label for two chains);
  38. * if the `group_id` is not given, each row is processed separately */
  39. group_id: str,
  40. label_entity_id: str,
  41. label_asym_id: str,
  42. auth_asym_id: str,
  43. label_seq_id: int,
  44. auth_seq_id: int,
  45. pdbx_PDB_ins_code: str,
  46. /** Minimum label_seq_id (inclusive) */
  47. beg_label_seq_id: int,
  48. /** Maximum label_seq_id (inclusive) */
  49. end_label_seq_id: int,
  50. /** Minimum auth_seq_id (inclusive) */
  51. beg_auth_seq_id: int,
  52. /** Maximum auth_seq_id (inclusive) */
  53. end_auth_seq_id: int,
  54. /** Atom name like 'CA', 'N', 'O'... */
  55. label_atom_id: str,
  56. /** Atom name like 'CA', 'N', 'O'... */
  57. auth_atom_id: str,
  58. /** Element symbol like 'H', 'He', 'Li', 'Be' (case-insensitive)... */
  59. type_symbol: str,
  60. /** Unique atom identifier across conformations (_atom_site.id) */
  61. atom_id: int,
  62. /** 0-based index of the atom in the source data */
  63. atom_index: int,
  64. } satisfies Table.Schema;
  65. /** Allowed fields (i.e. CIF columns or JSON keys) for each annotation schema
  66. * (other fields will just be ignored) */
  67. const FieldsForSchemas = {
  68. whole_structure: ['group_id'],
  69. entity: ['group_id', 'label_entity_id'],
  70. chain: ['group_id', 'label_entity_id', 'label_asym_id'],
  71. auth_chain: ['group_id', 'auth_asym_id'],
  72. residue: ['group_id', 'label_entity_id', 'label_asym_id', 'label_seq_id'],
  73. auth_residue: ['group_id', 'auth_asym_id', 'auth_seq_id', 'pdbx_PDB_ins_code'],
  74. residue_range: ['group_id', 'label_entity_id', 'label_asym_id', 'beg_label_seq_id', 'end_label_seq_id'],
  75. auth_residue_range: ['group_id', 'auth_asym_id', 'beg_auth_seq_id', 'end_auth_seq_id'],
  76. atom: ['group_id', 'label_entity_id', 'label_asym_id', 'label_seq_id', 'label_atom_id', 'type_symbol', 'atom_id', 'atom_index'],
  77. auth_atom: ['group_id', 'auth_asym_id', 'auth_seq_id', 'pdbx_PDB_ins_code', 'auth_atom_id', 'type_symbol', 'atom_id', 'atom_index'],
  78. all_atomic: Object.keys(AllAtomicCifAnnotationSchema) as (keyof typeof AllAtomicCifAnnotationSchema)[],
  79. } satisfies { [schema in MVSAnnotationSchema]: (keyof typeof AllAtomicCifAnnotationSchema)[] };