Skip to content
Snippets Groups Projects
Commit 544fe5f5 authored by Julian Matschinske's avatar Julian Matschinske
Browse files

Merge branch 'connect-backend' into 'master'

Connect backend

See merge request covid-19/frontend!9
parents ffa5905c bf08763b
No related branches found
No related tags found
No related merge requests found
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment';
const networkUrl = `${environment.backend}` + 'network';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
async getNetwork() {
return this.http.get(networkUrl).toPromise();
}
}
...@@ -9,6 +9,8 @@ import { AppComponent } from './app.component'; ...@@ -9,6 +9,8 @@ import { AppComponent } from './app.component';
import {ExplorerPageComponent} from './pages/explorer-page/explorer-page.component'; import {ExplorerPageComponent} from './pages/explorer-page/explorer-page.component';
import {AboutPageComponent} from './pages/about-page/about-page.component'; import {AboutPageComponent} from './pages/about-page/about-page.component';
import {HomePageComponent} from './pages/home-page/home-page.component'; import {HomePageComponent} from './pages/home-page/home-page.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -21,7 +23,8 @@ import {HomePageComponent} from './pages/home-page/home-page.component'; ...@@ -21,7 +23,8 @@ import {HomePageComponent} from './pages/home-page/home-page.component';
BrowserModule, BrowserModule,
AppRoutingModule, AppRoutingModule,
FormsModule, FormsModule,
CommonModule CommonModule,
HttpClientModule
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]
......
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import {Effect, ProteinNetwork} from '../protein-network'; import {Effect, ProteinNetwork} from '../protein-network';
import { ApiService } from '../../api.service';
declare var vis: any; declare var vis: any;
...@@ -23,14 +26,20 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -23,14 +26,20 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
public proteinData: ProteinNetwork; public proteinData: ProteinNetwork;
public proteinGroups: any;
public effects: any;
public edges: any;
private network: any; private network: any;
private nodeData: { nodes: any, edges: any } = {nodes: null, edges: null}; private nodeData: { nodes: any, edges: any } = {nodes: null, edges: null};
private networkData: any = [];
private seed = 1; // TODO: Remove this private seed = 1; // TODO: Remove this
@ViewChild('network', {static: false}) networkEl: ElementRef; @ViewChild('network', {static: false}) networkEl: ElementRef;
constructor(private route: ActivatedRoute, private router: Router) { constructor(private route: ActivatedRoute, private router: Router, private api: ApiService) {
this.groupId = 'IFI16'; this.groupId = 'IFI16';
this.geneNames.push('IFI16'); this.geneNames.push('IFI16');
this.proteinNames.push('Gamma-interface-inducible protein 16'); this.proteinNames.push('Gamma-interface-inducible protein 16');
...@@ -70,12 +79,21 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -70,12 +79,21 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
ngOnInit() { ngOnInit() {
} }
async ngAfterViewInit() { async ngAfterViewInit() {
if (!this.network) { if (!this.network) {
await this.createNetwork(); await this.createNetwork();
} }
} }
private async getNetwork() {
const data: any = await this.api.getNetwork();
this.proteinGroups = data.proteinGroups;
this.effects = data.effects;
this.edges = data.edges;
}
public zoomToNode(id: string) { public zoomToNode(id: string) {
const coords = this.network.getPositions(id)[id]; const coords = this.network.getPositions(id)[id];
this.network.moveTo({ this.network.moveTo({
...@@ -99,8 +117,8 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -99,8 +117,8 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
} }
private async createNetwork() { private async createNetwork() {
const {proteinGroups, effects, edges: proteinEdges} = await this.loadNetwork(); await this.getNetwork();
this.proteinData = new ProteinNetwork(proteinGroups, effects, proteinEdges); this.proteinData = new ProteinNetwork(this.proteinGroups, this.effects, this.edges);
this.proteinData.loadPositions(); this.proteinData.loadPositions();
this.proteinData.linkNodes(); this.proteinData.linkNodes();
...@@ -114,8 +132,6 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -114,8 +132,6 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
const {nodes, edges} = this.mapDataToNodes(this.proteinData); const {nodes, edges} = this.mapDataToNodes(this.proteinData);
console.log(nodes, edges);
this.nodeData.nodes = new vis.DataSet(nodes); this.nodeData.nodes = new vis.DataSet(nodes);
this.nodeData.edges = new vis.DataSet(edges); this.nodeData.edges = new vis.DataSet(edges);
...@@ -203,58 +219,6 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -203,58 +219,6 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
this.nodeData.nodes.add(Array.from(addNodes.values())); this.nodeData.nodes.add(Array.from(addNodes.values()));
} }
private async loadNetwork(): Promise<any> {
// TODO: Load from backend instead of generating random stuff here...
const proteinGroupCount = 10000;
const effectCount = 50;
const edgeCount = 2000;
const proteinGroups = [];
const effects = [];
const edges = [];
for (let i = 0; i < effectCount; i++) {
effects.push({
id: i,
name: `eff${i}`,
});
}
const proteinGroupIds = [];
for (let i = 0; i < edgeCount; i++) {
const proteinGroupId = Math.floor(this.random() * proteinGroupCount);
const effectId = Math.floor(this.random() * effects.length);
let found = false;
for (const edge of edges) {
if (edge.proteinGroupId === proteinGroupId && edge.effectId === effectId) {
found = true;
break;
}
}
if (!found) {
edges.push({
proteinGroupId, effectId
});
if (proteinGroupIds.indexOf(proteinGroupId) === -1) {
proteinGroupIds.push(proteinGroupId);
}
}
}
for (const proteinGroupId of proteinGroupIds) {
proteinGroups.push({
id: proteinGroupId,
name: `pg${proteinGroupId}`,
});
}
return {
proteinGroups,
effects,
edges
};
}
private mapProteinGroupToNode(proteinGroup: any): any { private mapProteinGroupToNode(proteinGroup: any): any {
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment