annotation.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { CustomElementProperty } from 'mol-model-props/common/custom-element-property';
  7. import { Model, ElementIndex, ResidueIndex } from 'mol-model/structure';
  8. import { Color } from 'mol-util/color';
  9. // export const StripedResidues = CustomElementProperty.create<number>({
  10. // isStatic: true,
  11. // name: 'basic-wrapper-residue-striping',
  12. // display: 'Residue Stripes',
  13. // getData(model: Model) {
  14. // const map = new Map<ElementIndex, number>();
  15. // const residueIndex = model.atomicHierarchy.residueAtomSegments.index;
  16. // for (let i = 0, _i = model.atomicHierarchy.atoms._rowCount; i < _i; i++) {
  17. // map.set(i as ElementIndex, residueIndex[i] % 2);
  18. // }
  19. // return map;
  20. // },
  21. // coloring: {
  22. // getColor(e) { return e === 0 ? Color(0xff0000) : Color(0x0000ff) },
  23. // defaultColor: Color(0x777777)
  24. // },
  25. // format(e) {
  26. // return e === 0 ? 'Odd stripe' : 'Even stripe'
  27. // }
  28. // });
  29. const EvolutionaryConservationPalette: Color[] = [
  30. [255, 255, 150], // 9
  31. [160, 37, 96],
  32. [240, 125, 171],
  33. [250, 201, 222],
  34. [252, 237, 244],
  35. [255, 255, 255],
  36. [234, 255, 255],
  37. [215, 255, 255],
  38. [140, 255, 255],
  39. [16, 200, 209] // 1
  40. ].reverse().map(([r, g, b]) => Color.fromRgb(r, g, b));
  41. export const EvolutionaryConservation = CustomElementProperty.create<number>({
  42. isStatic: true,
  43. name: 'proteopedia-wrapper-evolutionary-conservation',
  44. display: 'Evolutionary Conservation',
  45. async getData(model: Model) {
  46. const id = model.label.toLowerCase();
  47. const req = await fetch(`https://proteopedia.org/cgi-bin/cnsrf?${id}`);
  48. const json = await req.json();
  49. const annotations = (json && json.residueAnnotations) || [];
  50. const conservationMap = new Map<string, number>();
  51. for (const e of annotations) {
  52. for (const r of e.ids) {
  53. conservationMap.set(r, e.annotation);
  54. }
  55. }
  56. const map = new Map<ElementIndex, number>();
  57. const { _rowCount: residueCount } = model.atomicHierarchy.residues;
  58. const { offsets: residueOffsets } = model.atomicHierarchy.residueAtomSegments;
  59. const chainIndex = model.atomicHierarchy.chainAtomSegments.index;
  60. for (let rI = 0 as ResidueIndex; rI < residueCount; rI++) {
  61. const cI = chainIndex[residueOffsets[rI]];
  62. const key = `${model.atomicHierarchy.chains.auth_asym_id.value(cI)} ${model.atomicHierarchy.residues.auth_seq_id.value(rI)}`;
  63. if (!conservationMap.has(key)) continue;
  64. const ann = conservationMap.get(key)!;
  65. for (let aI = residueOffsets[rI]; aI < residueOffsets[aI + 1]; aI++) {
  66. map.set(aI, ann);
  67. }
  68. }
  69. return map;
  70. },
  71. coloring: {
  72. getColor(e) { return EvolutionaryConservationPalette[(e - 1) || 0]; },
  73. defaultColor: Color(0x999999)
  74. },
  75. format(e) {
  76. return e ? `Evolutionary Conservation ${e}` : void 0;
  77. }
  78. });