Skip to content

Commit 1d63bdf

Browse files
committed
Initial Checkin
0 parents  commit 1d63bdf

24 files changed

+1416
-0
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
June 11, 2011 - Release 0.1.0
2+
3+
* Initial version

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2011 by Ümit Seren
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
LDViewer - 0.1.0
2+
a GWT Widget for visualization of LD plots.
3+
4+
//////////////////////////////////////////////////////////////////////////////
5+
6+
License MIT (see included LICENSE)
7+
Original Author Ümit Seren
8+
9+
10+
Web Site -
11+
Github Repo. https://github.com/timeu/LDViewer
12+
Bug Tracking -
13+
Test Suite -
14+
15+
16+
//////////////////////////////////////////////////////////////////////////////
17+
18+
ACKNOWLEDGMENT & THIRD PARTY LIBRARIES
19+
20+
- processing.js by John Resig (http://processingjs.org)
21+
- Google Web Toolkit (GWT) by Google (http://code.google.com/webtoolkit/)
22+
//////////////////////////////////////////////////////////////////////////////
23+
24+
INTRODUCTION
25+
26+
LDViewer is a simple Google Web Toolkit (GWT) widget for visualization of LD plots (Heatmap)
27+
28+
29+
30+
//////////////////////////////////////////////////////////////////////////////
31+
32+
PLATFORM AND BROWSER COMPATIBILITY
33+
34+
The LDViewer widget uses processing.js to visualize the LD plots.
35+
Both widgets rely on the HTML5 canvas element. For browser compatiblity refer to
36+
the documentation of both libraries.
37+
38+
In general this widget works with browser that support the HTML5 canvas element.
39+
In case of Microsoft's IE this only applies to the Internet Explorer 9.0
40+
41+
//////////////////////////////////////////////////////////////////////////////
42+
43+
USAGE
44+
45+
to be written
46+
47+
//////////////////////////////////////////////////////////////////////////////

pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>superpom</artifactId>
7+
<groupId>at.gmi.nordborglab</groupId>
8+
<version>0.1</version>
9+
</parent>
10+
<groupId>at.gmi.nordborglab.widgets</groupId>
11+
<artifactId>ldviewer</artifactId>
12+
<version>0.1.0-SNAPSHOT</version>
13+
<name>ldviewer</name>
14+
<url>http://maven.apache.org</url>
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
18+
<gwtVersion>2.4.0</gwtVersion>
19+
<github.maven.repository>file:///srv/uemit.seren/repository/maven-repository/</github.maven.repository>
20+
</properties>
21+
<repositories>
22+
<repository>
23+
<id>nordborglab-snapshots</id>
24+
<url>https://github.com/timeu/maven-repos/raw/master/snapshots/</url>
25+
</repository>
26+
</repositories>
27+
<dependencies>
28+
<dependency>
29+
<groupId>junit</groupId>
30+
<artifactId>junit</artifactId>
31+
<version>3.8.1</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.google.gwt</groupId>
36+
<artifactId>gwt-user</artifactId>
37+
<version>${gwtVersion}</version>
38+
<scope>provided</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>at.gmi.nordborglab</groupId>
42+
<artifactId>processingjs</artifactId>
43+
<version>0.6.0</version>
44+
</dependency>
45+
</dependencies>
46+
<distributionManagement>
47+
<repository>
48+
<id>repo</id>
49+
<url>${github.maven.repository}/releases/</url>
50+
</repository>
51+
<snapshotRepository>
52+
<id>snapshot-repo</id>
53+
<url>${github.maven.repository}/snapshots/</url>
54+
</snapshotRepository>
55+
</distributionManagement>
56+
<organization>
57+
<name>GMI</name>
58+
<url>http://www.gmi.oeaw.ac.at</url>
59+
</organization>
60+
<build>
61+
<resources>
62+
<resource>
63+
<directory>src/main/java</directory>
64+
</resource>
65+
<resource>
66+
<directory>src/main/resources</directory>
67+
</resource>
68+
</resources>
69+
</build>
70+
<scm>
71+
<url>https://timeu@github.com/timeu</url>
72+
<connection>scm:git:https://timeu@github.com/timeu/LDViewer.git</connection>
73+
<developerConnection>scm:git:https://timeu@github.com/timeu/LDViewer.git</developerConnection>
74+
</scm>
75+
</project>
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
package at.gmi.nordborglab.widgets.ldviewer.client;
2+
3+
4+
import at.gmi.nordborglab.processingjs.client.Processing;
5+
import at.gmi.nordborglab.widgets.ldviewer.client.datasource.impl.LDDataPoint;
6+
import at.gmi.nordborglab.widgets.ldviewer.client.event.HasHighlightLDHandlers;
7+
import at.gmi.nordborglab.widgets.ldviewer.client.event.HasMiddleMouseClickHandlers;
8+
import at.gmi.nordborglab.widgets.ldviewer.client.event.HasUnhighlightLDHandlers;
9+
import at.gmi.nordborglab.widgets.ldviewer.client.event.HighlightLDEvent;
10+
import at.gmi.nordborglab.widgets.ldviewer.client.event.HighlightLDHandler;
11+
import at.gmi.nordborglab.widgets.ldviewer.client.event.MiddleMouseClickEvent;
12+
import at.gmi.nordborglab.widgets.ldviewer.client.event.MiddleMouseClickHandler;
13+
import at.gmi.nordborglab.widgets.ldviewer.client.event.UnhighlightLDEvent;
14+
import at.gmi.nordborglab.widgets.ldviewer.client.event.UnhighlightLDHandler;
15+
16+
import com.google.gwt.core.client.GWT;
17+
import com.google.gwt.core.client.JsArray;
18+
import com.google.gwt.core.client.JsArrayInteger;
19+
import com.google.gwt.core.client.JsArrayNumber;
20+
import com.google.gwt.core.client.Scheduler;
21+
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
22+
import com.google.gwt.event.shared.GwtEvent;
23+
import com.google.gwt.resources.client.ClientBundle;
24+
import com.google.gwt.resources.client.ExternalTextResource;
25+
import com.google.gwt.resources.client.ResourceException;
26+
import com.google.gwt.uibinder.client.UiBinder;
27+
import com.google.gwt.uibinder.client.UiField;
28+
import com.google.gwt.user.client.ui.Composite;
29+
import com.google.gwt.user.client.ui.RequiresResize;
30+
import com.google.gwt.user.client.ui.Widget;
31+
import com.google.web.bindery.event.shared.HandlerRegistration;
32+
33+
public class LDViewer extends Composite implements RequiresResize,
34+
HasUnhighlightLDHandlers,HasHighlightLDHandlers,
35+
HasMiddleMouseClickHandlers{
36+
37+
private static LDViewerUiBinder uiBinder = GWT
38+
.create(LDViewerUiBinder.class);
39+
40+
interface LDViewerUiBinder extends UiBinder<Widget, LDViewer> {
41+
}
42+
interface Resources extends ClientBundle
43+
{
44+
Resources INSTANCE = GWT.create(Resources.class);
45+
@Source("resources/LDViewer.pde")
46+
ExternalTextResource getCode();
47+
}
48+
49+
@UiField Processing<LDViewerInstance> processing;
50+
51+
private int start;
52+
private int end;
53+
private int zoomStart;
54+
private int zoomEnd;
55+
private int width=1024;
56+
private JsArrayInteger snps;
57+
private JsArray<JsArrayNumber> r2Values;
58+
59+
private final ScheduledCommand layoutCmd = new ScheduledCommand() {
60+
public void execute() {
61+
layoutScheduled = false;
62+
forceLayout();
63+
}
64+
};
65+
private boolean layoutScheduled = false;
66+
67+
public LDViewer() {
68+
initWidget(uiBinder.createAndBindUi(this));
69+
}
70+
71+
public void load(final Runnable onLoad) throws ResourceException {
72+
Runnable onLoadCode = new Runnable()
73+
{
74+
@Override
75+
public void run() {
76+
if (!processing.isLoaded())
77+
return;
78+
processing.getInstance().setLayoutSize(getElement().getClientWidth(), false);
79+
if (onLoad != null)
80+
onLoad.run();
81+
}
82+
};
83+
processing.load(Resources.INSTANCE.getCode(), onLoadCode);
84+
}
85+
86+
87+
public void showLDValues(JsArrayInteger SNPs,JsArray<JsArrayNumber> r2Values,int start, int end) {
88+
this.snps = SNPs;
89+
this.r2Values = r2Values;
90+
this.start = start;
91+
this.end = end;
92+
this.zoomStart = start;
93+
this.zoomEnd = end;
94+
showPlot();
95+
}
96+
97+
public void setZoom(int start, int end) {
98+
zoomStart = zoomStart >= start ? zoomStart : start;
99+
zoomEnd = zoomEnd <= end ? zoomEnd :end;
100+
showPlot();
101+
}
102+
103+
public int getZoomStart() {
104+
return zoomStart;
105+
}
106+
107+
public int getZoomEnd() {
108+
return zoomEnd;
109+
}
110+
111+
public void resetZoom() {
112+
zoomStart = start;
113+
zoomEnd = end;
114+
showPlot();
115+
}
116+
117+
private void showPlot() {
118+
if (!processing.isLoaded())
119+
return;
120+
int[] indices = getFilteredIndices(snps);
121+
processing.getInstance().setData(filterSNPs(snps,indices),filterR2Values(r2Values,indices),zoomStart,zoomEnd);
122+
}
123+
124+
private JsArray<JsArrayNumber> filterR2Values(JsArray<JsArrayNumber> r2Values,int[] indices) {
125+
if (zoomStart == start && zoomEnd == end)
126+
return r2Values;
127+
JsArray<JsArrayNumber> filtered = JsArray.createArray().cast();
128+
for (int i = indices[0];i<indices[1];i++) {
129+
JsArrayNumber r2vals = r2Values.get(i);
130+
JsArrayNumber filteredR2Vals = JsArrayNumber.createArray().cast();
131+
for (int j=indices[0];j<r2vals.length();j++) {
132+
filteredR2Vals.push(r2vals.get(j));
133+
}
134+
filtered.push(filteredR2Vals);
135+
}
136+
return filtered;
137+
}
138+
139+
private int[] getFilteredIndices(JsArrayInteger snps) {
140+
int[] indices = new int[2];
141+
indices[0] = 0;
142+
indices[1] = snps.length();
143+
if (zoomStart == start && zoomEnd == end) {
144+
return indices;
145+
}
146+
for (int i = 0;i<snps.length();i++)
147+
{
148+
if (zoomStart > start && indices[0] == 0 && snps.get(i) > zoomStart)
149+
indices[0] = i;
150+
if (zoomEnd < end && indices[1] == snps.length() && snps.get(i) > zoomEnd)
151+
indices[1] = i;
152+
}
153+
return indices;
154+
}
155+
156+
private JsArrayInteger filterSNPs(JsArrayInteger snps,int[] indices) {
157+
if (zoomStart == start && zoomEnd == end)
158+
return snps;
159+
JsArrayInteger filtered = JsArrayInteger.createArray().cast();
160+
for (int i = indices[0];i<indices[1];i++) {
161+
filtered.push(snps.get(i));
162+
}
163+
return filtered;
164+
}
165+
166+
public boolean isDataValid(int zoomStart,int zoomEnd) {
167+
return zoomStart >= start && zoomEnd < end;
168+
}
169+
170+
public void forceLayout() {
171+
if (!isAttached())
172+
return;
173+
width = getElement().getClientWidth();
174+
if (processing.isLoaded()) {
175+
processing.getInstance().setLayoutSize(width,isVisible());
176+
}
177+
}
178+
179+
private void scheduledLayout() {
180+
if (isAttached() && !layoutScheduled) {
181+
layoutScheduled = true;
182+
Scheduler.get().scheduleDeferred(layoutCmd);
183+
}
184+
}
185+
186+
@Override
187+
public void onResize() {
188+
scheduledLayout();
189+
}
190+
191+
public void setHighlightPosition(Integer position) {
192+
if (!processing.isLoaded())
193+
return;
194+
processing.getInstance().setHighlightPosition(position);
195+
}
196+
197+
@Override
198+
public HandlerRegistration addHighlightLDHandler(HighlightLDHandler handler) {
199+
sinkEvents(HighlightLDEvent.getType());
200+
return addHandler(handler, HighlightLDEvent.getType());
201+
}
202+
203+
@Override
204+
public HandlerRegistration addUnhighlightHandler(
205+
UnhighlightLDHandler handler) {
206+
sinkEvents(UnhighlightLDEvent.getType());
207+
return addHandler(handler, UnhighlightLDEvent.getType());
208+
}
209+
210+
protected final void sinkEvents(GwtEvent.Type<?> type) {
211+
String callback = "";
212+
if (type == HighlightLDEvent.getType())
213+
callback = "highlightEvent";
214+
else if (type == UnhighlightLDEvent.getType())
215+
callback = "unhighlightEvent";
216+
else if (type == MiddleMouseClickEvent.getType())
217+
callback = "middleMouseClickEvent";
218+
processing.getInstance().sinkNativeEvent(this,callback);
219+
}
220+
221+
public LDDataPoint[] getHighlightedDataPoints() {
222+
if (processing.getInstance() != null)
223+
return processing.getInstance().getHighlightedDataPoints();
224+
return null;
225+
}
226+
227+
@Override
228+
public HandlerRegistration addMiddleMouseClickHandler(
229+
MiddleMouseClickHandler handler) {
230+
sinkEvents(MiddleMouseClickEvent.getType());
231+
return addHandler(handler, MiddleMouseClickEvent.getType());
232+
}
233+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
2+
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
3+
xmlns:g="urn:import:com.google.gwt.user.client.ui"
4+
xmlns:pjs="urn:import:at.gmi.nordborglab.processingjs.client">
5+
6+
<ui:style>
7+
.ldviewer {
8+
}
9+
</ui:style>
10+
<g:FlowPanel ui:field="container">
11+
<pjs:Processing ui:field="processing" addStyleNames="{style.ldviewer}"></pjs:Processing>
12+
</g:FlowPanel>
13+
</ui:UiBinder>

0 commit comments

Comments
 (0)