Skip to content

Commit 6cf1e09

Browse files
committed
Support for retrieving genome wide ld and exact ld added
1 parent dc6e1f2 commit 6cf1e09

File tree

10 files changed

+153
-9
lines changed

10 files changed

+153
-9
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client.datasource;
2+
3+
import com.google.gwt.core.client.JsArray;
4+
import com.google.gwt.core.client.JsArrayInteger;
5+
import com.google.gwt.core.client.JsArrayNumber;
6+
7+
public interface FetchExactLDCallback {
8+
public void onFetchExactLDValues(JsArrayInteger snps,JsArray<JsArrayNumber> r2Values,int start,int end);
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client.datasource;
2+
3+
4+
import com.google.gwt.core.client.JsArray;
5+
import com.google.gwt.core.client.JsArrayInteger;
6+
import com.google.gwt.core.client.JsArrayNumber;
7+
8+
public interface FetchLDCallback {
9+
public void onFetchLDValues(JsArrayInteger snps,JsArray<JsArrayNumber> r2Values);
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client.datasource;
2+
3+
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.impl.LDDataForSNP;
4+
5+
public interface FetchLDForSNPCallback {
6+
void onFetchLDForSNP(LDDataForSNP data);
7+
}

src/main/java/at/gmi/nordborglab/widgets/ldviewer/client/datasource/LDDataSource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33

44
public interface LDDataSource {
5-
public void fetchLDValues(String prefix,String chr, int start, int end, LDDataSourceCallback callback);
5+
public void fetchLDValues(String prefix,String chr, int start, int end, FetchLDCallback callback);
6+
public void fetchLDValuesForSNP(String prefix,String chr,int position,FetchLDForSNPCallback callback);
7+
public void fetchExactLDValues(String prefix, String chr, int position,FetchExactLDCallback callback);
68
}

src/main/java/at/gmi/nordborglab/widgets/ldviewer/client/datasource/impl/JSOLDDataSource.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package at.gmi.nordborglab.widgets.ldviewer.client.datasource.impl;
22

33
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.AbstractHTTPDataSource;
4-
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.LDDataSourceCallback;
4+
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.FetchExactLDCallback;
5+
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.FetchLDCallback;
6+
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.FetchLDForSNPCallback;
57

68
import com.google.gwt.core.client.JsonUtils;
79
import com.google.gwt.http.client.Request;
@@ -18,7 +20,7 @@ public JSOLDDataSource(String url) {
1820

1921
@Override
2022
public void fetchLDValues(String prefix,String chr, int start, int end,
21-
final LDDataSourceCallback callback) {
23+
final FetchLDCallback callback) {
2224

2325
RequestBuilder request = new RequestBuilder(RequestBuilder.GET,url+"?"+prefix+"&chr="+chr+"&start=" + start+ "&end="+ end);
2426
request.setCallback(new RequestCallback() {
@@ -46,4 +48,61 @@ public void onError(Request request, Throwable exception) {
4648

4749
}
4850

51+
@Override
52+
public void fetchLDValuesForSNP(String prefix, String chr, int position,
53+
final FetchLDForSNPCallback callback) {
54+
RequestBuilder request = new RequestBuilder(RequestBuilder.GET,url+"?"+prefix+"&chr="+chr+"&position=" + position);
55+
request.setCallback(new RequestCallback() {
56+
57+
@Override
58+
public void onResponseReceived(Request request, Response response) {
59+
if (response.getStatusCode() == Response.SC_OK) {
60+
String json = response.getText();
61+
LDDataForSNP data = JsonUtils.safeEval(json);
62+
callback.onFetchLDForSNP(data);
63+
}
64+
}
65+
66+
@Override
67+
public void onError(Request request, Throwable exception) {
68+
}
69+
});
70+
try
71+
{
72+
request.send();
73+
}
74+
catch (Exception e) {
75+
76+
}
77+
}
78+
79+
@Override
80+
public void fetchExactLDValues(String prefix, String chr, int position, final FetchExactLDCallback callback) {
81+
RequestBuilder request = new RequestBuilder(RequestBuilder.GET,url+"?"+prefix+"&chr="+chr+"&position=" + position);
82+
request.setCallback(new RequestCallback() {
83+
84+
@Override
85+
public void onResponseReceived(Request request, Response response) {
86+
if (response.getStatusCode() == Response.SC_OK) {
87+
String json = response.getText();
88+
LDData data = JsonUtils.safeEval(json);
89+
callback.onFetchExactLDValues(data.getSNPs(), data.getR2Values(),data.getStart(),data.getEnd());
90+
}
91+
}
92+
93+
@Override
94+
public void onError(Request request, Throwable exception) {
95+
}
96+
});
97+
try
98+
{
99+
request.send();
100+
}
101+
catch (Exception e) {
102+
103+
}
104+
105+
}
106+
107+
49108
}

src/main/java/at/gmi/nordborglab/widgets/ldviewer/client/datasource/impl/LDData.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ public final native JsArrayInteger getSNPs() /*-{
1818
public final native JsArray<JsArrayNumber> getR2Values() /*-{
1919
return this.r2;
2020
}-*/;
21+
22+
public final native int getStart() /*-{
23+
return this.start;
24+
}-*/;
25+
26+
public final native int getEnd() /*-{
27+
return this.end;
28+
}-*/;
2129
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client.datasource.impl;
2+
3+
import com.google.gwt.core.client.JavaScriptObject;
4+
import com.google.gwt.core.client.JsArrayInteger;
5+
import com.google.gwt.core.client.JsArrayNumber;
6+
7+
public class LDDataForChr extends JavaScriptObject {
8+
protected LDDataForChr() {
9+
}
10+
11+
public final native JsArrayInteger getSNPs() /*-{
12+
return this.snps;
13+
}-*/;
14+
15+
public final native JsArrayNumber getR2Values() /*-{
16+
return this.r2;
17+
}-*/;
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client.datasource.impl;
2+
3+
import com.google.gwt.core.client.JavaScriptObject;
4+
import com.google.gwt.core.client.JsArray;
5+
6+
public class LDDataForSNP extends JavaScriptObject{
7+
8+
protected LDDataForSNP() {}
9+
10+
public final native JsArray<LDDataForChr> getData() /*-{
11+
return this.data;
12+
}-*/;
13+
14+
}

src/main/java/at/gmi/nordborglab/widgets/ldviewer/client/datasource/impl/LDDataPoint.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public final native float getR2() /*-{
1010
return this.r2;
1111
}-*/;
1212

13+
public final native void setR2(double r2) /*-{
14+
this.r2 = r2;
15+
}-*/;
16+
17+
public final native void setPosX(int posX) /*-{
18+
this.posX = posX;
19+
}-*/;
20+
1321
public final native int getPosX() /*-{
1422
return this.posX;
1523
}-*/;
@@ -18,8 +26,12 @@ public final native int getPosY() /*-{
1826
return this.posY;
1927
}-*/;
2028

29+
public final native void setPosY(int posY) /*-{
30+
this.posY =posY;
31+
}-*/;
32+
2133
public final int getR2Color(double threshold,int maxColor) {
22-
return (int)Math.round((1 - (getR2() - 0.3)/(1-0.3))*255);
34+
return (int)Math.round((1 - (getR2() - threshold)/(1-threshold))*maxColor);
2335
}
2436

2537
}

src/main/resources/at/gmi/nordborglab/widgets/ldviewer/client/resources/LDViewer.pde

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void api_setData(int[] snps,float[][] r2,int start,int end) {
2626
void api_setSize(int width,boolean isDraw) {
2727
if (width==0)
2828
return;
29-
size(width,width/2+browser.snpPosBandHeight);
3029
browser.setSize(width,width,isDraw);
3130
}
3231

@@ -95,6 +94,7 @@ class LDBrowser {
9594
public void setSize(int width,int height,boolean isDraw) {
9695
if (this.width == width && this.height == height)
9796
return;
97+
size(width,width/2+snpPosBandHeight);
9898
console.log('setsize'+width);
9999
pg = null;
100100
pgSNPs = null;
@@ -155,7 +155,6 @@ class LDBrowser {
155155
pgSNPs = null;
156156
dataPoints = new ArrayList();
157157
filteredDataPoints = new ArrayList();
158-
159158
for (int i = 0; i <data.length ; i++) {
160159
for (int j = 0; j < data[i].length; j++) {
161160
DataPoint dataPoint = new DataPoint(0+j*separation,0+i*separation,separation,snps[j],snps[i],data[i][j]);
@@ -293,7 +292,6 @@ class LDBrowser {
293292
popMatrix();
294293
displaySnpPosBand();
295294
displayLegend();
296-
297295
}
298296

299297
private void createSNPsBand() {
@@ -412,19 +410,26 @@ class DataPoint {
412410
public void display(float threshold,float maxHue,float alpha) {
413411
noStroke();
414412
colorMode(HSB, 360, 100, 100,1);
415-
float hue = (1 - (r2 - threshold)/(1-threshold))*maxHue;
413+
float hue = calculateHue(threshold,maxHue);
416414
fill(hue,100,100,alpha);
417415
rect(x,y,separation,separation);
418416
}
419417

420418
public void createR2Boxes(float threshold,float maxHue, PGraphics pg) {
421419
pg.noStroke();
422420
pg.colorMode(HSB, 360, 100, 100,1);
423-
float hue = (1 - (r2 - threshold)/(1-threshold))*maxHue;
421+
float hue = calculateHue(threshold,maxHue);
424422
pg.fill(hue,100,100,1);
425423
pg.rect(x,y,separation,separation);
426424
}
427425

426+
private float calculateHue(float threshold,float maxHue) {
427+
float hue = (1 - (r2 - threshold)/(1-threshold))*maxHue;
428+
if (hue < 0)
429+
hue=0;
430+
return hue;
431+
}
432+
428433
public float getR2() {
429434
return r2;
430435
}

0 commit comments

Comments
 (0)