From aa50e6a60f82f7f5cd6b849b19b8efbb177af49a Mon Sep 17 00:00:00 2001
From: AndiMajore <andi.majore@googlemail.com>
Date: Fri, 29 Jul 2022 09:43:37 +0200
Subject: [PATCH] made analysis on analysis result work

---
 .../analysis-panel/analysis-panel.component.ts    | 15 ++++++++++++---
 src/app/components/network/network.component.ts   |  1 -
 .../explorer-page/explorer-page.component.html    |  4 ++--
 .../explorer-page/explorer-page.component.ts      | 14 ++++++++++++++
 src/app/services/analysis/analysis.service.ts     |  7 ++++++-
 5 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/app/components/analysis-panel/analysis-panel.component.ts b/src/app/components/analysis-panel/analysis-panel.component.ts
index 27dfb2e4..0ea1547e 100644
--- a/src/app/components/analysis-panel/analysis-panel.component.ts
+++ b/src/app/components/analysis-panel/analysis-panel.component.ts
@@ -204,8 +204,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
         this.tableDrugs.forEach((r) => {
           r.rawScore = r.score;
         });
-        console.log(this.tableDrugs)
-
         this.tableProteins = nodes.filter(e => e.drugstoneId && e.drugstoneType === 'protein');
         this.tableSelectedProteins = [];
         this.tableProteins.forEach((r) => {
@@ -441,7 +439,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
         // or was found during analysis
         // FIXME connectorNodes are not visualized correctly
         nodeDetails.group = result.targetNodes && result.targetNodes.indexOf(nodeId) !== -1 ? 'foundNode' : (nodeDetails.group ? nodeDetails.group : 'connectorNode');
-        console.log(nodeDetails)
         nodeDetails.label = nodeDetails.label ? nodeDetails.label : nodeDetails[identifier];
         nodeDetails.id = nodeDetails[identifier][0] ? nodeDetails[identifier][0] : nodeDetails.id;
         this.proteins.push(nodeDetails);
@@ -478,6 +475,18 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
     };
   }
 
+  getResultNodes(){
+    if(this.nodeData && this.nodeData['nodes'])
+      return this.nodeData['nodes'].get()
+    return []
+  }
+
+  getResultEdges(){
+    if(this.nodeData && this.nodeData['edges'])
+      return this.nodeData['edges'].get().filter(e=> !e.id || !e.groupName || (typeof e.from === 'string' && typeof e.to === 'string'))
+    return []
+  }
+
   public tableProteinSelection = (e): void => {
     const oldSelection = [...this.tableSelectedProteins];
     this.tableSelectedProteins = e;
diff --git a/src/app/components/network/network.component.ts b/src/app/components/network/network.component.ts
index 477c20e5..05156fca 100644
--- a/src/app/components/network/network.component.ts
+++ b/src/app/components/network/network.component.ts
@@ -447,7 +447,6 @@ export class NetworkComponent implements OnInit {
         this.legendContext = 'drugTarget';
       }
     }
-    console.log(this.legendContext)
   }
 
   /**
diff --git a/src/app/pages/explorer-page/explorer-page.component.html b/src/app/pages/explorer-page/explorer-page.component.html
index 1922c450..e0e2e204 100644
--- a/src/app/pages/explorer-page/explorer-page.component.html
+++ b/src/app/pages/explorer-page/explorer-page.component.html
@@ -4,7 +4,7 @@
       [(show)]="showAnalysisDialog"
       [target]="analysisDialogTarget"
       [config]="drugstoneConfig.config"
-      [inputNetwork]="{ nodes: proteins, edges: edges }"
+      [inputNetwork]="{ nodes: getNodes(), edges: getEdges()}"
       (taskEvent)="emitTaskEvent($event)"
     >
     </app-launch-analysis>
@@ -721,7 +721,7 @@
       <div class="drugstone network column" id="main-column">
         <!-- analysis panel with analysis network -->
         <div class="analysis-view" *ngIf="selectedAnalysisToken">
-          <app-analysis-panel
+          <app-analysis-panel #analysisPanel
             [(token)]="selectedAnalysisToken"
             (showDetailsChange)="
               networkHandler.activeNetwork.selectedWrapper = $event
diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts
index 2b52f4c1..9deff465 100644
--- a/src/app/pages/explorer-page/explorer-page.component.ts
+++ b/src/app/pages/explorer-page/explorer-page.component.ts
@@ -538,6 +538,20 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
       'background=';
   }
 
+  @ViewChild('analysisPanel') analysisPanel;
+
+  getNodes() :any {
+    if (this.selectedAnalysisToken && this.analysisPanel)
+      return this.analysisPanel.getResultNodes()
+    return this.proteins
+  }
+
+  getEdges() :any {
+    if(this.selectedAnalysisToken && this.analysisPanel)
+      return this.analysisPanel.getResultEdges()
+    return this.edges
+  }
+
 
   emitTaskEvent(eventObject: object) {
     this.taskEvent.emit(eventObject);
diff --git a/src/app/services/analysis/analysis.service.ts b/src/app/services/analysis/analysis.service.ts
index b0d5d3c3..516a1195 100644
--- a/src/app/services/analysis/analysis.service.ts
+++ b/src/app/services/analysis/analysis.service.ts
@@ -103,6 +103,8 @@ export class AnalysisService {
   }
 
   async getTasks() {
+    if (!this.finishedTokens)
+      this.finishedTokens = []
     return await this.netex.getTasks(this.finishedTokens.length > 0 && this.tasks.length === 0 ? this.tokens : this.tokens.filter(t => this.finishedTokens.indexOf(t) === -1)).catch((e) => {
       clearInterval(this.intervalId);
     });
@@ -256,6 +258,7 @@ export class AnalysisService {
   }
 
   async startAnalysis(algorithm, target: 'drug' | 'drug-target', parameters) {
+    console.log(parameters)
     if (!this.canLaunchTask()) {
       toast({
         message: `You can only run ${MAX_TASKS} tasks at once. Please wait for one of them to finish or delete it from the task list.`,
@@ -312,7 +315,9 @@ export class AnalysisService {
 
   startWatching() {
     const watch = async () => {
-      const finished = JSON.parse(localStorage.getItem(this.tokensFinishedCookieKey));
+      let finished = JSON.parse(localStorage.getItem(this.tokensFinishedCookieKey));
+      if(!finished)
+        finished = []
       const unfinished = this.tokens.filter(t => finished.indexOf(t) === -1);
       if (unfinished.length > 0 || ! this.initialTasksLoaded) {
         this.initialTasksLoaded = true;
-- 
GitLab