Quellcode durchsuchen

Issue #805: refactoring: createFeatureViewerConfing

cycle20 vor 1 Jahr
Ursprung
Commit
f823159243
2 geänderte Dateien mit 114 neuen und 115 gelöschten Zeilen
  1. 93 30
      src/examples/assembly-tm/FeatureViewConfig.ts
  2. 21 85
      src/examples/assembly-tm/index.ts

+ 93 - 30
src/examples/assembly-tm/FeatureViewConfig.ts

@@ -10,44 +10,58 @@ import {
     StructureViewerPublicInterface, SaguaroRegionList
 } from "../../RcsbFvStructure/StructureViewerInterface";
 import {
-    LoadMolstarInterface, LoadMolstarReturnType
+    LoadMethod,
+    LoadMolstarInterface,
+    LoadMolstarReturnType
 } from "../../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarActionManager";
 import {RcsbFvStateManager} from "../../RcsbFvState/RcsbFvStateManager";
 
-export const rowConfig: Array<RcsbFvRowConfigInterface> = [
-    {
-        trackId: "sequenceTrack",
-        trackHeight: 20,
-        trackColor: "#F9F9F9",
-        displayType: RcsbFvDisplayTypes.SEQUENCE,
-        nonEmptyDisplay: true,
-        rowTitle: "N/A",
-        trackData: [
-            {
-                begin: 1,
-                value: "N/A"
-            }
-        ]
-    }
-];
+import {RcsbFvStructureConfigInterface} from "../../RcsbFvStructure/RcsbFvStructure";
+import {
+    CustomViewInterface,
+    FeatureBlockInterface
+} from "../../RcsbFvSequence/SequenceViews/CustomView/CustomView";
+import {
+} from "../../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarActionManager";
+import {ViewerProps} from "@rcsb/rcsb-molstar/build/src/viewer";
+import { RcsbPreset } from "@rcsb/rcsb-molstar/build/src/viewer/helpers/preset";
+import { updateSiteColors } from "./UniTmpColor";
+import { fetchHtpDescriptor, fetchPdbtmJsvLibDescriptor, htpDescriptorToTrackData, jsvLibDescriptorToTrackData } from "./UniTmpHelper";
 
 
-export function createFeatureViewerConfing(pdbEntry: string, labelAsymId: string) {
-    const modelId = `${pdbEntry}_model`;
+export async function createFeatureViewerConfing(params: { pdbEntry: string, pdbtmEntry: string, htpEntry: string, labelAsymId: string, side1: string }) {
+    const modelId = `${params.pdbEntry}_model`;
+
+    const rowConfig: Array<RcsbFvRowConfigInterface> = [
+        {
+            trackId: "sequenceTrack",
+            trackHeight: 20,
+            trackColor: "#F9F9F9",
+            displayType: RcsbFvDisplayTypes.SEQUENCE,
+            nonEmptyDisplay: true,
+            rowTitle: "N/A",
+            trackData: [
+                {
+                    begin: 1,
+                    value: "N/A"
+                }
+            ]
+        }
+    ];
 
     const fvConfig: FeatureViewInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
-        boardId: `${pdbEntry}_board`,
+        boardId: `${params.pdbEntry}_board`,
         boardConfig: {
             rowTitleWidth: 190,
             includeAxis: true
         },
         rowConfig: rowConfig,
         sequenceSelectionChangeCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, sequenceRegion: Array<RcsbFvTrackDataElementInterface>) => {
-            stateManager.selectionState.clearSelection("select", {modelId: modelId, labelAsymId: labelAsymId});
+            stateManager.selectionState.clearSelection("select", {modelId: modelId, labelAsymId: params.labelAsymId});
             if(sequenceRegion.length > 0) {
                 const regions = sequenceRegion.map(r => ({
                     modelId: modelId,
-                    labelAsymId: labelAsymId,
+                    labelAsymId: params.labelAsymId,
                     region: {begin: r.begin, end: r.end ?? r.begin, source: "sequence"} as RegionSelectionInterface
                 }));
                 stateManager.selectionState.addSelectionFromMultipleRegions(regions, "select");
@@ -57,36 +71,35 @@ export function createFeatureViewerConfing(pdbEntry: string, labelAsymId: string
                     end: r.region.end
                 })), "select", "set");
             }else{
-                plugin.clearSelection("select", {modelId: modelId, labelAsymId: labelAsymId})
+                plugin.clearSelection("select", {modelId: modelId, labelAsymId: params.labelAsymId})
                 plugin.resetCamera();
             }
         },
         sequenceElementClickCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, d: RcsbFvTrackDataElementInterface) => {
             if(d!=null)
-                plugin.cameraFocus(modelId, "A", d.begin, d.end ?? d.begin);
+                plugin.cameraFocus(modelId, params.labelAsymId, d.begin, d.end ?? d.begin);
         },
         sequenceHoverCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, elements: Array<RcsbFvTrackDataElementInterface>) => {
-            console.log('HOEVER...', elements);
             if(elements == null || elements.length == 0)
                 plugin.clearSelection("hover");
             else {
                 const e = elements[0];
                 console.log({
                         modelId: modelId,
-                        labelAsymId: labelAsymId,
+                        labelAsymId: params.labelAsymId,
                         begin: e.begin,
                         end: e.end ?? e.begin
                 });
                 plugin.select(elements.map(e=>({
                     modelId: modelId,
-                    labelAsymId: labelAsymId,
+                    labelAsymId: params.labelAsymId,
                     begin: e.begin,
                     end: e.end ?? e.begin
                 })), "hover", "set");
             }
         },
         structureSelectionCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, pfv: RcsbFv, stateManager: RcsbFvStateManager) => {
-            const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, "A", "select");
+            const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, params.labelAsymId, "select");
             if(sel == null) {
                 pfv.clearSelection("select");
                 plugin.resetCamera();
@@ -95,12 +108,62 @@ export function createFeatureViewerConfing(pdbEntry: string, labelAsymId: string
             }
         },
         structureHoverCallback: (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, pfv: RcsbFv, stateManager: RcsbFvStateManager) => {
-            const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, "A", "hover");
+            const sel: SaguaroRegionList | undefined = stateManager.selectionState.getSelectionWithCondition(modelId, params.labelAsymId, "hover");
             if(sel == null)
                 pfv.clearSelection("hover");
             else
                 pfv.setSelection({elements:sel.regions, mode:"hover"});
         }
     }
