Skip to content

Commit 61e7603

Browse files
committed
Support for displaying genome wide ld and exact ld added
1 parent b74ab3d commit 61e7603

File tree

1 file changed

+68
-33
lines changed

1 file changed

+68
-33
lines changed

Diff for: src/main/java/at/gmi/nordborglab/widgets/gwasgeneviewer/client/GWASGeneViewer.java

+68-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.HashMap;
44
import java.util.List;
55
import java.util.Map;
6-
import java.util.logging.Logger;
76

87
import org.danvk.dygraphs.client.DygraphOptions;
98
import org.danvk.dygraphs.client.DygraphOptions.HighlightSeriesOptions;
@@ -113,6 +112,7 @@ public void execute() {
113112
protected LDDataPoint highlightedLDDataPoint = null;
114113
protected double threshold = 0.3;
115114
protected int maxColor = 255;
115+
protected boolean isNotPairWise=false;
116116

117117
//General settings
118118
protected String chromosome;
@@ -122,8 +122,6 @@ public void execute() {
122122
protected int viewStart = 0;
123123
protected int viewEnd = 0;
124124
protected HashMap<Gene, DivElement> displayGenes = new HashMap<Gene, DivElement>();
125-
126-
private static Logger logger = Logger.getLogger("at.gmi.nordborglab.widgets.gwasgeneviewer");
127125

128126
public GWASGeneViewer() {
129127
initWidget();
@@ -343,7 +341,8 @@ public void setZoom(int start, int end) {
343341

344342
public void loadLDPlot(JsArrayInteger snps,
345343
JsArray<JsArrayNumber> r2Values,int startRegion,int endRegion) {
346-
toggleGenomeViewVisible(false);
344+
setZoom(startRegion, endRegion);
345+
isNotPairWise = false;
347346
ldviewer.setVisible(true);
348347
ldviewer.onResize();
349348
ldviewer.showLDValues(snps, r2Values, startRegion, endRegion);
@@ -378,8 +377,10 @@ public void onZoom(ZoomEvent event) {
378377
ldviewer.setHighlightPosition(null);
379378
ldviewer.setVisible(false);
380379
DygraphOptions options = DygraphOptions.create();
381-
highlightedLDDataPoint = null;
382-
highlightedLDDataPoints = null;
380+
if (!isNotPairWise) {
381+
highlightedLDDataPoint = null;
382+
highlightedLDDataPoints = null;
383+
}
383384
options.setColors(color);
384385
scatterChart.getDygraphsJS().updateOptions(options);
385386
}
@@ -418,10 +419,10 @@ else if (event.maxX > viewEnd)
418419
@Override
419420
public void onHighlight(HighlightEvent event) {
420421
geneViewer.setSelectionLine(event.xVal);
421-
ldviewer.setHighlightPosition(event.xVal);
422-
highlightedLDDataPoints = getHighlightedDataPointMap();
423-
highlightedLDDataPoint = null;
424422
if (ldviewer.isVisible()) {
423+
ldviewer.setHighlightPosition(event.xVal);
424+
highlightedLDDataPoints = getHighlightedDataPointMap();
425+
highlightedLDDataPoint = null;
425426
int row = scatterChart.getDygraphsJS().getSelection();
426427
scatterChart.redraw();
427428
scatterChart.getDygraphsJS().setSelection(row, null);
@@ -434,10 +435,10 @@ public void onHighlight(HighlightEvent event) {
434435
@Override
435436
public void onUnhighlight(UnhighlightEvent event) {
436437
geneViewer.hideSelectionLine();
437-
ldviewer.setHighlightPosition(null);
438-
highlightedLDDataPoints = null;
439-
highlightedLDDataPoint = null;
440438
if (ldviewer.isVisible()) {
439+
ldviewer.setHighlightPosition(null);
440+
highlightedLDDataPoints = null;
441+
highlightedLDDataPoint = null;
441442
scatterChart.getDygraphsJS().clearSelection();
442443
scatterChart.redraw();
443444
}
@@ -458,27 +459,26 @@ protected void drawScatterChart()
458459
public void onDrawPoint(DrawPointEvent event) {
459460
event.canvas.setLineWidth(1);
460461
String color = event.color;
461-
if (ldviewer.isVisible()) {
462-
if (highlightedLDDataPoints != null) {
463-
int x = (int)scatterChart.getDygraphsJS().toDataXCoord(event.cx);
464-
LDDataPoint point = highlightedLDDataPoints.get(x);
465-
if (point != null) {
466-
int hue = point.getR2Color(threshold, maxColor);
467-
color = "rgb(255,"+hue+",0)";
468-
}
469-
else
470-
color = "blue";
462+
if (highlightedLDDataPoints != null) {
463+
int x = (int)scatterChart.getDygraphsJS().toDataXCoord(event.cx);
464+
LDDataPoint point = highlightedLDDataPoints.get(x);
465+
if (point != null) {
466+
int hue = point.getR2Color(threshold, maxColor);
467+
color = "rgb(255,"+hue+",0)";
471468
}
472-
else if (highlightedLDDataPoint != null){
473-
int x = (int)scatterChart.getDygraphsJS().toDataXCoord(event.cx);
474-
if (x == highlightedLDDataPoint.getPosX() || x == highlightedLDDataPoint.getPosY()) {
475-
int hue = highlightedLDDataPoint.getR2Color(threshold, maxColor);
476-
color = "rgb(255,"+hue+",0)";
477-
scatterChart.getDygraphsJS().drawDEFAULT(event.dygraph, event.seriesName, event.canvas, event.cx, event.cy, color, event.radius+2);
478-
return;
479-
}
469+
else
470+
color = "blue";
471+
}
472+
else if (highlightedLDDataPoint != null){
473+
int x = (int)scatterChart.getDygraphsJS().toDataXCoord(event.cx);
474+
if (x == highlightedLDDataPoint.getPosX() || x == highlightedLDDataPoint.getPosY()) {
475+
int hue = highlightedLDDataPoint.getR2Color(threshold, maxColor);
476+
color = "rgb(255,"+hue+",0)";
477+
scatterChart.getDygraphsJS().drawDEFAULT(event.dygraph, event.seriesName, event.canvas, event.cx, event.cy, color, event.radius+2);
478+
return;
480479
}
481480
}
481+
482482
scatterChart.getDygraphsJS().drawDEFAULT(event.dygraph, event.seriesName, event.canvas, event.cx, event.cy, color, event.radius);
483483
//scatterChart.getDygraphsJS().drawPLUS(event.dygraph, event.seriesName, event.canvas, event.cx, event.cy, event.color, event.radius);
484484
}
@@ -488,11 +488,19 @@ else if (highlightedLDDataPoint != null){
488488
@Override
489489
public void onDrawHighlightPoint(DrawHighlightPointEvent event) {
490490
String color = event.color;
491-
if (ldviewer.isVisible() && highlightedLDDataPoints != null) {
491+
if (highlightedLDDataPoints != null) {
492492
int x = (int)scatterChart.getDygraphsJS().toDataXCoord(event.cx);
493493
LDDataPoint point = highlightedLDDataPoints.get(x);
494494
if (point != null) {
495-
color = "rgb(255,0,0)";
495+
if (isNotPairWise) {
496+
int hue = point.getR2Color(threshold, maxColor);
497+
color = "rgb(255,"+hue+",0)";
498+
}
499+
else
500+
color = "rgb(255,0,0)";
501+
}
502+
else if (isNotPairWise) {
503+
color = "blue";
496504
}
497505
}
498506
scatterChart.getDygraphsJS().drawDEFAULT(event.dygraph, event.seriesName, event.canvas, event.cx, event.cy, color, event.radius);
@@ -592,14 +600,41 @@ private HashMap<Integer, LDDataPoint> getHighlightedDataPointMap() {
592600
HashMap<Integer, LDDataPoint> map = new HashMap<Integer, LDDataPoint>();
593601
for (int i = 0;i<dataPoints.length;i++) {
594602
LDDataPoint point = dataPoints[i];
595-
map.put(point.getPosX(), point);
603+
map.put(point.getPosX(),point);
596604
map.put(point.getPosY(),point);
597605
}
598606
return map;
599607
}
600608
return null;
601609
}
602610

611+
protected void setHighlightedDataPoints(int position,JsArrayInteger snps,JsArrayNumber r2Values) {
612+
highlightedLDDataPoints = new HashMap<Integer, LDDataPoint>();
613+
for (int i = 0; i <r2Values.length() ; i++) {
614+
LDDataPoint dataPoint = LDDataPoint.createObject().cast();
615+
dataPoint.setR2(r2Values.get(i));
616+
dataPoint.setPosX(snps.get(i));
617+
if (dataPoint.getR2() > threshold)
618+
highlightedLDDataPoints.put(dataPoint.getPosX(), dataPoint);
619+
}
620+
621+
}
622+
623+
public void showColoredLDValues(int position,JsArrayInteger snps,JsArrayNumber r2Values) {
624+
isNotPairWise = true;
625+
setHighlightedDataPoints(position, snps, r2Values);
626+
ldviewer.setVisible(false);
627+
}
628+
629+
public void hideColoredLDValues() {
630+
highlightedLDDataPoints = null;
631+
highlightedLDDataPoint = null;
632+
if (isNotPairWise) {
633+
isNotPairWise = false;
634+
refresh();
635+
}
636+
}
637+
603638
protected DygraphOptions setOptions(DygraphOptions options){
604639
double maxValue = max_value;
605640
if (maxValue < bonferroniThreshold)

0 commit comments

Comments
 (0)