-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChrDisplay.pde
150 lines (123 loc) · 5.91 KB
/
ChrDisplay.pde
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
/*
* 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/>.
*/
/**
* Class that handles the chromosome view.
*/
class ChrDisplay extends UIComponent {
boolean chr_ready = true, update = true;
PFont normFont = createFont("Arial", 12, true);
float maxOffset = -1.0, chromosomeWidth, chromosomeHeight, multiplier;
float maxLen = -1.0;
ChrOrganizer[] chrs = new ChrOrganizer[chrLengths.length];
public ChrDisplay(float newX, float newY, float newWidth, float newHeight) {
super(newX, newY, newWidth, newHeight);
for (int i = 0; i < chrs.length; i++) {
chrs[i] = new ChrOrganizer();
}
}
void update() {
chromosomeWidth = cWidth / chrColumns;
chromosomeHeight = cHeight / ceil(chrLengths.length / (float)chrColumns);
multiplier = (chromosomeHeight - 24) / max(chrLengths);
update = (ENABLE_KINECT) ? fileTree.hasUpdated() : (update || fileTree.hasUpdated());
stroke(0x00);
fill(0x00);
strokeWeight(1);
textFont(normFont);
ellipseMode(CENTER);
// draw chromosomes
drawChromosomes(this);
strokeWeight(1);
noStroke();
fill(0x00);
// clear the calculated values if the UI needs to update
if (update) {
for (ChrOrganizer co : chrs) {
co.clear();
}
}
for (int i = 0; i < parentFiles.size(); i++) {
for (int j = 0; j < ((UITreeNode)fileTree.get(i)).size(); j++) {
Phenotype currentPhenotype = ((Parent_File)parentFiles.get(i)).get(j);
UITreeNode jTreeNode = ((UITreeNode)((UITreeNode)fileTree.get(i)).get(j));
if (jTreeNode.checked) {
if (!update) {
continue;
}
// recalculate, only if updating
for (int k = 0; k < currentPhenotype.bayesintrange.length; k++) {
chrs[currentPhenotype.chr_chrs[k] - 1].add(
currentPhenotype.chr_peaks[k], // peak position in cM
currentPhenotype.bayesintrange[k], // range of values (length of colored line)
jTreeNode.drawcolor, // color of phenotype, line
x + (chromosomeWidth * ((currentPhenotype.chr_chrs[k] - 1) % chrColumns)) + 16, // x coordinate of the drawn chromosome
(multiplier * (currentPhenotype.bayesintrange[k].lower)) + y + (chromosomeHeight * floor((currentPhenotype.chr_chrs[k] - 1) / chrColumns)) + 20, // y coordinate of the drawn chromosome
multiplier * (currentPhenotype.bayesintrange[k].upper - currentPhenotype.bayesintrange[k].lower), // the length of the chromosome in pixels
(multiplier * ((currentPhenotype.chr_peaks[k] - 1))) + y + (chromosomeHeight * floor((currentPhenotype.chr_chrs[k] - 1) / chrColumns)) + 20 // the position of the peak in cM (used for sorting)
);
}
}
}
}
// draw ranges, peaks
for (int i = 0; i < chrs.length; i++) {
for (int j = 0; j < chrs[i].peaks.length; j++) {
fill(chrs[i].colors[j]);
strokeWeight(1);
stroke(chrs[i].colors[j]);
line(
(float)chrs[i].uppers[j].getX() + (8 * chrs[i].layers[j]),
(float)chrs[i].uppers[j].getY(),
(float)chrs[i].uppers[j].getX() + (8 * chrs[i].layers[j]),
(float)chrs[i].uppers[j].getY() + chrs[i].heights[j]
);
ellipse(
(float)chrs[i].uppers[j].getX() + (8 * chrs[i].layers[j]),
chrs[i].peakYs[j],
6, 6);
}
}
if (update) {
for (ChrOrganizer co : chrs) {
co.organize();
}
}
update = false;
}
void mouseAction() {
// switch to LOD view if a chromosome is selected
if (mousePressed && mouseButton == LEFT && mouseX > x && mouseX < x + cWidth && mouseY > y && mouseY < y + cHeight) {
if (floor((mouseX - x) / chromosomeWidth) + (chrColumns * floor((mouseY - y) / chromosomeHeight)) < chrLengths.length &&
floor((mouseX - x) / chromosomeWidth) + (chrColumns * floor((mouseY - y) / chromosomeHeight)) >= 0) {
int chrNum = floor((mouseX - x) / chromosomeWidth) + (chrColumns * floor((mouseY - y) / chromosomeHeight));
if (chrs[chrNum].peaks.length > 0) {
loddisplay.current_chr = chrNum;
loddisplay.zoomFactor = 1.0;
loddisplay.offset = 0.0;
updateGenes = true;
tabs.prevPage();
}
}
}
}
int size() { return 0; }
void updateOrganizer() {
}
}