-
Notifications
You must be signed in to change notification settings - Fork 2
/
circularGenome.tsx
155 lines (133 loc) · 4.87 KB
/
circularGenome.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as React from "react";
import {CircularFigure, assembleCompilableTemplates, buildBaseFigureTemplate, assembleCompilableCoverageTrack} from "../../circularFigure/circularFigure";
import {Plasmid} from "../../../ngplasmid/lib/plasmid";
import {Node, loadFromString} from "../../../ngplasmid/lib/html";
import {Layer} from "./layer";
export interface CircularGenomeState
{
plasmidCache : Array<{uuid : string,plasmid : Plasmid}>;
}
export interface CircularGenomeProps
{
figure : CircularFigure;
width : number;
height : number;
x : number;
y : number;
}
export class CircularGenome extends React.Component<CircularGenomeProps,CircularGenomeState>
{
public constructor(props : CircularGenomeProps)
{
super(props);
this.state = {
plasmidCache : []
};
this.loadPlasmid = this.loadPlasmid.bind(this);
this.updateCanvas = this.updateCanvas.bind(this);
this.componentDidMount = this.componentDidMount.bind(this);
this.componentDidUpdate = this.componentDidUpdate.bind(this);
}
public async loadPlasmid(target : string) : Promise<{uuid : string,plasmid : Plasmid} | undefined>
{
let scope = {genome : this.props.figure};
if(target == this.props.figure.uuid)
{
console.log("Loading base figure");
console.log(this.props.figure.name);
let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;
let nodes : Array<Node> = await loadFromString(
assembleCompilableTemplates(this.props.figure,
buildBaseFigureTemplate(this.props.figure)
)
);
for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
return {
uuid : this.props.figure.uuid,
plasmid : plasmid
};
}
}
}
}
}
else
{
let coverageTrack = this.props.figure.renderedCoverageTracks.find((x) => x.uuid == target);
if(coverageTrack)
{
console.log("Rendering coverage track "+target);
let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;
let nodes : Array<Node> = await loadFromString(assembleCompilableCoverageTrack(this.props.figure,coverageTrack));
for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
this.setState({
plasmidCache : [
...this.state.plasmidCache,
{
uuid : target,
plasmid : plasmid
}
]
});
}
}
}
}
}
}
return undefined;
}
public updateCanvas()
{
}
public componentDidMount()
{
this.updateCanvas();
}
public componentDidUpdate(prevProps : Readonly<CircularGenomeProps>,prevState : Readonly<CircularGenomeState>)
{
this.updateCanvas();
}
public render() : JSX.Element
{
return (
<React.Fragment>
{
this.props.figure.visibleLayers.map((layer) =>
{
return (
<Layer
plasmidCache={this.state.plasmidCache}
figure={this.props.figure}
target={layer}
loadPlasmid={this.loadPlasmid}
width={this.props.width}
height={this.props.height}
x={this.props.x}
y={this.props.y}
/>
);
})
}
</React.Fragment>
);
}
}