-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQTLViewer.pde
More file actions
333 lines (279 loc) · 9.75 KB
/
QTLViewer.pde
File metadata and controls
333 lines (279 loc) · 9.75 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* Copyright (c) 2010 The Jackson Laboratory
*
* This software was developed by Matt Hibbs' Lab at The Jackson
* Laboratory (see http://cbfg.jax.org/).
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* QTL Viewer main module.
*
* This module contains methods that operate the UI, which include event handling, input prompting, etc.
*
* @author Braden Kell
* @version 22 May 2013
* @since 1.7
*/
public static final boolean ENABLE_KINECT = false; // whether or not to use Kinect
public static final boolean ENABLE_KINECT_SIMULATE = false; // simulate Kinect with the mouse
import processing.opengl.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JColorChooser;
import org.jax.mousemap.*;
import org.jax.mousemap.MouseMap.*;
import org.jax.util.datastructure.SequenceUtilities;
import SimpleOpenNI.*;
boolean exiting = false;
boolean dragReady = true, dragging = false;
boolean kinect_showmenu = false;
boolean genesLoaded = false;
boolean hasInit = false;
int chrColumns = 7;
int unitThreshold;
int mouseId = -1;
int mouseLock = -1;
long lastFrame = 0;
long lastTime;
float menuY, menuTargetY;
float legendOffsetX = -1, legendOffsetY = -1, legendBorder = 0x00;
float legendX, legendY, legendW, legendH;
float chrTotal, maxLod = -1.0, velocity = 0.1, tabsXTarget = 335.0;
int drawWidth, drawHeight;
float[] chrLengths, chrOffsets, chrMarkerpos;
String[] chrNames;
ArrayList<Parent_File> parentFiles;
ArrayList<KinectUser> users;
Gene[] genes;
PFont legendFont;
PFont large, buttonfont = createFont("Arial", 16, true);
UITree fileTree;
UIContainer texts;
UIRadioGroup unitSelect;
UITabFolder tabs;
UIButton yes, no;
UIButton loadcfg;
UIButton quit;
LODDisplay loddisplay;
ChrDisplay chrdisplay;
UIKFileBrowser filebrowser;
UIKSpinner defUpper;
UIKSpinner defLower;
UITextInput upperDefault, lowerDefault;
MouseMap unitConverter;
SimpleOpenNI context = null;
void init() {
super.init();
}
void start() {
super.start();
}
void setup() {
// set up base UI
if (ENABLE_KINECT) {
size(displayWidth, drawHeight = displayHeight); // SimpleOpenNI is apparently not compatible with OpenGL
drawWidth = (int)((4.0 / 3.0) * drawHeight);
} else {
size(drawWidth = 1600, drawHeight = 900); // use OPENGL for 4x anti-aliasing (looks better)
//hint(ENABLE_OPENGL_4X_SMOOTH); // enable OPENGL 4x AA
}
smooth(); // enable Processing 2x AA
frameRate(60);
frame.setTitle("QTL Viewer");
if (!hasInit) {
hasInit = true;
} else {
return;
}
// see InitUI for init* methods
initConstants();
initMenu();
if (ENABLE_KINECT) {
initKinect();
legendFont = createFont("Arial", 32, true);
// set up exit prompt, fonts
yes = new UIButton((drawWidth / 2.0) - 80, (drawHeight / 2.0) - 24, "Yes", 72, 48, 32, new UIAction() {
public void doAction() {
exit();
}
});
no = new UIButton((drawWidth / 2.0) + 8, (drawHeight / 2.0) - 24, "No", 72, 48, 32, new UIAction() {
public void doAction() {
exiting = false;
}
});
} else {
initMenuBar();
legendFont = createFont("Arial", 16, true);
yes = new UIButton((drawWidth / 2.0) - 40, (drawHeight / 2.0) - 24, "Yes", new UIAction() {
public void doAction() {
exit();
}
});
no = new UIButton((drawWidth / 2.0) + 8, (drawHeight / 2.0) - 24, "No", new UIAction() {
public void doAction() {
exiting = false;
}
});
}
large = createFont("Arial", (ENABLE_KINECT) ? 64 : 32, true);
textFont(large);
// set up tab container
String[] titles;
if (ENABLE_KINECT) {
titles = new String[] {
"File management", "LOD Score view", "Chromosome view", "Settings"
};
} else {
titles = new String[] {
"LOD Score view", "Chromosome view"
};
}
parentFiles = new ArrayList<Parent_File>(); // this ArrayList maps to the contents of fileTree
tabs = new UITabFolder((!ENABLE_KINECT) ? 335 : 10, 30, 10, 10, titles);
if (ENABLE_KINECT) {
fileTree = new UIKTree(tabs.cWidth - 670, tabs.y + 10, 670, tabs.cHeight - 92, new UIListener() { // remove file
public int eventHeard(int i, int j) {
parentFiles.remove(i);
return i;
}
}, new UIListener() { // remove phenotype
public int eventHeard(int i, int j) {
((Parent_File)parentFiles.get(i)).remove(j);
return j;
}
}) {
public void blockEvents() {
filebrowser.lastFrame = frameCount;
}
};
tabs.addComponent(fileTree, 0, 0);
} else {
fileTree = new UITree(10, 10, 315, drawHeight - 20, new UIListener() { // remove file
public int eventHeard(int i, int j) {
parentFiles.remove(i);
return i;
}
}, new UIListener() { // remove phenotype
public int eventHeard(int i, int j) {
((Parent_File)parentFiles.get(i)).remove(j);
return j;
}
});
}
initMouseWheelListener();
tabs.addComponent(loddisplay = new LODDisplay((!ENABLE_KINECT) ? 400 : 65, 40, 0, 0) {
public void update() {
cWidth = (drawWidth - x) - 35;
cHeight = (drawHeight - y) - 25;
plotHeight = cHeight - ((ENABLE_KINECT) ? 400 : 200);
super.update();
}
}, (ENABLE_KINECT) ? 1 : 0, 0);
if (ENABLE_KINECT) {
loddisplay.strandHeight = 50.0;
}
tabs.addComponent(chrdisplay = new ChrDisplay((!ENABLE_KINECT) ? 360 : 25, 40, 0, 0) {
public void update() {
cWidth = (drawWidth - x) - 35;
cHeight = (drawHeight - y) - 25;
super.update();
}
}, (ENABLE_KINECT) ? 2 : 1, 0);
if (ENABLE_KINECT) {
tabs.addComponent(quit = new UIButton((drawWidth / 2.0) + 8, (tabs.cHeight / 2.0) + tabs.y + 192, "Exit", 256, 128, 48, new UIAction() {
public void doAction() {
kinect_showmenu = false;
exiting = true;
}
}), 3, 0);
tabs.addComponent(defUpper = new UIKSpinner(0, 400, 48, 3.0, "Default upper threshold") {
public void update() {
this.x = (tabs.cWidth / 2.0) - getWidth() - 32 + tabs.x;
upperDefault.data = str(value);
textColor = color(0x00);
super.update();
}
}, 3, 0);
tabs.addComponent(defLower = new UIKSpinner(0, 558, 48, 1.5, "Default lower threshold") {
public void update() {
this.x = (tabs.cWidth / 2.0) - getWidth() - 32 + tabs.x;
lowerDefault.data = str(value);
textColor = color(0x00);
super.update();
}
}, 3, 0);
tabs.addComponent(unitSelect = new UIRadioGroup((tabs.cWidth / 2.0) + 32 + tabs.x, 400, 48.0, 100.0, new String[] {
"Centimorgans", "Base pairs"
}) {
public void update() {
super.textColor = color(0x00);
super.update();
}
}, 3, 0);
tabs.addComponent(new UIButton((tabs.cWidth / 2.0) - 264 + tabs.x, (tabs.cHeight / 2.0) + tabs.y + 192, "Stop Tracking", 256, 128, 36, new UIAction() {
public void doAction() {
if (!ENABLE_KINECT_SIMULATE) {
for (int i = 0; i < users.size(); i++) {
if (users.get(i).ID == mouseId) {
users.remove(i);
}
}
context.stopTrackingSkeleton(mouseId);
context.startPoseDetection("Psi", mouseId);
}
}
}), 3, 0);
tabs.addComponent(filebrowser = new UIKFileBrowser(tabs.x + 10, tabs.y + 10, tabs.cWidth - 720, tabs.cHeight - 20), 0, 0);
}
legendX = drawWidth - 400.0;
legendY = 250.0;
lastTime = System.currentTimeMillis();
}
void draw() {
background(0xAA);
// see module UpdateUI for update* methods
updateViewArea();
if (!ENABLE_KINECT) {
updateMenu();
}
updateLegend();
// display exit prompt, buttons if appropriate
if (exiting) {
noStroke();
fill(0x00, 0x00, 0x00, 0xAA);
rect(0, 0, drawWidth, drawHeight);
no.focus = true;
yes.active = true;
no.active = true;
no.update();
yes.update();
textFont(large);
fill(0xCC);
text("Exit?", (drawWidth - textWidth("Exit?")) / 2.0, (drawHeight / 2.0) - 32.0);
} else {
yes.active = false;
yes.active = false;
no.active = false;
}
if (ENABLE_KINECT) {
updateKinect();
}
}
double map(double value, double src_low, double src_high, double dest_low, double dest_high) {
return (((value - src_low) / (src_high - src_low)) * (dest_high - dest_low)) + dest_low;
}