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 package org.utgenome.gwt.utgb.client.track.lib;
26
27 import java.util.List;
28
29 import org.utgenome.gwt.utgb.client.bio.SAMRead;
30 import org.utgenome.gwt.utgb.client.canvas.SAMCanvas;
31 import org.utgenome.gwt.utgb.client.db.Value;
32 import org.utgenome.gwt.utgb.client.db.ValueDomain;
33 import org.utgenome.gwt.utgb.client.db.datatype.StringType;
34 import org.utgenome.gwt.utgb.client.track.Track;
35 import org.utgenome.gwt.utgb.client.track.TrackBase;
36 import org.utgenome.gwt.utgb.client.track.TrackConfig;
37 import org.utgenome.gwt.utgb.client.track.TrackConfigChange;
38 import org.utgenome.gwt.utgb.client.track.TrackFrame;
39 import org.utgenome.gwt.utgb.client.track.TrackGroup;
40 import org.utgenome.gwt.utgb.client.track.TrackWindow;
41 import org.utgenome.gwt.utgb.client.util.CanonicalProperties;
42
43 import com.google.gwt.core.client.GWT;
44 import com.google.gwt.user.client.Command;
45 import com.google.gwt.user.client.DeferredCommand;
46 import com.google.gwt.user.client.rpc.AsyncCallback;
47 import com.google.gwt.user.client.ui.AbsolutePanel;
48 import com.google.gwt.user.client.ui.FlexTable;
49 import com.google.gwt.user.client.ui.Widget;
50
51
52
53
54
55
56
57 public class SAMQueryTrack extends TrackBase {
58 private final boolean isDebug = true;
59 private boolean isC2T = false;
60
61 protected String trackBaseURL;
62
63 protected String target = "chr13";
64 protected int start = 3000000;
65 protected int end = 3100000;
66
67 protected String bamFileName = null;
68 protected String indexFileName = null;
69 protected String refSeqFileName = null;
70 protected String colorMode = "nucleotide";
71
72 private final FlexTable layoutTable = new FlexTable();
73 private final SAMCanvas samCanvas = new SAMCanvas();
74 private final AbsolutePanel labelPanel = new AbsolutePanel();
75
76 private int height = 500;
77 private int leftMargin = 100;
78 private int labelWidth = 100;
79
80 private List<SAMRead> readDataList;
81 private String refSeq;
82
83 public static TrackFactory factory() {
84 return new TrackFactory() {
85 @Override
86 public Track newInstance() {
87 return new SAMQueryTrack();
88 }
89 };
90 }
91
92 public SAMQueryTrack() {
93 super("SAM Query Viewer Track");
94
95
96 layoutTable.setCellPadding(0);
97 layoutTable.setCellSpacing(0);
98 layoutTable.setBorderWidth(0);
99 layoutTable.setWidth("100%");
100
101 layoutTable.setWidget(1, 0, labelPanel);
102 layoutTable.setWidget(1, 1, samCanvas);
103
104 }
105
106 public Widget getWidget() {
107 return layoutTable;
108 }
109
110 @Override
111 public void setUp(TrackFrame trackFrame, TrackGroup group) {
112
113 TrackConfig config = getConfig();
114 config.addConfig("BAM File Name", new StringType("bamFileName"), bamFileName);
115
116 indexFileName = bamFileName + ".bai";
117 config.addConfig("Reference Sequence File Name", new StringType("refSeqFileName"), refSeqFileName);
118 ValueDomain colorModeDomain = new ValueDomain();
119 colorModeDomain.addValueList(new Value("nucleotide"));
120 colorModeDomain.addValueList(new Value("mapping quality"));
121 colorModeDomain.addValueList(new Value("base quality"));
122 config.addConfig("Color Mode", new StringType("colorMode", colorModeDomain), colorMode);
123 config.addConfig("Target Name", new StringType("target"), target);
124 config.addConfig("Start", new StringType("start"), String.valueOf(start));
125 config.addConfig("End", new StringType("end"), String.valueOf(end));
126 samCanvas.setWindow(group.getTrackWindow(), leftMargin);
127
128 update(group.getTrackWindow());
129 }
130
131 class UpdateCommand implements Command {
132 private final List<SAMRead> readList;
133 private final String refSeq;
134
135 public UpdateCommand(List<SAMRead> readList, String refSeq) {
136 this.readList = readList;
137 this.refSeq = refSeq;
138 }
139
140 public void execute() {
141 TrackWindow w = getTrackGroup().getTrackWindow();
142
143 height = getDefaultWindowHeight();
144
145 int s = w.getStartOnGenome();
146 int e = w.getEndOnGenome();
147 int width = w.getPixelWidth() - leftMargin;
148
149 labelPanel.clear();
150 labelPanel.setPixelSize(leftMargin, height);
151
152 samCanvas.clear();
153 samCanvas.setWindow(new TrackWindow(width, s, e), leftMargin);
154 samCanvas.setC2T(isC2T);
155 samCanvas.setColorMode(colorMode);
156
157
158
159
160
161
162
163
164 samCanvas.drawSAMRead(readList);
165 samCanvas.drawLabelPanel(readList, labelPanel, leftMargin);
166
167 refresh();
168 getFrame().loadingDone();
169 }
170 }
171
172 public void update(TrackWindow newWindow) {
173 getFrame().setNowLoading();
174
175 getBrowserService().querySAMReadList(bamFileName, indexFileName, refSeqFileName, target, start, end, new AsyncCallback<List<SAMRead>>() {
176
177 public void onFailure(Throwable e) {
178 GWT.log("failed to retrieve sam data", e);
179 getFrame().loadingDone();
180 }
181
182 public void onSuccess(List<SAMRead> dataList) {
183 GWT.log("read sam", null);
184 readDataList = dataList;
185
186 if (isDebug)
187 for (SAMRead read : dataList) {
188 GWT.log("read : " + read.qname, null);
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 DeferredCommand.addCommand(new UpdateCommand(readDataList, refSeq));
206
207
208 }
209 });
210
211 }
212
213 @Override
214 public void onChangeTrackWindow(TrackWindow newWindow) {
215
216 }
217
218 @Override
219 public void onChangeTrackConfig(TrackConfigChange change) {
220 boolean isUpdate = false;
221
222 if (isDebug) {
223 for (String key : change.getChangedParamSet()) {
224 GWT.log("Change : " + key + " : " + change.getValue(key), null);
225 }
226 }
227
228 if (change.contains("bamFileName")) {
229 bamFileName = change.getValue("bamFileName");
230 indexFileName = bamFileName + ".bai";
231 isUpdate = true;
232 }
233
234
235
236
237 if (change.contains("refSeqFileName")) {
238 refSeqFileName = change.getValue("refSeqFileName");
239 isUpdate = true;
240 }
241 if (change.contains("target")) {
242 target = change.getValue("target");
243 isUpdate = true;
244 }
245 if (change.contains("start")) {
246 start = change.getIntValue("start");
247 isUpdate = true;
248 }
249 if (change.contains("end")) {
250 end = change.getIntValue("end");
251 isUpdate = true;
252 }
253 if (change.contains("colorMode")) {
254 colorMode = change.getValue("colorMode");
255 }
256 if (change.contains("isC2T")) {
257 isC2T = change.getBoolValue("isC2T");
258 }
259
260 if (isUpdate) {
261 update(getTrackWindow());
262 }
263 else {
264 getFrame().setNowLoading();
265 DeferredCommand.addCommand(new UpdateCommand(readDataList, refSeq));
266 }
267 }
268
269
270
271
272
273
274
275
276
277
278
279
280
281 @Override
282 public void restoreProperties(CanonicalProperties properties) {
283 super.restoreProperties(properties);
284
285 bamFileName = properties.get("bamFileName", bamFileName);
286
287 refSeqFileName = properties.get("refSeqFileName", refSeqFileName);
288 colorMode = properties.get("colorMode", colorMode);
289 isC2T = properties.getBoolean("isC2T", isC2T);
290 leftMargin = properties.getInt("leftMargin", leftMargin);
291
292 target = properties.get("target", target);
293 start = properties.getInt("start", start);
294 end = properties.getInt("end", end);
295
296 String p = properties.get("changeParamOnClick");
297 if (p != null) {
298
299
300 }
301 }
302
303 }