FeatureViewConfig.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { FeatureViewInterface } from "../../RcsbFvSequence/SequenceViews/CustomView/CustomView";
  2. import {
  3. RcsbFv,
  4. RcsbFvDisplayTypes,
  5. RcsbFvRowConfigInterface,
  6. RcsbFvTrackDataElementInterface
  7. } from "@rcsb/rcsb-saguaro";
  8. import { RegionSelectionInterface } from "../../RcsbFvState/RcsbFvSelectorManager";
  9. import {
  10. StructureViewerPublicInterface, SaguaroRegionList
  11. } from "../../RcsbFvStructure/StructureViewerInterface";
  12. import {
  13. LoadMolstarInterface, LoadMolstarReturnType
  14. } from "../../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarActionManager";
  15. import {RcsbFvStateManager} from "../../RcsbFvState/RcsbFvStateManager";
  16. export const rowConfig: Array<RcsbFvRowConfigInterface> = [
  17. {
  18. trackId: "sequenceTrack",
  19. trackHeight: 20,
  20. trackColor: "#F9F9F9",
  21. displayType: RcsbFvDisplayTypes.SEQUENCE,
  22. nonEmptyDisplay: true,
  23. rowTitle: "N/A",
  24. trackData: [
  25. {
  26. begin: 1,
  27. value: "N/A"
  28. }
  29. ]
  30. }
  31. ];
  32. export function createFeatureViewerConfing(pdbEntry: string, labelAsymId: string) {
  33. const modelId = `${pdbEntry}_model`;
  34. const fvConfig: FeatureViewInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
  35. boardId: `${pdbEntry}_board`,
  36. boardConfig: {
  37. rowTitleWidth: 190,
  38. includeAxis: true
  39. },
  40. rowConfig: rowConfig,
  41. sequenceSelectionChangeCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, sequenceRegion: Array<RcsbFvTrackDataElementInterface>) => {
  42. stateManager.selectionState.clearSelection("select", {modelId: modelId, labelAsymId: labelAsymId});
  43. if(sequenceRegion.length > 0) {
  44. const regions = sequenceRegion.map(r => ({
  45. modelId: modelId,
  46. labelAsymId: labelAsymId,
  47. region: {begin: r.begin, end: r.end ?? r.begin, source: "sequence"} as RegionSelectionInterface
  48. }));
  49. stateManager.selectionState.addSelectionFromMultipleRegions(regions, "select");
  50. plugin.select(regions.map(r => ({
  51. ...r,
  52. begin: r.region.begin,
  53. end: r.region.end
  54. })), "select", "set");
  55. }else{
  56. plugin.clearSelection("select", {modelId: modelId, labelAsymId: labelAsymId})
  57. plugin.resetCamera();
  58. }
  59. },
  60. sequenceElementClickCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, d: RcsbFvTrackDataElementInterface) => {
  61. if(d!=null)
  62. plugin.cameraFocus(modelId, "A", d.begin, d.end ?? d.begin);
  63. },
  64. sequenceHoverCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, elements: Array<RcsbFvTrackDataElementInterface>) => {
  65. console.log('HOEVER...', elements);
  66. if(elements == null || elements.length == 0)
  67. plugin.clearSelection("hover");
  68. else {
  69. const e = elements[0];
  70. console.log({
  71. modelId: modelId,
  72. labelAsymId: labelAsymId,
  73. begin: e.begin,
  74. end: e.end ?? e.begin
  75. });
  76. plugin.select(elements.map(e=>({
  77. modelId: modelId,
  78. labelAsymId: labelAsymId,
  79. begin: e.begin,
  80. end: e.end ?? e.begin
  81. })), "hover", "set");
  82. }
  83. },
  84. structureSelectionCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, pfv: RcsbFv, stateManager: RcsbFvStateManager) => {
  85. const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, "A", "select");
  86. if(sel == null) {
  87. pfv.clearSelection("select");
  88. plugin.resetCamera();
  89. }else {
  90. pfv.setSelection({elements: sel.regions, mode: "select"});
  91. }
  92. },
  93. structureHoverCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, pfv: RcsbFv, stateManager: RcsbFvStateManager) => {
  94. const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, "A", "hover");
  95. if(sel == null)
  96. pfv.clearSelection("hover");
  97. else
  98. pfv.setSelection({elements:sel.regions, mode:"hover"});
  99. }
  100. }
  101. return fvConfig;
  102. }