Browse Source

Issue #820: refactoring: removed testing stuffs

cycle20 1 year ago
parent
commit
b37c68c325

+ 5 - 75
src/TmFv3DApp/FeatureViewConfig.ts

@@ -23,9 +23,7 @@ import {RcsbFvStateManager} from "../RcsbFvState/RcsbFvStateManager";
 import {RcsbFvStructureConfigInterface} from "../RcsbFvStructure/RcsbFvStructure";
 import {ViewerProps} from "@rcsb/rcsb-molstar/build/src/viewer";
 import { updateSiteColors } from "./tmdet-extension/tmdet-color-theme";
-import { fetchHtpDescriptor, fetchPdbtmJsvLibDescriptor, htpDescriptorToTrackData, jsvLibDescriptorToTrackData, registerRegionDescriptorData } from "./UniTmpHelper";
 import { TmDetRcsbPreset } from "./TmTrajectoryHierarchyPreset";
-import { TmDetDescriptorCache } from "./tmdet-extension/prop";
 import { TmRowTitleComponent } from "./tmdet-viewer/TmRowTitleComponent";
 
 export type TmFvConfigParams = {
@@ -42,39 +40,14 @@ export async function createFeatureViewerConfing(params: TmFvConfigParams) {
 
     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> =
-        params.fvConfigData
-        ?? {
-            rowConfig: rowConfig,
-            sequenceSelectionChangeCallback: () => {},
-            sequenceElementClickCallback: () => {},
-            sequenceHoverCallback: () => {},
-            structureSelectionCallback: () => {},
-            structureHoverCallback: () => {}
-        };
+        params.fvConfigData;
 
     fvConfig.boardId = `${params.pdbEntry}_board`;
     fvConfig.boardConfig = {
         rowTitleWidth: 190,
         includeAxis: true,
-        length: (fvConfig!.rowConfig[0]!.trackData![0].value as string).length
+        length: (fvConfig.rowConfig[0]!.trackData![0].value as string).length
     };
     setFvConfigCallbacks(fvConfig, modelId, params.labelAsymId);
 
@@ -114,54 +87,11 @@ export async function createFeatureViewerConfing(params: TmFvConfigParams) {
 
     updateSiteColors(params.side1 as any);
 
-    // TODO remove it after implementing external row title auto-config
-    if (params.fvConfigData) {
-        setExternalRowTitleComponent(fvConfig.rowConfig, structureRowClickHandler);
-    }
-
-    if (!params.fvConfigData) {
-        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));
-    
-        alignJsvLibDescriptorTrack(jsvlibDescriptor, params);
-        console.log('JSVLIB:', jsvlibDescriptor);
-        rowConfig.push(...jsvLibDescriptorToTrackData(jsvlibDescriptor));
-    }
-
-    // TODO: remove these test-data dump stmts.
-    // dumpPdbtmSampleTrack({ pdbEntry: '6bms', labelAsymId: 'A', side1: params.side1 as any });
-    // dumpPdbtmSampleTrack({ pdbEntry: '7khm', labelAsymId: 'B', side1: params.side1 as any });
+    setExternalRowTitleComponent(fvConfig.rowConfig, structureRowClickHandler);
 
     return { sequenceConfig: sequenceConfig, molstarConfig: molstarConfig };
 }
 
