Skip to content

Commit d1881f7

Browse files
author
Seren
committed
Selected SNPs are highlighted in the scatterplot
1 parent 8bbc3f9 commit d1881f7

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

src/at/gmi/nordborglab/widgets/gwasgeneviewer/client/GWASGeneViewer.java

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void onZoomResize(ZoomResizeEvent event) {
131131
if (clickGeneHandler != null)
132132
geneViewer.addClickGeneHandler(clickGeneHandler);
133133

134-
if (minZoomLevelForGenomeView >= (viewEnd- viewStart)) {
134+
if (minZoomLevelForGenomeView >= (viewEnd- viewStart) && (viewEnd - viewStart) > 0) {
135135
toggleGenomeViewVisible(true);
136136
geneViewer.redraw(true);
137137
}
@@ -164,6 +164,9 @@ public void draw(DataTable dataTable,double max_value, int start,int end,double
164164
geneViewer.setDataSource(datasource);
165165
geneViewer.setSize(width - DYGRAPHOFFSET, geneViewerHeight);
166166
this.drawScatterChart();
167+
if (minZoomLevelForGenomeView >= (viewEnd- viewStart)) {
168+
toggleGenomeViewVisible(true);
169+
}
167170
if (selectHandler != null)
168171
scatterChart.addSelectHandler(selectHandler);
169172
scatterChart.addZoomHandler(new ZoomHandler() {
@@ -236,15 +239,17 @@ public void onUnderlay(UnderlayEvent event) {
236239
for (int i =0;i<selections.length();i++)
237240
{
238241
Selection selection = selections.get(i);
239-
double posX = event.dygraph.toDomXCoord(dataTable.getValueInt(selection.getRow(), 0));
240-
double posY = event.dygraph.toDomYCoord(dataTable.getValueDouble(selection.getRow(), 1), 0);
241-
event.canvas.save();
242-
event.canvas.beginPath();
243-
event.canvas.setFillStyle(gene_marker_color);
244-
event.canvas.fillRect(posX-0.5, posY, 1, event.area.getH());
245-
event.canvas.arc(posX, posY, 3, 0, 2*Math.PI, false);
246-
event.canvas.fill();
247-
event.canvas.restore();
242+
if (selection != null) {
243+
double posX = event.dygraph.toDomXCoord(dataTable.getValueInt(selection.getRow(), 0));
244+
double posY = event.dygraph.toDomYCoord(dataTable.getValueDouble(selection.getRow(), 1), 0);
245+
event.canvas.save();
246+
event.canvas.beginPath();
247+
event.canvas.setFillStyle(gene_marker_color);
248+
event.canvas.fillRect(posX-0.5, posY, 1, event.area.getH());
249+
event.canvas.arc(posX, posY, 3, 0, 2*Math.PI, false);
250+
event.canvas.fill();
251+
event.canvas.restore();
252+
}
248253
}
249254

250255
if (bonferroniThreshold != -1) {
@@ -361,4 +366,43 @@ public void setSnpPosX(int snpPosX) {
361366
public void setGeneInfoUrl(String geneInfoUrl) {
362367
geneViewer.setGeneInfoUrl(geneInfoUrl);
363368
}
369+
370+
public static Selection getSelectionFromPos(DataTable data,int pos) {
371+
Selection selection = null;
372+
for (int i=0;i<data.getNumberOfRows();i++) {
373+
if (data.getValueInt(i, 0) == pos) {
374+
selection = Selection.createRowSelection(i);
375+
break;
376+
}
377+
}
378+
return selection;
379+
}
380+
381+
public void addSelection(Selection selection) {
382+
if (selection != null) {
383+
selections.set(selections.length(), selection);
384+
}
385+
}
386+
387+
public static Selection getTopSNP(DataTable data) {
388+
Selection selection = null;
389+
double top_pValue = -1;
390+
for (int i=0;i<data.getNumberOfRows();i++) {
391+
if (!data.isValueNull(i, 1))
392+
{
393+
double pValue = data.getValueDouble(i, 1);
394+
if ( pValue > top_pValue) {
395+
selection = Selection.createRowSelection(i);
396+
top_pValue = pValue;
397+
}
398+
}
399+
}
400+
return selection;
401+
}
402+
403+
public Selection getTopSNP() {
404+
if (dataTable == null)
405+
return null;
406+
return getTopSNP(dataTable);
407+
}
364408
}

0 commit comments

Comments
 (0)