-    return fvConfig;
+
+    const block: FeatureBlockInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
+        blockId: `${params.pdbEntry}_${params.labelAsymId}_block_id`,
+        featureViewConfig: [fvConfig]
+    };
+
+    const customConfig: CustomViewInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
+        blockConfig:[block]
+    }
+
+    const sequenceConfig = {
+        title: "UniTmp example",
+        subtitle: `HTP entry ${params.htpEntry}`,
+        config: customConfig
+    };
+
+    const molstarConfig: RcsbFvStructureConfigInterface<LoadMolstarInterface<unknown,unknown>,{viewerProps:Partial<ViewerProps>}> = {
+        loadConfig: {
+            loadMethod: LoadMethod.loadStructureFromUrl,
+            loadParams: {
+                //url: `https://pdbtm.unitmp.org/api/v1/entry/${pdbEntry}.trpdb`,
+                url: `https://www.ebi.ac.uk/pdbe/entry-files/download/${params.pdbEntry}_updated.cif`,
+                format: 'mmcif',
+                isBinary: false,
+                id: `${params.pdbEntry}_model`,
+                reprProvider: RcsbPreset
+            }
+        },
+        structureViewerConfig: {
+            viewerProps:{
+                showImportControls: true,
+                showSessionControls: false,
+            }
+        }
+    };
+
+    updateSiteColors(params.side1 as any);
+    const htpDescriptor = await fetchHtpDescriptor(params.htpEntry);
+    const jsvlibDescriptor = await fetchPdbtmJsvLibDescriptor(params.pdbtmEntry);
+
+    let sequence = htpDescriptor.Sequence.Seq;
+    sequence = sequence.replace(/\s+/g, '');
+
+    fvConfig.boardConfig.length = parseInt(htpDescriptor.Sequence['@attributes'].Length);
+    fvConfig.rowConfig[0].rowTitle = `${htpDescriptor['@attributes'].id} sequence`;
+    rowConfig[0].trackData![0].value = sequence;
+    rowConfig.push(...htpDescriptorToTrackData(htpDescriptor));
+
+    rowConfig.push(...jsvLibDescriptorToTrackData(jsvlibDescriptor));
+
+    return { sequenceConfig: sequenceConfig, molstarConfig: molstarConfig };
 }

+ 21 - 85
src/examples/assembly-tm/index.ts