-function alignJsvLibDescriptorTrack(jsvlibDescriptor: any, params: any) {
-    const descriptor = TmDetDescriptorCache.get(params.pdbEntry);
-    const chain = descriptor?.chains.filter(ch => ch.chain_label == params.labelAsymId)[0];
-    const offset = parseInt(chain?.residues[0].pdb_res_label!) - 1;
-    jsvlibDescriptor.regions.forEach((region: any) => {
-        region.start += offset;
-        region.end += offset;
-    });
-}
-
-async function dumpPdbtmSampleTrack(params: { pdbEntry: string, labelAsymId: string, side1: "Inside"|"Outside"|null }) {
-    const jsvlibResponse = await fetchPdbtmJsvLibDescriptor(params.pdbEntry + '_' + params.labelAsymId);
-    await registerRegionDescriptorData(`https://pdbtm.unitmp.org/api/v1/entry/${params.pdbEntry}.json`, params.side1);
-    alignJsvLibDescriptorTrack(jsvlibResponse, params);
-    const trackData = jsvLibDescriptorToTrackData(jsvlibResponse);
-    console.log(`Sample Track of ${params.pdbEntry}_${params.labelAsymId}`);
-    console.log(JSON.stringify(trackData));
-}
-
 function setFvConfigCallbacks(fvConfig: FeatureViewInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, modelId: string, labelAsymId: string) {
     fvConfig.sequenceSelectionChangeCallback = (plugin: StructureViewerPublicInterface<LoadMolstarInterface<unknown,unknown>,LoadMolstarReturnType>, stateManager: RcsbFvStateManager, sequenceRegion: Array<RcsbFvTrackDataElementInterface>) => {
         stateManager.selectionState.clearSelection("select", {modelId: modelId, labelAsymId: labelAsymId});
@@ -218,7 +148,7 @@ function setFvConfigCallbacks(fvConfig: FeatureViewInterface<LoadMolstarInterfac
 
 }
 
-function setExternalRowTitleComponent(rows: RcsbFvRowConfigInterface[], titleClick: () => void) {
+function setExternalRowTitleComponent(rows: RcsbFvRowConfigInterface[], titleClick: (e: React.MouseEvent) => void) {
     rows.forEach(track => {
         if (track.externalRowTitle && (track.externalRowTitle.rowTitleComponent as unknown) == "TmRowTitleComponent") {
             track.externalRowTitle.rowTitleComponent = TmRowTitleComponent;
@@ -230,6 +160,6 @@ function setExternalRowTitleComponent(rows: RcsbFvRowConfigInterface[], titleCli
     });
 }
 
-function structureRowClickHandler() {
+function structureRowClickHandler(e: React.MouseEvent) {
     console.warn('TODO: implement structureRowClickHandler()');
 }

+ 0 - 85
src/TmFv3DApp/UniTmpHelper.ts

@@ -6,55 +6,17 @@
  * @author Gabor Tusnady <tusnady.gabor@ttk.hu>
  * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
  */
-import { RcsbFvDisplayTypes } from "@rcsb/rcsb-saguaro";
-
-import { getColorByLocation, getLabelByLocation } from "./UniTmpColor";
 import { PDBTMDescriptor } from "./tmdet-extension/types";
 import { setMembraneOrientation, TmDetDescriptorCache } from "./tmdet-extension/prop";
 import { createMembraneOrientation } from "./tmdet-extension/transformation";
 import { DebugUtil } from "./tmdet-extension/debug-utils";
 
-export async function fetchHtpDescriptor(entryId: string) {
-    return fetchDescriptor(`https://htp.unitmp.org/api/v1/entry/${entryId}.json`);
-}
-
-export async function fetchPdbtmJsvLibDescriptor(entryId: string) {
-    return fetchDescriptor(`https://pdbtm.unitmp.org/api/v1/jsvlib/${entryId}`);
-}
-
 export async function fetchDescriptor(url: string) {
     const response = await fetch(url);
     const descriptor = await response.json();
     return descriptor;
 }
 
-export function htpDescriptorToTrackData(descriptor: any) {
-    const tracks = [] as any[];
-
-    if (Array.isArray(descriptor.Topology.Region)) {
-        const trackData = createNewTrack('Topology', descriptor.Topology.Region, displayParamsFromHtpRegion);
-        tracks.push(trackData);
-    }
-
-    descriptor.Predictions.Prediction.forEach((prediction: any) => {
-        const trackData = createNewTrack(prediction['@attributes'].name, prediction.Region, displayParamsFromHtpRegion);
-        tracks.push(trackData);
-    });
-
-    return tracks;
-}
-
-export function jsvLibDescriptorToTrackData(descriptor: any) {
-    const tracks = [] as any[];
-
-    if (Array.isArray(descriptor.regions)) {
-        const trackData = createNewTrack(descriptor.code, descriptor.regions, displayParamsFromJsvLibRegion);
-        tracks.push(trackData);
-    }
-
-    return tracks;
-}
-
 export async function registerRegionDescriptorData(url: string, side1: "Inside"|"Outside"|null) {
     const pdbtmDescriptor: PDBTMDescriptor = await fetchDescriptor(url);
     pdbtmDescriptor.side1 = side1;
@@ -63,50 +25,3 @@ export async function registerRegionDescriptorData(url: string, side1: "Inside"|
     setMembraneOrientation(membraneOrientation);
     DebugUtil.log('TMDET Membrane Orientation Params:', membraneOrientation);
 }
-
-function createNewTrack(rowTitle: string, regions: any[], paramsConverter: (region: any) => { begin: number, end: number, location: string }) {
-    const trackData = {
-        trackHeight: 20,
-        trackColor: "#F9F9F9",
-        displayType: RcsbFvDisplayTypes.COMPOSITE,
-        rowTitle: rowTitle,
-        displayConfig: [] as any[]
-    };
-    if (!Array.isArray(regions)) {
-        return trackData;
-    }
-    regions.forEach((region: any) => {
-        trackData.displayConfig.push(createDisplayItem(paramsConverter(region)));
-    });
-
-    return trackData;
-}
-
-function createDisplayItem(params: any) {
-    return {
-        displayType: RcsbFvDisplayTypes.BLOCK,
-        displayColor: getColorByLocation(params.location),
-        displayId: `${params.begin}_${params.end}_${params.location}`,
-        displayData: [{
-            begin: params.begin,
-            end: params.end,
-            name: getLabelByLocation(params.location)
-        }]
-    };
-}
-
-function displayParamsFromHtpRegion(region: any) {
-    return {
-        begin: parseInt(region['@attributes'].from),
-        end: parseInt(region['@attributes'].to),
-        location: region['@attributes'].loc
-    };
-}
-
-function displayParamsFromJsvLibRegion(region: any) {
-    return {
-        begin: parseInt(region.start) + 1,
-        end: parseInt(region.end) + 1,
-        location: region.type
-    };
-}

+ 2 - 3
src/TmFv3DApp/tmdet-viewer/TmRowTitleComponent.tsx

@@ -12,7 +12,7 @@ import { RcsbFvRowTitleInterface } from "@rcsb/rcsb-saguaro/build/RcsbFv/RcsbFvR
 
 interface TmRowTitleInterface extends RcsbFvRowTitleInterface {
     color?: string;
-    titleClick?: () => void;
+    titleClick?: (e: React.MouseEvent) => void;
 }
 
 interface TmRowTitleState {
@@ -76,8 +76,7 @@ export class TmRowTitleComponent extends React.Component<TmRowTitleInterface, Tm
         if (!this.props.titleClick) {
             console.warn('title click handler is not set:', e);
         } else {
-            e.preventDefault();
-            this.props.titleClick!();
+            this.props.titleClick!(e);
         }
     }
 }