Kaynağa Gözat

Issue #2: region-aware residue label

cycle20 2 yıl önce
ebeveyn
işleme
616d0983a0

+ 39 - 1
src/extensions/tmdet/labeling.ts

@@ -3,7 +3,7 @@ import { StructureElement } from '../../mol-model/structure';
 import { LociLabel, LociLabelProvider } from '../../mol-plugin-state/manager/loci-label';
 import { TmDetChainListCache, TmDetDescriptorCache } from './prop';
 import { createResidueListsPerChain, getChainAndResidueIds } from './tmdet-color-theme';
-import { getResidue } from './types';
+import { ChainList, getResidue, ResidueItem } from './types';
 
 const siteLabels = [
     "Side1",
@@ -42,9 +42,47 @@ export const TmDetLabelProvider: LociLabelProvider = {
             const residue = getResidue(chainList, chainId!, residueId!);
             if (residue) {
                 labelText = siteLabels[residue?.siteId];
+                let regionText = getRegionText(chainList, chainId!, residue);
+                labelText = `${labelText}: ${regionText}`
             }
 
         }
         return labelText;
     }
 }
+
+function getRegionText(chainList: ChainList, chainId: string, residue: ResidueItem): string {
+    let value = "Unknown region range";
+
+    const chain = chainList.filter((chain) => chain.chainId === chainId)[0];
+    if (chain) {
+        // find start of region
+        const residues = chain.residues;
+        const  authId = parseInt(residue.authId!)
+        let previous = residues[residues.length-1];
+        for (let i = residues.length-1; i > 0; i--) {
+            const current = residues[i];
+            const currentId = parseInt(current.authId!);
+            // cancel loop when siteId changes
+            if (currentId < authId && current.siteId != residue.siteId) {
+                break;
+            }
+            previous = current;
+        }
+        value = `[ ${previous.authId}`;
+
+        // find end of region
+        previous = residues[0];
+        for (let current of residues) {
+            const currentId = parseInt(current.authId!);
+            // cancel loop when siteId changes
+            if (authId < currentId && current.siteId !== residue.siteId) {
+                break;
+            }
+            previous = current;
+        }
+        value = `${value}-${previous.authId} ]`;
+    }
+
+    return value;
+}

+ 1 - 1
src/extensions/tmdet/types.ts

@@ -58,7 +58,7 @@ type StructureComponentType = StateObjectSelector<
 export type ComponentsType = { polymer: StructureComponentType; ligand: StructureComponentType; water: StructureComponentType };
 
 // for coloring and labeling
-type ResidueItem = {
+export type ResidueItem = {
     authId: string|undefined,
     siteId: number
 };