UniprotPfvManagerFactory.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {
  2. AbstractPfvManager,
  3. PfvManagerFactoryConfigInterface,
  4. PfvManagerInterface,
  5. PfvManagerFactoryInterface
  6. } from "../PfvManagerFactoryInterface";
  7. import {
  8. RcsbFvModulePublicInterface
  9. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvModule/RcsbFvModuleInterface";
  10. import {buildMultipleAlignmentSequenceFv, TagDelimiter} from "@rcsb/rcsb-saguaro-app";
  11. import {RcsbFvDOMConstants} from "../../../../RcsbFvConstants/RcsbFvConstants";
  12. import {
  13. UniprotSequenceOnchangeInterface
  14. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvBuilder/RcsbFvUniprotBuilder";
  15. import {
  16. AlignmentRequestContextType
  17. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvFactories/RcsbFvTrackFactory/TrackFactoryImpl/AlignmentTrackFactory";
  18. import {AlignmentResponse, TargetAlignment} from "@rcsb/rcsb-api-tools/build/RcsbGraphQL/Types/Borrego/GqlTypes";
  19. import {StructureLoaderInterface} from "../../../../RcsbFvStructure/StructureUtils/StructureLoaderInterface";
  20. import {
  21. ViewerActionManagerInterface,
  22. ViewerCallbackManagerInterface
  23. } from "../../../../RcsbFvStructure/StructureViewerInterface";
  24. import {UniprotRowMarkComponent} from "./UniprotPfvManagerFactory/UniprotRowMarkComponent";
  25. interface UniprotPfvManagerInterface<R> extends PfvManagerFactoryConfigInterface<R,{context: UniprotSequenceOnchangeInterface;}> {
  26. upAcc:string;
  27. }
  28. export class UniprotPfvManagerFactory<R> implements PfvManagerFactoryInterface<{upAcc:string},R,{context: UniprotSequenceOnchangeInterface;}> {
  29. private readonly structureLoader: StructureLoaderInterface<[ViewerCallbackManagerInterface & ViewerActionManagerInterface <R>,{entryId:string;entityId:string;},{entryId:string;entityId:string;}]>;
  30. constructor(config: {
  31. structureLoader: StructureLoaderInterface<[ViewerCallbackManagerInterface & ViewerActionManagerInterface <R>,{entryId:string;entityId:string;},{entryId:string;entityId:string;}]>
  32. }) {
  33. this.structureLoader = config.structureLoader;
  34. }
  35. getPfvManager(config: UniprotPfvManagerInterface<R>): PfvManagerInterface {
  36. return new UniprotPfvManager({
  37. ...config,
  38. structureLoader:this.structureLoader
  39. });
  40. }
  41. }
  42. class UniprotPfvManager<R> extends AbstractPfvManager<{upAcc:string},R,{context: UniprotSequenceOnchangeInterface;}>{
  43. private readonly upAcc:string;
  44. private readonly structureLoader: StructureLoaderInterface<[ViewerCallbackManagerInterface & ViewerActionManagerInterface <R>,{entryId:string;entityId:string;},{entryId:string;entityId:string;}]>;
  45. private module:RcsbFvModulePublicInterface;
  46. private structureRef: {entryId:string;entityId:string;};
  47. constructor(config:UniprotPfvManagerInterface<R> & {
  48. structureLoader: StructureLoaderInterface<[ViewerCallbackManagerInterface & ViewerActionManagerInterface <R>,{entryId:string;entityId:string;},{entryId:string;entityId:string;}]>
  49. }) {
  50. super(config);
  51. this.upAcc = config.upAcc;
  52. this.structureLoader = config.structureLoader;
  53. }
  54. async create(): Promise<RcsbFvModulePublicInterface | undefined> {
  55. this.module = await buildMultipleAlignmentSequenceFv(
  56. this.rcsbFvDivId,
  57. RcsbFvDOMConstants.SELECT_BUTTON_PFV_ID,
  58. this.upAcc,
  59. {
  60. onChangeCallback:(context,module)=>{
  61. this.pfvChangeCallback({context});
  62. }
  63. },{
  64. ... this.additionalConfig,
  65. trackConfigModifier: {
  66. alignment: (alignmentContext: AlignmentRequestContextType, targetAlignment: TargetAlignment) => new Promise((resolve)=>{
  67. resolve({
  68. rowMark:{
  69. externalComponent: UniprotRowMarkComponent,
  70. clickCallback:()=>{
  71. this.loadAlignment(alignmentContext,targetAlignment);
  72. }
  73. }
  74. });
  75. })
  76. }
  77. }
  78. );
  79. this.rcsbFvContainer.set(this.module);
  80. await this.readyStateLoad();
  81. return this.module;
  82. }
  83. private async readyStateLoad(): Promise<void> {
  84. const alignments: AlignmentResponse = await this.module.getAlignmentResponse();
  85. if(alignments.target_alignment && alignments.target_alignment.length > 0 && typeof alignments.target_alignment[0]?.target_id === "string"){
  86. this.structureRef = TagDelimiter.parseEntity(alignments.target_alignment[0]?.target_id);
  87. await this.loadAlignment({queryId:this.upAcc}, alignments.target_alignment[0]);
  88. }
  89. }
  90. private async loadAlignment(alignmentContext: AlignmentRequestContextType, targetAlignment: TargetAlignment): Promise<void> {
  91. if(typeof targetAlignment.target_id === "string") {
  92. await this.structureLoader.load(this.structureViewer,this.structureRef,TagDelimiter.parseEntity(targetAlignment.target_id));
  93. }
  94. }
  95. }