@@ -1,95 +1,31 @@
-import {RcsbFv3DCustom} from "../../RcsbFv3D/RcsbFv3DCustom";
-import {RcsbFvStructureConfigInterface} from "../../RcsbFvStructure/RcsbFvStructure";
-import {
-    CustomViewInterface,
-    FeatureBlockInterface
-} from "../../RcsbFvSequence/SequenceViews/CustomView/CustomView";
-import {
-    LoadMethod,
-    LoadMolstarInterface, LoadMolstarReturnType
-} from "../../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarActionManager";
-import {ViewerProps} from "@rcsb/rcsb-molstar/build/src/viewer";
-
-import {
-    fetchHtpDescriptor,
-    fetchPdbtmJsvLibDescriptor,
-    htpDescriptorToTrackData,
-    jsvLibDescriptorToTrackData
-} from "./UniTmpHelper";
-import { updateSiteColors } from "./UniTmpColor";
-import { createFeatureViewerConfing, rowConfig } from "./FeatureViewConfig";
-import { RcsbPreset } from "@rcsb/rcsb-molstar/build/src/viewer/helpers/preset";
-
-const side1 = "Inside";
-const htpEntry = "GLPA_HUMAN";
-const pdbEntry = "1afo";
-const labelAsymId = "B"
-const pdbtmEntry = `${pdbEntry}_${labelAsymId}`;
-
-
-
-
-const fvConfig = createFeatureViewerConfing(pdbEntry, labelAsymId);
-const block: FeatureBlockInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
-    blockId:"MyBlock_1",
-    featureViewConfig: [fvConfig]
-};
-
-const customConfig: CustomViewInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType> = {
-    blockConfig:[block]
-}
-
-const sequenceConfig = {
-    title: "UniTmp example",
-    subtitle: `HTP entry ${htpEntry}`,
-    config: customConfig
-};
-
-const molstarConfig: RcsbFvStructureConfigInterface<LoadMolstarInterface<unknown,unknown>,{viewerProps:Partial<ViewerProps>}> = {
-    loadConfig: {
-        loadMethod: LoadMethod.loadStructureFromUrl,
-        loadParams: {
-            //url: `https://pdbtm.unitmp.org/api/v1/entry/${pdbEntry}.trpdb`,
-            url: `https://www.ebi.ac.uk/pdbe/entry-files/download/${pdbEntry}_updated.cif`,
-            format: 'mmcif',
-            isBinary: false,
-            id: `${pdbEntry}_model`,
-            reprProvider: RcsbPreset
-        }
-    },
-    structureViewerConfig: {
-        viewerProps:{
-            showImportControls: true,
-            showSessionControls: false,
-            //extensions: 
-        }
-    }
-};
+import {RcsbFv3DCustom, RcsbFv3DCustomInterface} from "../../RcsbFv3D/RcsbFv3DCustom";
+import { DebugUtil } from "@rcsb/rcsb-molstar/build/src/tmdet-extension/debug-utils";
+import { createFeatureViewerConfing } from "./FeatureViewConfig";
 
 document.addEventListener("DOMContentLoaded", (event) => {
     (async function(event) {
-        updateSiteColors(side1);
-        const htpDescriptor = await fetchHtpDescriptor(htpEntry);
-        const jsvlibDescriptor = await fetchPdbtmJsvLibDescriptor(pdbtmEntry);
-
-        console.log(htpDescriptor);
 
-        let sequence = htpDescriptor.Sequence.Seq;
-        sequence = sequence.replace(/\s+/g, '');
+        DebugUtil.enableLog();
 
-        fvConfig.boardConfig.length = parseInt(htpDescriptor.Sequence['@attributes'].Length);
-        fvConfig.rowConfig[0].rowTitle = `${htpDescriptor['@attributes'].id} sequence`;
-        rowConfig[0].trackData![0].value = sequence;
-        rowConfig.push(...htpDescriptorToTrackData(htpDescriptor));
+        const pdbEntry = "1afo";
+        const labelAsymId = "B";
+        const params = {
+            side1: "Inside",
+            htpEntry: "GLPA_HUMAN",
+            pdbEntry: pdbEntry,
+            labelAsymId: labelAsymId,
+            pdbtmEntry: `${pdbEntry}_${labelAsymId}`
+        };
 
-        rowConfig.push(...jsvLibDescriptorToTrackData(jsvlibDescriptor));
-
-
-        const panel3d = new RcsbFv3DCustom({
+        const { sequenceConfig, molstarConfig } = await createFeatureViewerConfing(params);
+        const panel3dConfig: RcsbFv3DCustomInterface = {
             elementId: "null",
-            structurePanelConfig: molstarConfig,
-            sequencePanelConfig: sequenceConfig
-        });
+            sequencePanelConfig: sequenceConfig,
+            structurePanelConfig: molstarConfig
+        };
+        DebugUtil.log(panel3dConfig);
+
+        const panel3d = new RcsbFv3DCustom(panel3dConfig);
         panel3d.render();
     })();
 });