View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // OldUTGBTrackGroup.java
20  // Since: 2007/06/19
21  //
22  // $URL$ 
23  // $Author$ ssksn
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.lib.old;
26  
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  import org.utgenome.gwt.utgb.client.RPCServiceManager;
31  import org.utgenome.gwt.utgb.client.track.TrackGroup;
32  import org.utgenome.gwt.utgb.client.track.TrackGroupPropertyChange;
33  import org.utgenome.gwt.utgb.client.track.TrackGroupPropertyWriter;
34  import org.utgenome.gwt.utgb.client.track.TrackWindow;
35  import org.utgenome.gwt.utgb.client.track.impl.TrackGroupPropertyImpl;
36  import org.utgenome.gwt.utgb.client.track.lib.TrackTreeTrack;
37  import org.utgenome.gwt.utgb.client.track.lib.ValueSelectorTrack;
38  import org.utgenome.gwt.utgb.client.util.GETMethodURL;
39  
40  import com.google.gwt.core.client.GWT;
41  import com.google.gwt.user.client.rpc.AsyncCallback;
42  
43  /**
44   * @author ssksn
45   * 
46   */
47  public class OldUTGBTrackGroup extends TrackGroup {
48  	public static TrackGroupFactory factory() {
49  		return new TrackGroupFactory() {
50  			public TrackGroup newInstance() {
51  				final OldUTGBTrackGroup trackGroup = new OldUTGBTrackGroup();
52  				final TrackGroupPropertyWriter propertyWriter = trackGroup.getPropertyWriter();
53  
54  				propertyWriter.setProperty(OldUTGBProperty.REVISION, (String) (properties.get(OldUTGBProperty.REVISION)));
55  				propertyWriter.setProperty(OldUTGBProperty.TARGET, (String) (properties.get(OldUTGBProperty.TARGET)));
56  				propertyWriter.setProperty(OldUTGBProperty.SPECIES, (String) (properties.get(OldUTGBProperty.SPECIES)));
57  
58  				return trackGroup;
59  			}
60  
61  			Map<String, String> properties = new HashMap<String, String>();
62  
63  			public void setProperty(String key, String value) {
64  				properties.put(key, value);
65  			}
66  
67  		};
68  	}
69  
70  	public OldUTGBTrackGroup() {
71  		super("OldUTGBTrackGroup");
72  	}
73  
74  	public void defaultSetUp() {
75  		setTrackGroupProperty(new TrackGroupPropertyImpl(this) {
76  			private int currentTargetLength = 0;
77  			private GETMethodURL GET_TARGET_LENGTH_URL = GETMethodURL
78  					.newInstance("http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/browser_web_api/getTargetLength.php");
79  
80  			private final int correctIndex(final int inputIndex) {
81  				int _index = Math.max(inputIndex, 1);
82  				_index = Math.min(_index, currentTargetLength);
83  
84  				return _index;
85  			}
86  
87  			public void setTrackWindow(int startOnGenome, int endOnGenome) {
88  				super.setTrackWindow(correctIndex(startOnGenome), correctIndex(endOnGenome));
89  			}
90  
91  			public void setTrackWindow(TrackWindow newWindow) {
92  				final TrackWindow _window = newWindow.newWindow(correctIndex(newWindow.getStartOnGenome()), correctIndex(newWindow.getEndOnGenome()));
93  				super.setTrackWindow(_window);
94  			}
95  
96  			public void setProperty(Map<String, String> property) {
97  				boolean updateFlag = false;
98  				String species = getProperty(OldUTGBProperty.SPECIES);
99  				String revision = getProperty(OldUTGBProperty.REVISION);
100 				String target = getProperty(OldUTGBProperty.TARGET);
101 
102 				if (property.containsKey(OldUTGBProperty.SPECIES)) {
103 					species = (String) property.get(OldUTGBProperty.SPECIES);
104 					updateFlag = true;
105 				}
106 				if (property.containsKey(OldUTGBProperty.REVISION)) {
107 					revision = (String) property.get(OldUTGBProperty.REVISION);
108 					updateFlag = true;
109 				}
110 				if (property.containsKey(OldUTGBProperty.TARGET)) {
111 					target = (String) property.get(OldUTGBProperty.TARGET);
112 					updateFlag = true;
113 				}
114 
115 				if (updateFlag) {
116 					final Map<String, String> parameterMap = new HashMap<String, String>();
117 					parameterMap.put("species", species);
118 					parameterMap.put("revision", revision);
119 					parameterMap.put("target", target);
120 					final String url = GET_TARGET_LENGTH_URL.getURL(parameterMap);
121 
122 					RPCServiceManager.getRPCService().getHTTPContent(url, new AsyncCallback<String>() {
123 						public void onFailure(Throwable caught) {
124 							GWT.log("cannot retrieve: " + url, caught);
125 						}
126 
127 						public void onSuccess(String result) {
128 							final String targetLengthStr = result.trim();
129 
130 							final int targetLength = Integer.parseInt(targetLengthStr);
131 
132 							if (targetLength != -1) {
133 								currentTargetLength = targetLength;
134 
135 								setTrackWindow(1, currentTargetLength);
136 							}
137 						}
138 					});
139 				}
140 				super.setProperty(property);
141 			}
142 
143 			public void setProperty(String key, String value) {
144 				boolean updateFlag = false;
145 				String species = null;
146 				String revision = null;
147 				String target = null;
148 
149 				if (key.equals(OldUTGBProperty.SPECIES)) {
150 					species = value;
151 					revision = getProperty(OldUTGBProperty.REVISION);
152 					target = getProperty(OldUTGBProperty.TARGET);
153 
154 					updateFlag = true;
155 				}
156 				else if (key.equals(OldUTGBProperty.REVISION)) {
157 					species = getProperty(OldUTGBProperty.SPECIES);
158 					revision = value;
159 					target = getProperty(OldUTGBProperty.TARGET);
160 
161 					updateFlag = true;
162 				}
163 				else if (key.equals(OldUTGBProperty.TARGET)) {
164 					species = getProperty(OldUTGBProperty.SPECIES);
165 					revision = getProperty(OldUTGBProperty.REVISION);
166 					target = value;
167 
168 					updateFlag = true;
169 				}
170 
171 				if (updateFlag) {
172 					final Map<String, String> parameterMap = new HashMap<String, String>();
173 					parameterMap.put("species", species);
174 					parameterMap.put("revision", revision);
175 					parameterMap.put("target", target);
176 					final String url = GET_TARGET_LENGTH_URL.getURL(parameterMap);
177 
178 					getBrowserService().getHTTPContent(url, new AsyncCallback<String>() {
179 						public void onFailure(Throwable caught) {
180 							GWT.log("cannot retrieve: " + url, caught);
181 						}
182 
183 						public void onSuccess(String result) {
184 							final String targetLengthStr = result.trim();
185 
186 							final int targetLength = Integer.parseInt(targetLengthStr);
187 
188 							if (targetLength != -1) {
189 								currentTargetLength = targetLength;
190 
191 								setTrackWindow(1, currentTargetLength);
192 							}
193 						}
194 					});
195 				}
196 				super.setProperty(key, value);
197 			}
198 		});
199 
200 		final TrackGroupPropertyWriter propertyWriter = getPropertyWriter();
201 		propertyWriter.setTrackWindowSize(800);
202 		final Map<String, String> defaultPropertyMap = new HashMap<String, String>();
203 		defaultPropertyMap.put(OldUTGBProperty.SPECIES, "medaka");
204 		defaultPropertyMap.put(OldUTGBProperty.REVISION, "200506");
205 		defaultPropertyMap.put(OldUTGBProperty.TARGET, "scaffold1");
206 		propertyWriter.setProperty(defaultPropertyMap);
207 
208 		//addTrack(new LoadAndStoreTrack());
209 		final TrackTreeTrack ttTrack = new TrackTreeTrack();
210 		addTrackUpdateListener(ttTrack);
211 		addTrack(ttTrack);
212 
213 		addTrack(new OldUTGBPropertyTrack());
214 		addTrack(new OldUTGBAddTrackTrack());
215 
216 		// {
217 		// final SequenceRulerTrack sequenceRulerTrack = new SequenceRulerTrack();
218 		// addTrack(sequenceRulerTrack);
219 		// sequenceRulerTrack.setSequenceSize(10000000);
220 		// addTrack(new RulerTrack());
221 		// }
222 
223 		{
224 			final ValueSelectorTrack speciesTrack = new ValueSelectorTrack("Species", OldUTGBProperty.SPECIES);
225 			speciesTrack.addValue("medaka");
226 			speciesTrack.addValue("medaka-HNI");
227 			addTrack(speciesTrack);
228 		}
229 
230 		{
231 			final ValueSelectorTrack revisionTrack = new ValueSelectorTrack("Revision", OldUTGBProperty.REVISION) {
232 				public void onChangeTrackGroupProperty(TrackGroupPropertyChange change) {
233 					if (change.contains(OldUTGBProperty.SPECIES)) {
234 						setRevision(change.getProperty(OldUTGBProperty.SPECIES));
235 						draw();
236 						updateSelection();
237 					}
238 
239 				}
240 
241 				private void setRevision(String species) {
242 
243 					if (species.equals("medaka")) {
244 						clearValues();
245 						addValue("200406");
246 						addValue("200506");
247 						addValue("version0.9");
248 						addValue("version1.0");
249 					}
250 					else if (species.equals("medaka-HNI")) {
251 						clearValues();
252 						addValue("version1.0");
253 					}
254 
255 				}
256 			};
257 			revisionTrack.addValue("200406");
258 			revisionTrack.addValue("200506");
259 			revisionTrack.addValue("version0.9");
260 			revisionTrack.addValue("version1.0");
261 			addTrack(revisionTrack);
262 		}
263 
264 		{
265 			final OldUTGBTrack rulerTrack = new OldUTGBRulerTrack();
266 			addTrack(rulerTrack);
267 			rulerTrack.setDescriptionXML("http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/rulertrack.xml");
268 
269 			final OldUTGBTrack zoomerTrack = new OldUTGBRulerTrack();
270 			addTrack(zoomerTrack);
271 			zoomerTrack.setDescriptionXML("http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/zoomertrack.xml");
272 
273 			final OldUTGBTrack basecolorTrack = new OldUTGBRulerTrack();
274 			addTrack(basecolorTrack);
275 			basecolorTrack.setDescriptionXML("http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/basecolortrack.xml");
276 		}
277 
278 		final String[] descriptionXMLs = {
279 				// "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/rulertrack.xml",
280 				// "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/zoomertrack.xml",
281 				// "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/basecolortrack.xml",
282 				"http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/qv.xml", "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/coverage.xml",
283 				"http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/mappedGene.xml", "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/descriptions/5sage.xml",
284 				"http://medaka3.gi.k.u-tokyo.ac.jp/~yamada/repeat/test.xml",
285 				"http://medaka.utgenome.org/~ssksn/clonelink_test_track/clonelink_test_description.xml",
286 				// "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/bac_end_track/bac_end_description.xml",
287 				"http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/geneticMarker_track/geneticMarker_description.xml" };
288 
289 		for (int i = 0; i < descriptionXMLs.length; i++) {
290 			final String descriptionXML = descriptionXMLs[i];
291 
292 			final OldUTGBTrack track = new OldUTGBTrack();
293 
294 			addTrack(track);
295 			track.setDescriptionXML(descriptionXML);
296 		}
297 
298 		/*
299 		 * final String descriptionXML =
300 		 * "http://medaka3.gi.k.u-tokyo.ac.jp/~ssksn/fosmid_end_track/fosmid_end_description.xml";
301 		 * 
302 		 * final OldUTGBTrack track = new OldUTGBTrack(); track.setDescriptionXML(descriptionXML);
303 		 * 
304 		 * addTrack(track);
305 		 */
306 
307 		setTrackWindowLocation(1, 1000000);
308 	}
309 
310 }