UniprotPfvManagerFactory.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 {buildUniprotAlignmentFv, TagDelimiter} from "@rcsb/rcsb-saguaro-app";
  11. import {
  12. UniprotSequenceOnchangeInterface
  13. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvBuilder/RcsbFvUniprotBuilder";
  14. import {
  15. AlignmentRequestContextType
  16. } from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvFactories/RcsbFvTrackFactory/TrackFactoryImpl/AlignmentTrackFactory";
  17. import {AlignmentResponse, TargetAlignment} from "@rcsb/rcsb-api-tools/build/RcsbGraphQL/Types/Borrego/GqlTypes";
  18. import {MsaRowTitleComponent} from "./MsaPfvComponents/MsaRowTitleComponent";
  19. import {MsaRowMarkComponent} from "./MsaPfvComponents/MsaRowMarkComponent";
  20. import {SearchQuery} from "@rcsb/rcsb-api-tools/build/RcsbSearch/Types/SearchQueryInterface";
  21. interface UniprotPfvManagerInterface<R> extends PfvManagerFactoryConfigInterface<R,{context: UniprotSequenceOnchangeInterface;}> {
  22. upAcc:string;
  23. query?: SearchQuery
  24. }
  25. export class UniprotPfvManagerFactory<R> implements PfvManagerFactoryInterface<{upAcc:string},R,{context: UniprotSequenceOnchangeInterface;}> {
  26. getPfvManager(config: UniprotPfvManagerInterface<R>): PfvManagerInterface {
  27. return new UniprotPfvManager(config);
  28. }
  29. }
  30. type AlignmentDataType = {
  31. pdb:{
  32. entryId:string;
  33. entityId:string;
  34. },
  35. targetAlignment: TargetAlignment;
  36. };
  37. class UniprotPfvManager<R> extends AbstractPfvManager<{upAcc:string},R,{context: UniprotSequenceOnchangeInterface;}>{
  38. private readonly upAcc:string;
  39. private readonly config:UniprotPfvManagerInterface<R>;
  40. private module:RcsbFvModulePublicInterface;
  41. constructor(config:UniprotPfvManagerInterface<R>) {
  42. super(config);
  43. this.config = config;
  44. this.upAcc = config.upAcc;
  45. }
  46. async create(): Promise<RcsbFvModulePublicInterface | undefined> {
  47. this.module = await buildUniprotAlignmentFv(
  48. this.rcsbFvDivId,
  49. this.upAcc,
  50. this.config.query,
  51. {
  52. ... this.additionalConfig,
  53. boardConfig: this.boardConfigContainer.get(),
  54. trackConfigModifier: {
  55. alignment: (alignmentContext: AlignmentRequestContextType, targetAlignment: TargetAlignment) => new Promise((resolve)=>{
  56. resolve({
  57. rowMark:{
  58. externalRowMark: {
  59. component:MsaRowMarkComponent,
  60. props:{
  61. rowRef:TagDelimiter.parseEntity(targetAlignment.target_id!),
  62. stateManager: this.stateManager
  63. }
  64. },
  65. clickCallback:() => this.loadAlignment(alignmentContext,targetAlignment)
  66. },
  67. externalRowTitle: {
  68. rowTitleComponent:MsaRowTitleComponent,
  69. rowTitleAdditionalProps:{
  70. alignmentContext,
  71. targetAlignment,
  72. stateManager: this.stateManager,
  73. titleClick: ()=> this.loadAlignment(alignmentContext,targetAlignment)
  74. }
  75. }
  76. });
  77. })
  78. }
  79. }
  80. );
  81. this.rcsbFvContainer.set(this.module);
  82. await this.readyStateLoad();
  83. return this.module;
  84. }
  85. private async readyStateLoad(): Promise<void> {
  86. const alignments: AlignmentResponse = await this.module.getAlignmentResponse();
  87. if(alignments.target_alignment && alignments.target_alignment.length > 0 && typeof alignments.target_alignment[0]?.target_id === "string"){
  88. this.loadAlignment({queryId:this.upAcc}, alignments.target_alignment[0]);
  89. }
  90. }
  91. private loadAlignment(alignmentContext: AlignmentRequestContextType, targetAlignment: TargetAlignment):void {
  92. if(typeof targetAlignment.target_id === "string") {
  93. this.stateManager.next<"model-change",AlignmentDataType>({
  94. type:"model-change",
  95. view:"1d-view",
  96. data:{
  97. pdb:TagDelimiter.parseEntity(targetAlignment.target_id),
  98. targetAlignment
  99. }
  100. });
  101. }
  102. }
  103. }